61 R::R(
int qbit_num_in,
int target_qbit_in) {
73 std::stringstream sstream;
74 sstream <<
"The index of the target qubit is larger than the number of qubits" << std::endl;
76 throw "The index of the target qubit is larger than the number of qubits";
109 std::stringstream sstream;
110 sstream <<
"Wrong matrix size in RX gate apply" << std::endl;
118 ThetaOver2 = parameters[0];
123 u3_1qbit[0].real = std::cos(ThetaOver2);
124 u3_1qbit[0].imag = 0;
126 u3_1qbit[1].real = -1.*std::sin(ThetaOver2)*std::sin(Phi);
127 u3_1qbit[1].imag = -1.*std::sin(ThetaOver2)*std::cos(Phi);
129 u3_1qbit[2].real = std::sin(ThetaOver2)*std::sin(Phi);
130 u3_1qbit[2].imag = -1.*std::sin(ThetaOver2)*std::cos(Phi);
132 u3_1qbit[3].real = std::cos(ThetaOver2);
133 u3_1qbit[3].imag = 0;
152 std::stringstream sstream;
153 sstream <<
"Wrong matrix size in U3 apply_from_right" << std::endl;
161 ThetaOver2 = parameters[0];
162 Phi = parameters[1] - M_PI/2;
163 Lambda = -1.*parameters[1] + M_PI/2;
187 std::stringstream sstream;
188 sstream <<
"Wrong matrix size in RX apply_derivate_to" << std::endl;
194 std::vector<Matrix> ret;
198 double ThetaOver2,
Phi;
199 ThetaOver2 = parameters_mtx[0];
200 Phi = parameters_mtx[1];
204 u3_1qbit[0].real = std::cos(ThetaOver2+ M_PI/2);
205 u3_1qbit[0].imag = 0;
207 u3_1qbit[1].real = -1.*std::sin(ThetaOver2+ M_PI/2)*std::sin(Phi);
208 u3_1qbit[1].imag = -1.*std::sin(ThetaOver2+ M_PI/2)*std::cos(Phi);
210 u3_1qbit[2].real = std::sin(ThetaOver2+ M_PI/2)*std::sin(Phi);
211 u3_1qbit[2].imag = -1.*std::sin(ThetaOver2+ M_PI/2)*std::cos(Phi);
213 u3_1qbit[3].real = std::cos(ThetaOver2+ M_PI/2);
214 u3_1qbit[3].imag = 0;
217 ret.push_back(res_mtx);
222 u3_1qbit[0].real = 0;
223 u3_1qbit[0].imag = 0;
225 u3_1qbit[1].real = -1.*std::sin(ThetaOver2)*std::sin(Phi+ M_PI/2);
226 u3_1qbit[1].imag = -1.*std::sin(ThetaOver2)*std::cos(Phi+ M_PI/2);
228 u3_1qbit[2].real = std::sin(ThetaOver2)*std::sin(Phi+ M_PI/2);
229 u3_1qbit[2].imag = -1.*std::sin(ThetaOver2)*std::cos(Phi+ M_PI/2);
231 u3_1qbit[3].real = 0;
232 u3_1qbit[3].imag = 0;
235 ret.push_back(res_mtx2);
271 std::string err(
"R::extract_parameters: Cant extract parameters, since the dinput arary has not enough elements.");
280 return extracted_parameters;
std::vector< Gate * > parents
list of parent gates to be applied in the circuit prior to this current gate
void print(const std::stringstream &sstream, int verbose_level=1) const
Call to print output messages in the function of the verbosity level.
Header file for a class representing a rotation gate around the X axis.
virtual std::vector< Matrix > apply_derivate_to(Matrix_real ¶meters, Matrix &input, int parallel)
Call to evaluate the derivate of the circuit on an inout with respect to all of the free parameters...
int control_qbit
The index of the qubit which acts as a control qubit (control_qbit >= 0) in controlled operations...
void set_children(std::vector< Gate *> &children_)
Call to set the children of the current gate.
int target_qbit
The index of the qubit on which the operation acts (target_qbit >= 0)
void apply_kernel_from_right(Matrix &u3_1qbit, Matrix &input)
Call to apply the gate kernel on the input state or unitary from right (no AVX support) ...
int matrix_size
The size N of the NxN matrix associated with the operations.
~R()
Destructor of the class.
virtual Matrix_real extract_parameters(Matrix_real ¶meters)
Call to extract parameters from the parameter array corresponding to the circuit, in which the gate i...
gate_type type
The type of the operation (see enumeration gate_type)
int rows
The number of rows.
int cols
The number of columns.
void set_parameter_start_idx(int start_idx)
Call to set the starting index of the parameters in the parameter array corresponding to the circuit ...
int get_parameter_start_idx()
Call to get the starting index of the parameters in the parameter array corresponding to the circuit ...
void apply_from_right(Matrix_real ¶meters, Matrix &input)
Call to apply the gate on the input array/matrix by input*U3.
R()
Nullary constructor of the class.
virtual Matrix calc_one_qubit_u3()
Calculate the matrix of the constans gates.
int Power_of_2(int n)
Calculates the n-th power of 2.
Class to store data of complex arrays and its properties.
void apply_to(Matrix_real ¶meters, Matrix &input, int parallel)
Call to apply the gate on the input array/matrix by R*input.
int size() const
Call to get the number of the allocated elements.
int get_parameter_num()
Call to get the number of free parameters.
std::string name
A string labeling the gate operation.
A class representing a U3 gate.
std::vector< Gate * > children
list of child gates to be applied after this current gate
void apply_kernel_to(Matrix &u3_1qbit, Matrix &input, bool deriv=false, int parallel=0)
Call to apply the gate kernel on the input state or unitary with optional AVX support.
R * clone()
Call to create a clone of the present class.
int parameter_num
the number of free parameters of the operation
void set_parents(std::vector< Gate *> &parents_)
Call to set the parents of the current gate.
Matrix copy()
Call to create a copy of the matrix.
int qbit_num
number of qubits spanning the matrix of the operation
Class to store data of complex arrays and its properties.