36 U3::U3(
int qbit_num_in,
int target_qbit_in,
bool theta_in,
bool phi_in,
bool lambda_in) {
47 printf(
"The index of the target qubit is larger than the number of qubits");
48 throw "The index of the target qubit is larger than the number of qubits";
301 U3_matrix[element_index] = u3_1qbit[0];
305 U3_matrix[element_index] = u3_1qbit[1];
309 U3_matrix[element_index] = u3_1qbit[2];
313 U3_matrix[element_index] = u3_1qbit[3];
343 int indexes_target_qubit_1_idx = 0;
344 int indexes_target_qubit_0_idx = 0;
349 int bit = int(idx/target_qbit_power) % 2;
352 indexes_target_qubit_0_idx++;
356 indexes_target_qubit_1_idx++;
436 double cos_theta = cos(Theta/2);
437 double sin_theta = sin(Theta/2);
440 u3_1qbit[0].real = cos_theta;
441 u3_1qbit[0].imag = 0;
443 u3_1qbit[1].real = -cos(Lambda)*sin_theta;
444 u3_1qbit[1].imag = -sin(Lambda)*sin_theta;
446 u3_1qbit[2].real = cos(Phi)*sin_theta;
447 u3_1qbit[2].imag = sin(Phi)*sin_theta;
449 u3_1qbit[3].real = cos(Phi+Lambda)*cos_theta;
450 u3_1qbit[3].imag = sin(Phi+Lambda)*cos_theta;
504 memcpy( parameters_in,
parameters, 3*
sizeof(
double) );
A class representing a U3 operation.
int composite_u3_Lambda(const double *parameters, Matrix &U3_matrix)
Calculate the matrix of a U3 gate operation corresponding to the given parameters acting on the space...
int composite_u3_Theta_Lambda(const double *parameters, Matrix &U3_matrix)
Calculate the matrix of a U3 gate operation corresponding to the given parameters acting on the space...
int * indexes_target_qubit_0
the base indices of the target qubit for state |0>
int target_qbit
The index of the qubit on which the operation acts (target_qbit >= 0)
int control_qbit
The index of the qubit which acts as a control qubit (control_qbit >= 0) in controlled operations.
void determine_base_indices()
Determine the base indices corresponding to the target qubit states |0> and |1>
void * qgd_calloc(size_t element_num, size_t size, size_t alignment)
custom defined memory allocation function.
void qgd_free(void *ptr)
custom defined memory release function.
scalar * get_data()
Call to get the pointer to the stored data.
void get_optimized_parameters(double *parameters_in)
Call to get the final optimized parameters of the operation.
Matrix calc_one_qubit_u3(double Theta, double Phi, double Lambda)
Calculate the matrix of a U3 gate operation corresponding to the given parameters acting on a single ...
void set_optimized_parameters(double Theta, double Phi, double Lambda)
Call to set the final optimized parameters of the operation.
int composite_u3_Theta_Phi_Lambda(const double *parameters, Matrix &U3_matrix)
Calculate the matrix of a U3 gate operation corresponding to the given parameters acting on the space...
int matrix_size
The size N of the NxN matrix associated with the operations.
bool is_theta_parameter()
Call to check whether theta is a free parameter of the gate.
virtual void reorder_qubits(std::vector< int > qbit_list)
Call to reorder the qubits in the matrix of the operation.
void reorder_qubits(std::vector< int > qbit_list)
Call to reorder the qubits in the matrix of the operation.
U3 * clone()
Call to create a clone of the present class.
int composite_u3_Phi_Lambda(const double *parameters, Matrix &U3_matrix)
Calculate the matrix of a U3 gate operation corresponding to the given parameters acting on the space...
operation_type type
The type of the operation (see enumeration operation_type)
U3(int qbit_num_in, int target_qbit_in, bool theta_in, bool phi_in, bool lambda_in)
Constructor of the class.
QGD_Complex16 * composite_u3(double Theta, double Phi, double Lambda)
Calculate the matrix of a U3 gate operation corresponding corresponding to the given parameters actin...
int composite_u3_Theta(const double *parameters, Matrix &U3_matrix)
Calculate the matrix of a U3 gate operation corresponding to the given parameters acting on the space...
int qbit_num
number of qubits spanning the matrix of the operation
bool phi
logical value indicating whether the matrix creation takes an argument phi
int * indexes_target_qubit_1
the base indices of the target qubit for state |1>
unsigned int parameter_num
the number of free parameters of the operation
void set_owner(bool owner_in)
Call to set the current class instance to be (or not to be) the owner of the stored data array.
Structure type representing complex numbers in the QGD package.
int Power_of_2(int n)
Calculates the n-th power of 2.
Matrix get_matrix()
Call to retrieve the operation matrix.
Class to store data of complex arrays and its properties.
Header file for a class representing a U3 operation.
bool theta
logical value indicating whether the matrix creation takes an argument theta
~U3()
Destructor of the class.
bool is_lambda_parameter()
Call to check whether Lambda is a free parameter of the gate.
bool is_phi_parameter()
Call to check whether Phi is a free parameter of the gate.
bool lambda
logical value indicating whether the matrix creation takes an argument lambda
virtual void set_qbit_num(int qbit_num_in)
Set the number of qubits spanning the matrix of the operation.
double * parameters
Parameters theta, phi, lambda of the U3 operation after the decomposition of the unitary is done.
int composite_u3_Phi(const double *parameters, Matrix &U3_matrix)
Calculate the matrix of a U3 gate operation corresponding to the given parameters acting on the space...
void set_qbit_num(int qbit_num_in)
Call to set the number of qubits spanning the matrix of the operation.
size_t size()
Call to get the number of the allocated elements.
int composite_u3_Theta_Phi(const double *parameters, Matrix &U3_matrix)
Calculate the matrix of a U3 gate operation corresponding to the given parameters acting on the space...