62 CROT::CROT(
int qbit_num_in,
int target_qbit_in,
int control_qbit_in) {
79 std::stringstream sstream;
80 sstream <<
"The index of the control qubit is larger than the number of qubits in CROT gate." << std::endl;
115 for ( std::vector<Matrix>::iterator it=input.begin(); it != input.end(); it++ ) {
131 if ( parallel == 0 ) {
132 work_batch = inputs.size();
139 tbb::parallel_for( tbb::blocked_range<int>(0,inputs.size(),work_batch), [&](tbb::blocked_range<int> r) {
140 for (
int idx=r.begin(); idx<r.end(); ++idx) {
142 Matrix* input = &inputs[idx];
144 apply_to( parameters_mtx, *input, parallel );
163 std::stringstream sstream;
164 sstream <<
"Wrong matrix size in CROT gate apply" << std::endl;
170 double ThetaOver2,
Phi;
173 ThetaOver2 = parameters_mtx[0];
174 Phi = parameters_mtx[1];
179 memset(U_2qbit.
get_data(),0.0,(U_2qbit.
size()*2)*
sizeof(
double));
180 U_2qbit[0].real = std::cos(ThetaOver2);
181 U_2qbit[2].real = std::sin(ThetaOver2)*std::sin(Phi);
182 U_2qbit[2].imag = std::sin(ThetaOver2)*std::cos(Phi);
183 U_2qbit[1*4+3].real = -1.*std::sin(-1.*ThetaOver2)*std::sin(Phi);
184 U_2qbit[1*4+3].imag = -1.*std::sin(-1.*ThetaOver2)*std::cos(Phi);
185 U_2qbit[1*4+1].real = std::cos(-1.*ThetaOver2);
186 U_2qbit[2*4+2].real = std::cos(ThetaOver2);
187 U_2qbit[2*4].real = -1.*std::sin(ThetaOver2)*std::sin(Phi);
188 U_2qbit[2*4].imag = std::sin(ThetaOver2)*std::cos(Phi);
189 U_2qbit[3*4+3].real = std::cos(-1.*ThetaOver2);
190 U_2qbit[3*4+1].real = std::sin(-1.*ThetaOver2)*std::sin(Phi);
191 U_2qbit[3*4+1].imag = -1.*std::sin(-1.*ThetaOver2)*std::cos(Phi);
244 std::stringstream sstream;
245 sstream <<
"Wrong matrix size in CROT gate apply" << std::endl;
250 std::vector<Matrix> ret;
252 double ThetaOver2,
Phi;
255 ThetaOver2 = parameters_mtx[0];
257 Phi = parameters_mtx[1];
268 double Theta0Over2_shifted = ThetaOver2 +
M_PIOver2;
269 double Theta1Over2_shifted;
271 Theta1Over2_shifted = -1.*Theta0Over2_shifted;
279 memset(U_2qbit.
get_data(),0.0,(U_2qbit.
size()*2)*
sizeof(
double));
281 U_2qbit[0].real = std::cos(Theta0Over2_shifted);
282 U_2qbit[2].real = std::sin(Theta0Over2_shifted)*std::sin(Phi);
283 U_2qbit[2].imag = std::sin(Theta0Over2_shifted)*std::cos(Phi);
285 U_2qbit[2*4+2].real = std::cos(Theta0Over2_shifted);
286 U_2qbit[2*4].real = -1.*std::sin(Theta0Over2_shifted)*std::sin(Phi);
287 U_2qbit[2*4].imag = std::sin(Theta0Over2_shifted)*std::cos(Phi);
289 U_2qbit[1*4+3].real = -1.*std::sin(Theta1Over2_shifted)*std::sin(Phi);
290 U_2qbit[1*4+3].imag = -1.*std::sin(Theta1Over2_shifted)*std::cos(Phi);
291 U_2qbit[1*4+1].real = std::cos(Theta1Over2_shifted);
293 U_2qbit[3*4+3].real = std::cos(Theta1Over2_shifted);
294 U_2qbit[3*4+1].real = std::sin(Theta1Over2_shifted)*std::sin(Phi);
295 U_2qbit[3*4+1].imag = -1.*std::sin(Theta1Over2_shifted)*std::cos(Phi);
301 ret.push_back(res_mtx);
305 memset(U_2qbit.
get_data(),0.0,(U_2qbit.
size()*2)*
sizeof(
double));
307 U_2qbit[2].real = std::sin(ThetaOver2)*std::sin(Phi0_shifted);
308 U_2qbit[2].imag = std::sin(ThetaOver2)*std::cos(Phi0_shifted);
310 U_2qbit[2*4].real = -1.*std::sin(ThetaOver2)*std::sin(Phi0_shifted);
311 U_2qbit[2*4].imag = std::sin(ThetaOver2)*std::cos(Phi0_shifted);
313 U_2qbit[1*4+3].real = -1.*std::sin(-1.*ThetaOver2)*std::sin(Phi1_shifted);
314 U_2qbit[1*4+3].imag = -1.*std::sin(-1.*ThetaOver2)*std::cos(Phi1_shifted);
316 U_2qbit[3*4+1].real = std::sin(-1.*ThetaOver2)*std::sin(Phi1_shifted);
317 U_2qbit[3*4+1].imag = -1.*std::sin(-1.*ThetaOver2)*std::cos(Phi1_shifted);
320 ret.push_back(res_mtx1);
332 ret.push_back(res_mtx);
337 U3_matrix[0].real = 0;
338 U3_matrix[0].imag = 0;
339 U3_matrix[3].real = 0;
340 U3_matrix[3].imag = 0;
341 U3_matrix2[0].real = 0;
342 U3_matrix2[0].imag = 0;
343 U3_matrix2[3].real = 0;
344 U3_matrix2[3].imag = 0;
346 ret.push_back(res_mtx1);
405 std::string err(
"CROT::extract_parameters: Cant extract parameters, since the dinput arary has not enough elements.");
414 return extracted_parameters;
std::vector< Gate * > parents
list of parent gates to be applied in the circuit prior to this current gate
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...
void print(const std::stringstream &sstream, int verbose_level=1) const
Call to print output messages in the function of the verbosity level.
virtual void apply_from_right(Matrix_real ¶meters, Matrix &input)
Call to apply the gate on the input array/matrix by input*CROT.
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.
virtual void set_qbit_num(int qbit_num_in)
Set the number of qubits spanning the matrix of the operation.
Header file for a class representing a controlled rotation gate around the Y axis.
int target_qbit
The index of the qubit on which the operation acts (target_qbit >= 0)
int matrix_size
The size N of the NxN matrix associated with the operations.
scalar * get_data() const
Call to get the pointer to the stored data.
A class representing a CROT gate.
void apply_to_list(Matrix_real ¶meters_mtx, std::vector< Matrix > &input)
Call to apply the gate on the input array/matrix by U3*input.
virtual void reorder_qubits(std::vector< int > qbit_list)
Call to reorder the qubits in the matrix of the gate.
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 ...
virtual void apply_to(Matrix_real ¶meters_mtx, Matrix &input, int parallel)
Call to apply the gate on the input array/matrix by CROT3*input.
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.
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.
std::vector< Gate * > children
list of child gates to be applied after this current gate
int parameter_num
the number of free parameters of the operation
virtual void set_qbit_num(int qbit_num_in)
Call to set the number of qubits spanning the matrix of the gate.
virtual CROT * clone()
Call to create a clone of the present class.
CROT()
Nullary constructor of the class.
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.
virtual ~CROT()
Destructor of the class.
int qbit_num
number of qubits spanning the matrix of the operation
virtual std::vector< Matrix > apply_derivate_to(Matrix_real ¶meters_mtx, Matrix &input, int parallel)
Call to evaluate the derivate of the circuit on an inout with respect to all of the free parameters...
virtual void reorder_qubits(std::vector< int > qbit_list)
Call to reorder the qubits in the matrix of the operation.
Class to store data of complex arrays and its properties.