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;
110 std::vector<Matrix> operation_mtxs =
get_matrices( parameters );
127 std::vector<Matrix> matrices;
136 CNOT* cnot_operation = static_cast<CNOT*>(operation);
142 U3* u3_operation = static_cast<U3*>(operation);
145 operation_mtx = u3_operation->
get_matrix( parameters );
146 parameters = parameters + 1;
149 operation_mtx = u3_operation->
get_matrix( parameters );
150 parameters = parameters + 2;
153 operation_mtx = u3_operation->
get_matrix( parameters );
154 parameters = parameters + 3;
157 printf(
"The U3 operation has wrong number of parameters");
158 throw "The U3 operation has wrong number of parameters";
166 matrices.push_back(operation_mtx);
248 for(std::vector<Operation*>::iterator it = operations_in.begin(); it != operations_in.end(); ++it) {
262 for(std::vector<Operation*>::iterator it = operations_in.end(); it != operations_in.begin(); --it) {
333 Operation_block* block_operation = static_cast<Operation_block*>(operation);
335 gate_nums.
u3 = gate_nums.
u3 + gate_nums_loc.
u3;
339 gate_nums.
u3 = gate_nums.
u3 + 1;
342 gate_nums.
cnot = gate_nums.
cnot + 1;
381 printf(
"\nThe operations in the list of operations:\n" );
383 int operation_idx = start_index;
386 for(
int op_idx =
operations.size()-1; op_idx>=0; op_idx--) {
391 CNOT* cnot_operation = static_cast<CNOT*>(operation);
393 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() );
394 operation_idx = operation_idx + 1;
405 U3* u3_operation = static_cast<U3*>(operation);
408 vartheta = std::fmod( parameters[parameter_idx-1], 4*M_PI);
411 parameter_idx = parameter_idx - 1;
416 varphi = std::fmod( parameters[ parameter_idx-1 ], 2*M_PI);
418 parameter_idx = parameter_idx - 1;
423 varlambda = std::fmod( parameters[ parameter_idx-1 ], 2*M_PI);
424 parameter_idx = parameter_idx - 1;
427 vartheta = std::fmod( parameters[ parameter_idx-2 ], 4*M_PI);
428 varphi = std::fmod( parameters[ parameter_idx-1 ], 2*M_PI);
430 parameter_idx = parameter_idx - 2;
433 vartheta = std::fmod( parameters[ parameter_idx-2 ], 4*M_PI);
435 varlambda = std::fmod( parameters[ parameter_idx-1 ], 2*M_PI);
436 parameter_idx = parameter_idx - 2;
440 varphi = std::fmod( parameters[ parameter_idx-2], 2*M_PI);
441 varlambda = std::fmod( parameters[ parameter_idx-1 ], 2*M_PI);
442 parameter_idx = parameter_idx - 2;
445 vartheta = std::fmod( parameters[ parameter_idx-3 ], 4*M_PI);
446 varphi = std::fmod( parameters[ parameter_idx-2 ], 2*M_PI);
447 varlambda = std::fmod( parameters[ parameter_idx-1 ], 2*M_PI);
448 parameter_idx = parameter_idx - 3;
452 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 );
453 operation_idx = operation_idx + 1;
457 Operation_block* block_operation = static_cast<Operation_block*>(operation);
458 const double* parameters_layer = parameters + parameter_idx - operation->
get_parameter_num();
480 CNOT* cnot_operation = static_cast<CNOT*>(operation);
484 U3* u3_operation = static_cast<U3*>(operation);
488 Operation_block* block_operation = static_cast<Operation_block*>(operation);
505 std::vector<int> involved_qbits;
527 return involved_qbits;
547 std::vector<Operation*> operations_in = op_block->
get_operations();
549 for(std::vector<Operation*>::iterator it = (operations_in).begin(); it != (operations_in).end(); ++it) {
553 CNOT* cnot_op = static_cast<CNOT*>( op );
555 Operation* op_cloned = static_cast<Operation*>( cnot_op_cloned );
559 U3* u3_op = static_cast<U3*>( op );
560 U3* u3_op_cloned = u3_op->
clone();
561 Operation* op_cloned = static_cast<Operation*>( u3_op_cloned );
567 Operation* op_cloned = static_cast<Operation*>( block_op_cloned );
594 CNOT* cnot_op = static_cast<CNOT*>( op );
598 U3* u3_op = static_cast<U3*>( op );
623 printf(
"Operation_block::clone(): extracting operations was not succesfull\n");
645 CNOT* cnot_op = static_cast<CNOT*>( op );
647 Operation* op_cloned = static_cast<Operation*>( cnot_op_cloned );
651 U3* u3_op = static_cast<U3*>( op );
652 U3* u3_op_cloned = u3_op->
clone();
653 Operation* op_cloned = static_cast<Operation*>( u3_op_cloned );
659 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.
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
gates_num get_gate_nums()
Call to get the number of the individual gate types in the list of operations.
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.
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.