76 CNOT* cnot_operation = static_cast<CNOT*>(operation);
77 delete cnot_operation;
81 U3* u3_operation = static_cast<U3*>(operation);
87 Operation_block* block_operation = static_cast<Operation_block*>(operation);
88 delete block_operation;
109 vector<Matrix> operation_mtxs =
get_matrices( parameters );
114 operation_mtxs.clear();
125 QGD_Complex16* Operation_block::matrix(
const double* parameters ) {
128 vector<Matrix> operation_mtxs =
get_matrices( parameters );
133 operation_mtxs.clear();
147 int Operation_block::matrix(
const double* parameters,
QGD_Complex16* block_mtx ) {
150 vector<Matrix> operation_mtxs =
get_matrices( parameters );
155 operation_mtxs.clear();
176 std::vector<Matrix> matrices;
185 CNOT* cnot_operation = static_cast<CNOT*>(operation);
191 U3* u3_operation = static_cast<U3*>(operation);
194 operation_mtx = u3_operation->
get_matrix( parameters );
195 parameters = parameters + 1;
198 operation_mtx = u3_operation->
get_matrix( parameters );
199 parameters = parameters + 2;
202 operation_mtx = u3_operation->
get_matrix( parameters );
203 parameters = parameters + 3;
206 printf(
"The U3 operation has wrong number of parameters");
207 throw "The U3 operation has wrong number of parameters";
215 matrices.push_back(operation_mtx);
297 for(std::vector<Operation*>::iterator it = operations_in.begin(); it != operations_in.end(); ++it) {
311 for(std::vector<Operation*>::iterator it = operations_in.end(); it != operations_in.begin(); --it) {
382 Operation_block* block_operation = static_cast<Operation_block*>(operation);
384 gate_nums.
u3 = gate_nums.
u3 + gate_nums_loc.
u3;
388 gate_nums.
u3 = gate_nums.
u3 + 1;
391 gate_nums.
cnot = gate_nums.
cnot + 1;
430 printf(
"\nThe operations in the list of operations:\n" );
432 int operation_idx = start_index;
435 for(
int op_idx =
operations.size()-1; op_idx>=0; op_idx--) {
440 CNOT* cnot_operation = static_cast<CNOT*>(operation);
442 printf(
"%dth operation: CNOT with control qubit: %d and target qubit: %d\n", operation_idx, cnot_operation->
get_control_qbit(), cnot_operation->
get_target_qbit() );
443 operation_idx = operation_idx + 1;
454 U3* u3_operation = static_cast<U3*>(operation);
457 vartheta = std::fmod( parameters[parameter_idx-1], 4*M_PI);
460 parameter_idx = parameter_idx - 1;
465 varphi = std::fmod( parameters[ parameter_idx-1 ], 2*M_PI);
467 parameter_idx = parameter_idx - 1;
472 varlambda = std::fmod( parameters[ parameter_idx-1 ], 2*M_PI);
473 parameter_idx = parameter_idx - 1;
476 vartheta = std::fmod( parameters[ parameter_idx-2 ], 4*M_PI);
477 varphi = std::fmod( parameters[ parameter_idx-1 ], 2*M_PI);
479 parameter_idx = parameter_idx - 2;
482 vartheta = std::fmod( parameters[ parameter_idx-2 ], 4*M_PI);
484 varlambda = std::fmod( parameters[ parameter_idx-1 ], 2*M_PI);
485 parameter_idx = parameter_idx - 2;
489 varphi = std::fmod( parameters[ parameter_idx-2], 2*M_PI);
490 varlambda = std::fmod( parameters[ parameter_idx-1 ], 2*M_PI);
491 parameter_idx = parameter_idx - 2;
494 vartheta = std::fmod( parameters[ parameter_idx-3 ], 4*M_PI);
495 varphi = std::fmod( parameters[ parameter_idx-2 ], 2*M_PI);
496 varlambda = std::fmod( parameters[ parameter_idx-1 ], 2*M_PI);
497 parameter_idx = parameter_idx - 3;
501 printf(
"%dth operation: U3 on target qubit: %d and with parameters theta = %f, phi = %f and lambda = %f\n", operation_idx, u3_operation->
get_target_qbit(), vartheta, varphi, varlambda );
502 operation_idx = operation_idx + 1;
506 Operation_block* block_operation = static_cast<Operation_block*>(operation);
507 const double* parameters_layer = parameters + parameter_idx - operation->
get_parameter_num();
529 CNOT* cnot_operation = static_cast<CNOT*>(operation);
533 U3* u3_operation = static_cast<U3*>(operation);
537 Operation_block* block_operation = static_cast<Operation_block*>(operation);
554 std::vector<int> involved_qbits;
576 return involved_qbits;
596 std::vector<Operation*> operations_in = op_block->
get_operations();
598 for(std::vector<Operation*>::iterator it = (operations_in).begin(); it != (operations_in).end(); ++it) {
602 CNOT* cnot_op = static_cast<CNOT*>( op );
604 Operation* op_cloned = static_cast<Operation*>( cnot_op_cloned );
608 U3* u3_op = static_cast<U3*>( op );
609 U3* u3_op_cloned = u3_op->
clone();
610 Operation* op_cloned = static_cast<Operation*>( u3_op_cloned );
616 Operation* op_cloned = static_cast<Operation*>( block_op_cloned );
643 CNOT* cnot_op = static_cast<CNOT*>( op );
647 U3* u3_op = static_cast<U3*>( op );
672 printf(
"Operation_block::clone(): extracting operations was not succesfull\n");
694 CNOT* cnot_op = static_cast<CNOT*>( op );
696 Operation* op_cloned = static_cast<Operation*>( cnot_op_cloned );
700 U3* u3_op = static_cast<U3*>( op );
701 U3* u3_op_cloned = u3_op->
clone();
702 Operation* op_cloned = static_cast<Operation*>( u3_op_cloned );
708 Operation* op_cloned = static_cast<Operation*>( block_op_cloned );
Operation * clone()
Call to create a clone of the present class.
A class representing a U3 operation.
void reorder_qubits(std::vector< int > qbit_list)
Call to reorder the qubits in the matrix of the operations.
void add_operations_to_end(std::vector< Operation * > operations_in)
Append a list of operations to the list of operations.
std::vector< Operation * > get_operations()
Call to get the operations stored in the class.
int extract_operations(Operation_block *op_block)
Call to extract the operations stored in the class.
Base class for the representation of one- and two-qubit operations.
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.
int get_parameter_num()
Call to get the number of free parameters.
Operation_block * clone()
Create a clone of the present class.
std::vector< Matrix > get_matrices(const double *parameters)
Call to get the list of matrix representation of the operations grouped in the block.
int get_target_qbit()
Call to get the index of the target qubit.
Structure type conatining numbers of gates.
scalar * get_data()
Call to get the pointer to the stored data.
void list_operations(const double *parameters, int start_index)
Call to print the list of operations stored in the block of operations for a specific set of paramete...
void combine(Operation_block *op_block)
Call to append the operations of an operation block to the current block.
bool is_theta_parameter()
Call to check whether theta is a free parameter of the gate.
void reorder_qubits(std::vector< int > qbit_list)
Call to reorder the qubits in the matrix of the operation.
Header file for a class representing a CNOT operation.
U3 * clone()
Call to create a clone of the present class.
operation_type type
The type of the operation (see enumeration operation_type)
Matrix reduce_zgemm(std::vector< Matrix > &mtxs)
Calculate the product of several square shaped complex matrices stored in a vector.
int u3
The number of U3 gates.
int general
The number of general gates.
void reorder_qubits(std::vector< int > qbit_list)
Call to reorder the qubits in the matrix of the operation.
int qbit_num
number of qubits spanning the matrix of the operation
std::vector< int > get_involved_qubits()
Call to get the qubits involved in the operations stored in the block of operations.
void release_operations()
Call to release the stored operations.
A class responsible for grouping CNOT and U3 operations into layers.
Operation_block()
Deafult constructor of the class.
CNOT * clone()
Call to create a clone of the present class.
virtual ~Operation_block()
Destructor of the class.
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.
gates_num get_gate_nums()
Call to get the number of the individual gate types in the list of operations.
Structure type representing complex numbers in the QGD package.
A class representing a CNOT operation.
int layer_num
number of operation layers
void set_qbit_num(int qbit_num)
Call to set the number of qubits spanning the matrix of the operation.
Matrix get_matrix()
Call to retrieve the operation matrix.
Class to store data of complex arrays and its properties.
std::vector< Operation * > operations
The list of stored operations.
unsigned int get_parameter_num()
Call to get the number of free parameters.
Header file for a class representing a U3 operation.
void add_u3_to_end(int target_qbit, bool Theta, bool Phi, bool Lambda)
Append a U3 gate to the list of operations.
void add_operation_to_end(Operation *operation)
Append a general operation to the list of operations.
void add_operation_to_front(Operation *operation)
Add an operation to the front of the list of operations.
operation_type get_type()
Call to get the type of the operation.
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.
Matrix get_matrix(const double *parameters)
Call to retrieve the operation matrix.
virtual void set_qbit_num(int qbit_num_in)
Set the number of qubits spanning the matrix of the operation.
void add_unique_elelement(std::vector< int > &involved_qbits, int qbit)
Add an integer to a vector of integers if the integer is not already an element of the vector.
int get_operation_num()
Call to get the number of operations grouped in the class.
Matrix get_matrix()
Call to retrieve the operation matrix.
void set_qbit_num(int qbit_num_in)
Call to set the number of qubits spanning the matrix of the operation.
int get_control_qbit()
Call to get the index of the control qubit.
Header file for a class responsible for grouping CNOT and U3 operations into layers.
void add_cnot_to_end(int control_qbit, int target_qbit)
Append a C_NOT gate operation to the list of operations.
int cnot
The number of CNOT gates.
size_t size()
Call to get the number of the allocated elements.
void set_qbit_num(int qbit_num_in)
Set the number of qubits spanning the matrix of the operations stored in the block of operations.
void add_cnot_to_front(int control_qbit, int target_qbit)
Add a C_NOT gate operation to the front of the list of operations.
void add_u3_to_front(int target_qbit, bool Theta, bool Phi, bool Lambda)
Add a U3 gate to the front of the list of operations.
void add_operations_to_front(std::vector< Operation * > operations_in)
Add an array of operations to the front of the list of operations.