Skip to content

Update clang-format and clang-tidy dependancy #1721

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
May 12, 2025
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Please complete the following checklist when submitting a PR:
- [ ] All new functions and code must be clearly commented and documented.

- [ ] Ensure that code is properly formatted by running `make format`.
The latest version of black and `clang-format-14` are used in CI/CD to check formatting.
The latest version of black and `clang-format-20` are used in CI/CD to check formatting.

- [ ] All new features must include a unit test.
Integration and frontend tests should be added to [`frontend/test`](../frontend/test/),
Expand Down
10 changes: 4 additions & 6 deletions .github/workflows/check-formatting.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,11 @@ jobs:
runs-on: ubuntu-22.04

steps:
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get -y install clang-format-14

- name: Checkout code
uses: actions/checkout@v4

- name: Install dependencies
run: python3 -m pip install clang-format~=20.1

- name: Run clang-format
run: python3 ./bin/format.py --check --verbose --cfversion 14 .
run: python3 ./bin/format.py --check --verbose .
2 changes: 1 addition & 1 deletion bin/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

IGNORE_PATTERNS = ["external", "build", "llvm-project", "mlir-hlo", "Enzyme"]

DEFAULT_CLANG_FORMAT_VERSION = 13
DEFAULT_CLANG_FORMAT_VERSION = 20

CLANG_FMT_CNFG_PATH = "../.clang-format"

Expand Down
3 changes: 3 additions & 0 deletions doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@
[(#1671)](https://github.com/PennyLaneAI/catalyst/pull/1671)
[(#1681)](https://github.com/PennyLaneAI/catalyst/pull/1681)

* The clang-format and clang-tidy versions used by Catalyst have been updated to v20.
[(#1721)](https://github.com/PennyLaneAI/catalyst/pull/1721)

* Support for Mac x86 has been removed. This includes Macs running on Intel processors.
[(#1716)](https://github.com/PennyLaneAI/catalyst/pull/1716)

Expand Down
7 changes: 3 additions & 4 deletions mlir/include/Quantum/IR/QuantumOps.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,11 @@
namespace mlir {
namespace OpTrait {

template <typename ConcreteType> class UnitaryTrait : public TraitBase<ConcreteType, UnitaryTrait> {
};
template <typename ConcreteType>
class UnitaryTrait : public TraitBase<ConcreteType, UnitaryTrait> {};

template <typename ConcreteType>
class HermitianTrait : public TraitBase<ConcreteType, HermitianTrait> {
};
class HermitianTrait : public TraitBase<ConcreteType, HermitianTrait> {};

} // namespace OpTrait
} // namespace mlir
Expand Down
2 changes: 1 addition & 1 deletion mlir/lib/QEC/Transforms/CommuteCliffordPastPPM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "mlir/Analysis/SliceAnalysis.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Debug.h"
//#include "mlir/Analysis/TopologicalSortUtils.h" // enable when updating llvm
// #include "mlir/Analysis/TopologicalSortUtils.h" // enable when updating llvm
#include "mlir/Transforms/TopologicalSortUtils.h"

#include "QEC/IR/QECDialect.h"
Expand Down
2 changes: 1 addition & 1 deletion mlir/lib/QEC/Transforms/CommuteCliffordTPPR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#define DEBUG_TYPE "commute_ppr"

#include "llvm/Support/Debug.h"
//#include "mlir/Analysis/TopologicalSortUtils.h" // enable when updating llvm
// #include "mlir/Analysis/TopologicalSortUtils.h" // enable when updating llvm
#include "mlir/Transforms/TopologicalSortUtils.h"

#include "QEC/IR/QECDialect.h"
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ PyYAML

# formatting/linting
black
clang-format==14.*
clang-tidy~=16.0
clang-format~=20.1
clang-tidy~=20.1
pylint
isort

Expand Down
1 change: 1 addition & 0 deletions runtime/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ check-tidy:
-DCMAKE_BUILD_TYPE=$(BUILD_TYPE) \
-DCMAKE_C_COMPILER=$(C_COMPILER) \
-DCMAKE_CXX_COMPILER=$(CXX_COMPILER) \
-DMLIR_INCLUDE_DIRS="$(abspath $(LLVM_DIR))/mlir/include" \
-DRUNTIME_CLANG_TIDY=ON

cmake --build $(MK_DIR)/BuildTidy --target rt_capi -j$(NPROC)
2 changes: 1 addition & 1 deletion runtime/include/QuantumDevice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ struct QuantumDevice {
*
* @param gen Pointer to a Catalyst-managed Mersenne Twister instance.
*/
virtual void SetDevicePRNG(std::mt19937 *gen){};
virtual void SetDevicePRNG(std::mt19937 *gen) {};

// ----------------------------------------
// QUANTUM OPERATIONS
Expand Down
22 changes: 10 additions & 12 deletions runtime/lib/backend/common/Utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@
CLASSNAME &operator=(CLASSNAME &&) = delete;

#define QUANTUM_DEVICE_RT_DECLARATIONS \
auto AllocateQubit()->QubitIdType override; \
auto AllocateQubits(size_t num_qubits)->std::vector<QubitIdType> override; \
auto AllocateQubit() -> QubitIdType override; \
auto AllocateQubits(size_t num_qubits) -> std::vector<QubitIdType> override; \
void ReleaseQubit(QubitIdType q) override; \
void ReleaseAllQubits() override; \
[[nodiscard]] auto GetNumQubits() const->size_t override; \
[[nodiscard]] auto GetNumQubits() const -> size_t override; \
void StartTapeRecording() override; \
void StopTapeRecording() override; \
void SetDeviceShots(size_t shots) override; \
[[nodiscard]] auto GetDeviceShots() const->size_t override;
[[nodiscard]] auto GetDeviceShots() const -> size_t override;

#define QUANTUM_DEVICE_QIS_DECLARATIONS \
void NamedOperation( \
Expand All @@ -58,14 +58,12 @@
[[maybe_unused]] const std::vector<QubitIdType> &controlled_wires = {}, \
[[maybe_unused]] const std::vector<bool> &controlled_values = {}) override; \
auto Observable(ObsId id, const std::vector<std::complex<double>> &matrix, \
const std::vector<QubitIdType> &wires) \
->ObsIdType override; \
auto TensorObservable(const std::vector<ObsIdType> &obs)->ObsIdType override; \
const std::vector<QubitIdType> &wires) -> ObsIdType override; \
auto TensorObservable(const std::vector<ObsIdType> &obs) -> ObsIdType override; \
auto HamiltonianObservable(const std::vector<double> &coeffs, \
const std::vector<ObsIdType> &obs) \
->ObsIdType override; \
auto Expval(ObsIdType obsKey)->double override; \
auto Var(ObsIdType obsKey)->double override; \
const std::vector<ObsIdType> &obs) -> ObsIdType override; \
auto Expval(ObsIdType obsKey) -> double override; \
auto Var(ObsIdType obsKey) -> double override; \
void State(DataView<std::complex<double>, 1> &state) override; \
void Probs(DataView<double, 1> &probs) override; \
void PartialProbs(DataView<double, 1> &probs, const std::vector<QubitIdType> &wires) override; \
Expand All @@ -76,7 +74,7 @@
void PartialCounts(DataView<double, 1> &eigvals, DataView<int64_t, 1> &counts, \
const std::vector<QubitIdType> &wires) override; \
auto Measure(QubitIdType wire, std::optional<int32_t> postselect = std::nullopt) \
->Result override; \
-> Result override; \
void Gradient(std::vector<DataView<double, 1>> &gradients, \
const std::vector<size_t> &trainParams) override;

Expand Down