22 #define M_PI 3.14159265358979323846 33 : gate_(gate), owns_gate_(owns_gate) {
35 throw std::invalid_argument(
"GateOperation: gate cannot be null");
52 other.gate_ =
nullptr;
53 other.owns_gate_ =
false;
63 other.gate_ =
nullptr;
64 other.owns_gate_ =
false;
80 if (num_params == 0) {
86 if (param_count < num_params || params ==
nullptr) {
87 throw std::runtime_error(
88 "GateOperation::apply_to_density: not enough parameters");
92 double theta_over_2 = 0, phi = 0, lambda = 0;
95 Matrix_real params_mat(const_cast<double *>(params), 1, param_count);
99 if (num_params == 1) {
103 theta_over_2 = params[0] / 2.0;
114 theta_over_2 = params[0] / 2.0;
118 theta_over_2 = params[0] / 2.0;
122 }
else if (num_params == 2) {
124 theta_over_2 =
M_PI / 4.0;
127 }
else if (num_params == 3) {
129 theta_over_2 = params[0] / 2.0;
177 throw std::runtime_error(
"GateOperation::clone: gate is null");
int get_control_qbit() const
Get control qubit index (-1 if not a controlled gate)
std::unique_ptr< IDensityOperation > clone() const override
Create a deep copy of this operation.
int get_parameter_num() const override
Get number of free parameters this operation requires.
GateOperation & operator=(const GateOperation &)=delete
virtual Gate * clone()
Call to create a clone of the present class.
static Matrix calc_one_qubit_u3(double ThetaOver2=0.0, double Phi=0.0, double Lambda=0.0)
Build a 2x2 U3 kernel from angles (theta/2, phi, lambda).
gate_type get_type()
Call to get the type of the operation.
Wraps an existing Gate for density matrix operations.
Quantum density matrix Ï for mixed-state representation.
int get_target_qbit() const
Get target qubit index.
Double-precision complex matrix (float64).
void apply_to_density(const double *params, int param_count, DensityMatrix &rho) override
Apply gate to density matrix using optimized local kernel.
virtual int get_parameter_num()
Call to get the number of free parameters.
virtual Matrix gate_kernel(const Matrix_real &precomputed_sincos)
Compute the gate kernel matrix from precomputed trigonometric values.
int get_target_qbit()
Call to get the index of the target qubit.
Base class for the representation of general gate operations.
std::string get_name()
Call to get the name label of the gate.
std::string get_name() const override
Get operation name for debugging/display.
~GateOperation() override
Destructor - deletes gate if owns_gate was true.
gate_type
Type definition of operation types (also generalized for decomposition classes derived from the class...
GateOperation(Gate *gate, bool owns_gate=true)
Wrap an existing gate.
void apply_single_qubit_unitary(const matrix_base< QGD_Complex16 > &u_2x2, int target_qbit)
Apply single-qubit unitary using local kernel (optimized)
void apply_two_qubit_unitary(const matrix_base< QGD_Complex16 > &u_2x2, int target_qbit, int control_qbit)
Apply two-qubit controlled unitary using local kernel (optimized)
int get_control_qbit()
Call to get the index of the control qubit.
Class to store data of complex arrays and its properties.