diff --git a/.clang-format b/.clang-format index a49304f2..f496c47a 100644 --- a/.clang-format +++ b/.clang-format @@ -7,3 +7,5 @@ AccessModifierOffset: -4 BinPackArguments: false BinPackParameters: false ColumnLimit: 100 +DerivePointerAlignment: false +PointerAlignment: Left diff --git a/python/binding.cpp b/python/binding.cpp index 971504f0..dcd732ae 100644 --- a/python/binding.cpp +++ b/python/binding.cpp @@ -31,7 +31,7 @@ struct type_caster> { NB_TYPE_CASTER(Kokkos::complex, const_name("complex")) template - bool from_python(handle src, uint8_t flags, cleanup_list *cleanup) noexcept { + bool from_python(handle src, uint8_t flags, cleanup_list* cleanup) noexcept { (void)flags; (void)cleanup; @@ -63,7 +63,7 @@ struct type_caster> { } template - static handle from_cpp(T2 &&value, rv_policy policy, cleanup_list *cleanup) noexcept { + static handle from_cpp(T2&& value, rv_policy policy, cleanup_list* cleanup) noexcept { (void)policy; (void)cleanup; diff --git a/scaluq/gate/gate.hpp b/scaluq/gate/gate.hpp index bfaddcf4..0d2a8cf3 100644 --- a/scaluq/gate/gate.hpp +++ b/scaluq/gate/gate.hpp @@ -127,7 +127,7 @@ namespace internal { class GateBase : public std::enable_shared_from_this { protected: std::uint64_t _target_mask, _control_mask; - void check_qubit_mask_within_bounds(const StateVector &state_vector) const { + void check_qubit_mask_within_bounds(const StateVector& state_vector) const { std::uint64_t full_mask = (1ULL << state_vector.n_qubits()) - 1; if ((_target_mask | _control_mask) > full_mask) [[unlikely]] { throw std::runtime_error( @@ -166,7 +166,7 @@ class GateBase : public std::enable_shared_from_this { [[nodiscard]] virtual Gate get_inverse() const = 0; [[nodiscard]] virtual internal::ComplexMatrix get_matrix() const = 0; - virtual void update_quantum_state(StateVector &state_vector) const = 0; + virtual void update_quantum_state(StateVector& state_vector) const = 0; }; template @@ -181,9 +181,9 @@ class GatePtr { public: GatePtr() : _gate_ptr(nullptr), _gate_type(get_gate_type()) {} - GatePtr(const GatePtr &gate) = default; + GatePtr(const GatePtr& gate) = default; template - GatePtr(const std::shared_ptr &gate_ptr) { + GatePtr(const std::shared_ptr& gate_ptr) { if constexpr (std::is_same_v) { _gate_type = get_gate_type(); _gate_ptr = gate_ptr; @@ -200,7 +200,7 @@ class GatePtr { } } template - GatePtr(const GatePtr &gate) { + GatePtr(const GatePtr& gate) { if constexpr (std::is_same_v) { _gate_type = gate._gate_type; _gate_ptr = gate._gate_ptr; @@ -220,7 +220,7 @@ class GatePtr { GateType gate_type() const { return _gate_type; } - const T *operator->() const { + const T* operator->() const { if (!_gate_ptr) { throw std::runtime_error("GatePtr::operator->(): Gate is Null"); } @@ -236,41 +236,41 @@ namespace internal { .def("gate_type", &GATE_TYPE::gate_type, "Get gate type as `GateType` enum.") \ .def( \ "target_qubit_list", \ - [](const GATE_TYPE &gate) { return gate->target_qubit_list(); }, \ + [](const GATE_TYPE& gate) { return gate->target_qubit_list(); }, \ "Get target qubits as `list[int]`. **Control qubits is not included.**") \ .def( \ "control_qubit_list", \ - [](const GATE_TYPE &gate) { return gate->control_qubit_list(); }, \ + [](const GATE_TYPE& gate) { return gate->control_qubit_list(); }, \ "Get control qubits as `list[int]`.") \ .def( \ "operand_qubit_list", \ - [](const GATE_TYPE &gate) { return gate->operand_qubit_list(); }, \ + [](const GATE_TYPE& gate) { return gate->operand_qubit_list(); }, \ "Get target and control qubits as `list[int]`.") \ .def( \ "target_qubit_mask", \ - [](const GATE_TYPE &gate) { return gate->target_qubit_mask(); }, \ + [](const GATE_TYPE& gate) { return gate->target_qubit_mask(); }, \ "Get target qubits as mask. **Control qubits is not included.**") \ .def( \ "control_qubit_mask", \ - [](const GATE_TYPE &gate) { return gate->control_qubit_mask(); }, \ + [](const GATE_TYPE& gate) { return gate->control_qubit_mask(); }, \ "Get control qubits as mask.") \ .def( \ "operand_qubit_mask", \ - [](const GATE_TYPE &gate) { return gate->operand_qubit_mask(); }, \ + [](const GATE_TYPE& gate) { return gate->operand_qubit_mask(); }, \ "Get target and control qubits as mask.") \ .def( \ "get_inverse", \ - [](const GATE_TYPE &gate) { return gate->get_inverse(); }, \ + [](const GATE_TYPE& gate) { return gate->get_inverse(); }, \ "Generate inverse gate as `Gate` type. If not exists, return None.") \ .def( \ "update_quantum_state", \ - [](const GATE_TYPE &gate, StateVector &state_vector) { \ + [](const GATE_TYPE& gate, StateVector& state_vector) { \ gate->update_quantum_state(state_vector); \ }, \ "Apply gate to `state_vector`. `state_vector` in args is directly updated.") \ .def( \ "get_matrix", \ - [](const GATE_TYPE &gate) { return gate->get_matrix(); }, \ + [](const GATE_TYPE& gate) { return gate->get_matrix(); }, \ "Get matrix representation of the gate.") nb::class_ gate_base_def; @@ -283,7 +283,7 @@ nb::class_ gate_base_def; "\n\n.. note:: Upcast is required to use gate-general functions (ex: add to Circuit).") \ .def(nb::init()) -void bind_gate_gate_hpp(nb::module_ &m) { +void bind_gate_gate_hpp(nb::module_& m) { nb::enum_(m, "GateType", "Enum of Gate Type.") .value("I", GateType::I) .value("GlobalPhase", GateType::GlobalPhase) diff --git a/scaluq/gate/param_gate.hpp b/scaluq/gate/param_gate.hpp index eea4ad39..476f35a9 100644 --- a/scaluq/gate/param_gate.hpp +++ b/scaluq/gate/param_gate.hpp @@ -41,7 +41,7 @@ class ParamGateBase { protected: std::uint64_t _target_mask, _control_mask; double _pcoef; - void check_qubit_mask_within_bounds(const StateVector &state_vector) const { + void check_qubit_mask_within_bounds(const StateVector& state_vector) const { std::uint64_t full_mask = (1ULL << state_vector.n_qubits()) - 1; if ((_target_mask | _control_mask) > full_mask) [[unlikely]] { throw std::runtime_error( @@ -82,7 +82,7 @@ class ParamGateBase { [[nodiscard]] virtual ParamGate get_inverse() const = 0; [[nodiscard]] virtual internal::ComplexMatrix get_matrix(double param) const = 0; - virtual void update_quantum_state(StateVector &state_vector, double param) const = 0; + virtual void update_quantum_state(StateVector& state_vector, double param) const = 0; }; template @@ -97,9 +97,9 @@ class ParamGatePtr { public: ParamGatePtr() : _param_gate_ptr(nullptr), _param_gate_type(get_param_gate_type()) {} - ParamGatePtr(const ParamGatePtr ¶m_gate) = default; + ParamGatePtr(const ParamGatePtr& param_gate) = default; template - ParamGatePtr(const std::shared_ptr ¶m_gate_ptr) { + ParamGatePtr(const std::shared_ptr& param_gate_ptr) { if constexpr (std::is_same_v) { _param_gate_type = get_param_gate_type(); _param_gate_ptr = param_gate_ptr; @@ -116,7 +116,7 @@ class ParamGatePtr { } } template - ParamGatePtr(const ParamGatePtr ¶m_gate) { + ParamGatePtr(const ParamGatePtr& param_gate) { if constexpr (std::is_same_v) { _param_gate_type = param_gate._param_gate_type; _param_gate_ptr = param_gate._param_gate_ptr; @@ -136,7 +136,7 @@ class ParamGatePtr { ParamGateType param_gate_type() const { return _param_gate_type; } - const T *operator->() const { + const T* operator->() const { if (!_param_gate_ptr) { throw std::runtime_error("ParamGatePtr::operator->(): ParamGate is Null"); } @@ -154,46 +154,46 @@ namespace internal { "Get parametric gate type as `ParamGateType` enum.") \ .def( \ "param_coef", \ - [](const PARAM_GATE_TYPE &gate) { return gate->param_coef(); }, \ + [](const PARAM_GATE_TYPE& gate) { return gate->param_coef(); }, \ "Get coefficient of parameter.") \ .def( \ "target_qubit_list", \ - [](const PARAM_GATE_TYPE &gate) { return gate->target_qubit_list(); }, \ + [](const PARAM_GATE_TYPE& gate) { return gate->target_qubit_list(); }, \ "Get target qubits as `list[int]`. **Control qubits is not included.**") \ .def( \ "control_qubit_list", \ - [](const PARAM_GATE_TYPE &gate) { return gate->control_qubit_list(); }, \ + [](const PARAM_GATE_TYPE& gate) { return gate->control_qubit_list(); }, \ "Get control qubits as `list[int]`.") \ .def( \ "operand_qubit_list", \ - [](const PARAM_GATE_TYPE &gate) { return gate->operand_qubit_list(); }, \ + [](const PARAM_GATE_TYPE& gate) { return gate->operand_qubit_list(); }, \ "Get target and control qubits as `list[int]`.") \ .def( \ "target_qubit_mask", \ - [](const PARAM_GATE_TYPE &gate) { return gate->target_qubit_mask(); }, \ + [](const PARAM_GATE_TYPE& gate) { return gate->target_qubit_mask(); }, \ "Get target qubits as mask. **Control qubits is not included.**") \ .def( \ "control_qubit_mask", \ - [](const PARAM_GATE_TYPE &gate) { return gate->control_qubit_mask(); }, \ + [](const PARAM_GATE_TYPE& gate) { return gate->control_qubit_mask(); }, \ "Get control qubits as mask.") \ .def( \ "operand_qubit_mask", \ - [](const PARAM_GATE_TYPE &gate) { return gate->operand_qubit_mask(); }, \ + [](const PARAM_GATE_TYPE& gate) { return gate->operand_qubit_mask(); }, \ "Get target and control qubits as mask.") \ .def( \ "get_inverse", \ - [](const PARAM_GATE_TYPE ¶m_gate) { return param_gate->get_inverse(); }, \ + [](const PARAM_GATE_TYPE& param_gate) { return param_gate->get_inverse(); }, \ "Generate inverse parametric-gate as `ParamGate` type. If not exists, return None.") \ .def( \ "update_quantum_state", \ - [](const PARAM_GATE_TYPE ¶m_gate, StateVector &state_vector, double param) { \ + [](const PARAM_GATE_TYPE& param_gate, StateVector& state_vector, double param) { \ param_gate->update_quantum_state(state_vector, param); \ }, \ "Apply gate to `state_vector` with holding the parameter. `state_vector` in args is " \ "directly updated.") \ .def( \ "get_matrix", \ - [](const PARAM_GATE_TYPE &gate, double param) { return gate->get_matrix(param); }, \ + [](const PARAM_GATE_TYPE& gate, double param) { return gate->get_matrix(param); }, \ "Get matrix representation of the gate with holding the parameter.") nb::class_ param_gate_base_def; @@ -207,7 +207,7 @@ nb::class_ param_gate_base_def; "\n\n.. note:: Upcast is required to use gate-general functions (ex: add to Circuit).") \ .def(nb::init()) -void bind_gate_param_gate_hpp(nb::module_ &m) { +void bind_gate_param_gate_hpp(nb::module_& m) { nb::enum_(m, "ParamGateType", "Enum of ParamGate Type.") .value("ParamRX", ParamGateType::ParamRX) .value("ParamRY", ParamGateType::ParamRY)