59 U3::U3(
int qbit_num_in,
int target_qbit_in) {
72 std::stringstream sstream;
73 sstream <<
"The index of the target qubit is larger than the number of qubits" << std::endl;
75 throw "The index of the target qubit is larger than the number of qubits";
118 apply_to(parameters, U3_matrix, parallel);
121 if (U3_matrix.
isnan()) {
122 std::stringstream sstream;
123 sstream <<
"U3::get_matrix: U3_matrix contains NaN." << std::endl;
125 print(sstream,verbose_level);
144 if ( parallel == 0 ) {
145 work_batch = inputs.size();
152 tbb::parallel_for( tbb::blocked_range<int>(0,inputs.size(),work_batch), [&](tbb::blocked_range<int> r) {
153 for (
int idx=r.begin(); idx<r.end(); ++idx) {
155 Matrix* input = &inputs[idx];
157 apply_to( parameters_mtx, *input, parallel );
176 std::string err(
"U3::apply_to: Wrong input size in U3 gate apply.");
180 double ThetaOver2 = parameters_mtx[0];
181 double Phi = parameters_mtx[1];
182 double Lambda = parameters_mtx[2];
199 std::string err(
"U3::apply_from_right: Wrong matrix size in U3 apply_from_right.");
203 double ThetaOver2 = parameters_mtx[0];
204 double Phi = parameters_mtx[1];
205 double Lambda = parameters_mtx[2];
223 std::string err(
"U3::apply_derivate_to: Wrong matrix size in U3 gate apply.");
227 std::vector<Matrix> ret;
229 double ThetaOver2 = parameters_mtx[0];
230 double Phi = parameters_mtx[1];
231 double Lambda = parameters_mtx[2];
238 ret.push_back(res_mtx_theta);
245 ret.push_back(res_mtx_phi);
253 ret.push_back(res_mtx_lambda);
300 std::string err(
"U3::extract_parameters: Cant extract parameters, since the dinput arary has not enough elements.");
310 return extracted_parameters;
std::vector< Gate * > parents
list of parent gates to be applied in the circuit prior to this current gate
bool isnan()
Call to check the array for NaN entries.
A class representing a U3 gate.
void print(const std::stringstream &sstream, int verbose_level=1) const
Call to print output messages in the function of the verbosity level.
virtual Matrix get_matrix()
Call to retrieve the operation matrix.
virtual void apply_to(Matrix_real ¶meters, Matrix &input, int parallel)
Call to apply the gate on the input array/matrix by U3*input.
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.
U3()
Nullary constructor of the class.
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) ...
void apply_to_list(Matrix_real ¶meters, std::vector< Matrix > &inputs, int parallel)
Call to apply the gate on the input array/matrix by U3*input.
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.
virtual void reorder_qubits(std::vector< int > qbit_list)
Call to reorder the qubits in the matrix of the gate.
virtual U3 * clone()
Call to create a clone of the present class.
gate_type type
The type of the operation (see enumeration gate_type)
virtual void apply_from_right(Matrix_real ¶meters, Matrix &input)
Call to apply the gate on the input array/matrix by input*U3.
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 ...
Structure type representing complex numbers in the SQUANDER package.
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.
Header file for a class representing a U3 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...
std::string name
A string labeling the gate operation.
std::vector< Gate * > children
list of child gates to be applied after this current gate
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...
virtual ~U3()
Destructor of the class.
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.
Matrix create_identity(int matrix_size)
Call to create an identity matrix.
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
virtual void set_qbit_num(int qbit_num_in)
Call to set the number of qubits spanning the matrix of the gate.
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.