Skip to content

Commit

Permalink
PointerAlighment: Left
Browse files Browse the repository at this point in the history
  • Loading branch information
KowerKoint committed Sep 9, 2024
1 parent 815f24f commit ddcf43b
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 35 deletions.
2 changes: 2 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ AccessModifierOffset: -4
BinPackArguments: false
BinPackParameters: false
ColumnLimit: 100
DerivePointerAlignment: false
PointerAlignment: Left
4 changes: 2 additions & 2 deletions python/binding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct type_caster<Kokkos::complex<T>> {
NB_TYPE_CASTER(Kokkos::complex<T>, const_name("complex"))

template <bool Recursive = true>
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;

Expand Down Expand Up @@ -63,7 +63,7 @@ struct type_caster<Kokkos::complex<T>> {
}

template <typename T2>
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;

Expand Down
32 changes: 16 additions & 16 deletions scaluq/gate/gate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ namespace internal {
class GateBase : public std::enable_shared_from_this<GateBase> {
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(
Expand Down Expand Up @@ -166,7 +166,7 @@ class GateBase : public std::enable_shared_from_this<GateBase> {
[[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 <GateImpl T>
Expand All @@ -181,9 +181,9 @@ class GatePtr {

public:
GatePtr() : _gate_ptr(nullptr), _gate_type(get_gate_type<T>()) {}
GatePtr(const GatePtr &gate) = default;
GatePtr(const GatePtr& gate) = default;
template <GateImpl U>
GatePtr(const std::shared_ptr<const U> &gate_ptr) {
GatePtr(const std::shared_ptr<const U>& gate_ptr) {
if constexpr (std::is_same_v<T, U>) {
_gate_type = get_gate_type<T>();
_gate_ptr = gate_ptr;
Expand All @@ -200,7 +200,7 @@ class GatePtr {
}
}
template <GateImpl U>
GatePtr(const GatePtr<U> &gate) {
GatePtr(const GatePtr<U>& gate) {
if constexpr (std::is_same_v<T, U>) {
_gate_type = gate._gate_type;
_gate_ptr = gate._gate_ptr;
Expand All @@ -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");
}
Expand All @@ -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> gate_base_def;
Expand All @@ -283,7 +283,7 @@ nb::class_<Gate> gate_base_def;
"\n\n.. note:: Upcast is required to use gate-general functions (ex: add to Circuit).") \
.def(nb::init<Gate>())

void bind_gate_gate_hpp(nb::module_ &m) {
void bind_gate_gate_hpp(nb::module_& m) {
nb::enum_<GateType>(m, "GateType", "Enum of Gate Type.")
.value("I", GateType::I)
.value("GlobalPhase", GateType::GlobalPhase)
Expand Down
34 changes: 17 additions & 17 deletions scaluq/gate/param_gate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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 <ParamGateImpl T>
Expand All @@ -97,9 +97,9 @@ class ParamGatePtr {

public:
ParamGatePtr() : _param_gate_ptr(nullptr), _param_gate_type(get_param_gate_type<T>()) {}
ParamGatePtr(const ParamGatePtr &param_gate) = default;
ParamGatePtr(const ParamGatePtr& param_gate) = default;
template <ParamGateImpl U>
ParamGatePtr(const std::shared_ptr<U> &param_gate_ptr) {
ParamGatePtr(const std::shared_ptr<U>& param_gate_ptr) {
if constexpr (std::is_same_v<T, U>) {
_param_gate_type = get_param_gate_type<T>();
_param_gate_ptr = param_gate_ptr;
Expand All @@ -116,7 +116,7 @@ class ParamGatePtr {
}
}
template <ParamGateImpl U>
ParamGatePtr(const ParamGatePtr<U> &param_gate) {
ParamGatePtr(const ParamGatePtr<U>& param_gate) {
if constexpr (std::is_same_v<T, U>) {
_param_gate_type = param_gate._param_gate_type;
_param_gate_ptr = param_gate._param_gate_ptr;
Expand All @@ -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");
}
Expand All @@ -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 &param_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 &param_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_<ParamGate> param_gate_base_def;
Expand All @@ -207,7 +207,7 @@ nb::class_<ParamGate> param_gate_base_def;
"\n\n.. note:: Upcast is required to use gate-general functions (ex: add to Circuit).") \
.def(nb::init<ParamGate>())

void bind_gate_param_gate_hpp(nb::module_ &m) {
void bind_gate_param_gate_hpp(nb::module_& m) {
nb::enum_<ParamGateType>(m, "ParamGateType", "Enum of ParamGate Type.")
.value("ParamRX", ParamGateType::ParamRX)
.value("ParamRY", ParamGateType::ParamRY)
Expand Down

0 comments on commit ddcf43b

Please sign in to comment.