58 max_layer_num.insert( std::pair<int, int>(it->first, it->second) );
89 printf(
"Sub-disentaglement already done.\n");
95 printf(
"\nDisentagling submatrices.\n");
105 printf(
"Disentanglig not needed\n");
118 clock_t start_time = time(NULL);
121 int max_layer_num_loc;
126 throw "Layer number not given";
131 int identical_blocks_loc;
134 if (identical_blocks_loc==0) {
135 identical_blocks_loc = 1;
139 identical_blocks_loc=1;
142 while (
layer_num < max_layer_num_loc ) {
147 for (
int target_qbit_loc = 0; target_qbit_loc<control_qbit_loc; target_qbit_loc++ ) {
149 for (
int idx=0; idx<identical_blocks_loc; idx++) {
192 printf(
"--- %f seconds elapsed during the decomposition ---\n\n",
float(time(NULL) - start_time));
202 printf(
"Sub-disentaglement was succesfull.\n\n");
207 printf(
"Sub-disentaglement did not reach the tolerance limit.\n\n");
236 if (solution_guess_gsl == NULL) {
237 solution_guess_gsl = gsl_vector_alloc(num_of_parameters);
246 int iteration_loops_max;
251 iteration_loops_max = 1;
256 for (
int idx=0; idx<iteration_loops_max; idx++) {
261 const gsl_multimin_fdfminimizer_type *T;
262 gsl_multimin_fdfminimizer *s;
267 gsl_multimin_function_fdf my_func;
270 my_func.n = num_of_parameters;
274 my_func.params = par;
277 T = gsl_multimin_fdfminimizer_vector_bfgs2;
278 s = gsl_multimin_fdfminimizer_alloc (T, num_of_parameters);
281 gsl_multimin_fdfminimizer_set (s, &my_func, solution_guess_gsl, 0.1, 0.1);
286 status = gsl_multimin_fdfminimizer_iterate (s);
292 status = gsl_multimin_test_gradient (s->gradient, 1e-1);
297 }
while (status == GSL_CONTINUE && iter < 100);
302 gsl_multimin_fdfminimizer_free (s);
304 for (
int jdx=0; jdx<num_of_parameters; jdx++) {
305 solution_guess_gsl->data[jdx] = solution_guess_gsl->data[jdx] + (2*double(rand())/double(RAND_MAX)-1)*2*M_PI/100;
309 for (
int jdx=0; jdx<num_of_parameters; jdx++) {
310 solution_guess_gsl->data[jdx] = solution_guess_gsl->data[jdx] + (2*double(rand())/double(RAND_MAX)-1)*2*M_PI;
313 gsl_multimin_fdfminimizer_free (s);
340 return cost_function;
353 std::vector<Operation*> operations_loc = instance->
get_operations();
362 return cost_function;
398 for ( std::map<int,int>::iterator it=identical_blocks_in.begin(); it!= identical_blocks_in.end(); it++ ) {
423 printf(
"Sub_Matrix_Decomposition::clone(): extracting operations was not succesfull\n");
bool optimize_layer_num
logical value. Set true to optimize the minimum number of operation layers required in the decomposit...
std::vector< Operation * > get_operations()
Call to get the operations stored in the class.
Matrix get_transformed_matrix(const double *parameters, std::vector< Operation * >::iterator operations_it, int num_of_operations)
Calculate the transformed matrix resulting by an array of operations on the matrix Umtx.
int extract_operations(Operation_block *op_block)
Call to extract the operations stored in the class.
void solve_layer_optimization_problem(int num_of_parameters, gsl_vector *solution_guess_gsl)
Call to solve layer by layer the optimization problem.
Sub_Matrix_Decomposition(Matrix Umtx_in, int qbit_num_in, bool optimize_layer_num_in, guess_type initial_guess_in)
Constructor of the class.
void * qgd_calloc(size_t element_num, size_t size, size_t alignment)
custom defined memory allocation function.
Matrix get_Umtx()
Call to retrive a pointer to the unitary to be transformed.
void disentangle_submatrices()
Start the optimization process to disentangle the most significant qubit from the others.
double current_minimum
The current minimum of the optimization problem.
int set_max_layer_num(int n, int max_layer_num_in)
Set the maximal number of layers used in the subdecomposition of the n-th qubit.
std::map< int, int > max_layer_num
A map of <int n: int num> indicating that how many layers should be used in the subdecomposition proc...
static void optimization_problem_combined(const gsl_vector *parameters, void *void_instance, double *f0, gsl_vector *grad)
Call to calculate both the cost function and the its gradient components.
guess_type initial_guess
type to guess the initial values for the optimization. Possible values: ZEROS=0, RANDOM=1,...
std::map< int, int > identical_blocks
A map of <int n: int num> indicating that how many identical succesive blocks should be used in the d...
int set_identical_blocks(int qbit, int identical_blocks_in)
Set the number of identical successive blocks during the subdecomposition of the qbit-th qubit.
operation_type type
The type of the operation (see enumeration operation_type)
double get_submatrix_cost_function(Matrix &matrix)
Call to calculate the cost function of a given matrix during the submatrix decomposition process.
bool subdisentaglement_done
logical value indicating whether the disentamglement of a qubit from the othetrs was done or not
int qbit_num
number of qubits spanning the matrix of the operation
A class responsible for grouping CNOT and U3 operations into layers.
Operation_block()
Deafult constructor of the class.
Sub_Matrix_Decomposition * clone()
Call to create a clone of the present class.
void set_max_iteration(int max_iterations_in)
Call to set the maximal number of the iterations in the optimization process.
std::map< int, int > iteration_loops
A map of <int n: int num> indicating the number of iteration in each step of the decomposition.
double optimization_problem(const double *parameters)
The optimization problem of the final optimization.
~Sub_Matrix_Decomposition()
Destructor of the class.
unsigned int parameter_num
the number of free parameters of the operation
A class containing basic methods for the decomposition process.
int layer_num
number of operation layers
Class to store data of complex arrays and its properties.
std::vector< Operation * > operations
The list of stored operations.
bool verbose
Logical variable. Set true for verbose mode, or to false to suppress output messages.
Matrix subdecomposed_mtx
The subdecomposed matrix.
guess_type
Type definition of the types of the initial guess.
void add_u3_to_end(int target_qbit, bool Theta, bool Phi, bool Lambda)
Append a U3 gate to the list of operations.
double * optimized_parameters
The optimized parameters for the operations.
void add_operation_to_end(Operation *operation)
Append a general operation to the list of operations.
Header file for a class responsible for the disentanglement of one qubit from the others.
static void optimization_problem_grad(const gsl_vector *parameters, void *void_instance, gsl_vector *grad)
Calculate the approximate derivative (f-f0)/(x-x0) of the cost function with respect to the free para...
void solve_optimization_problem(double *solution_guess, int solution_guess_num)
This method can be used to solve the main optimization problem which is devidid into sub-layer optimi...
Matrix Umtx
The unitary to be decomposed.
static std::map< int, int > max_layer_num_def
A map of <int n: int num> indicating that how many layers should be used in the subdecomposition proc...
bool check_optimization_solution()
check_optimization_solution
A class responsible for the disentanglement of one qubit from the others.
int optimization_block
number of operation blocks used in one shot of the optimization process
void add_cnot_to_end(int control_qbit, int target_qbit)
Append a C_NOT gate operation to the list of operations.
int set_iteration_loops(int n, int iteration_loops_in)
Set the number of iteration loops during the subdecomposition of the n-th qubit.
double global_target_minimum
The global target minimum of the optimization problem.
void set_optimization_blocks(int optimization_block_in)
Call to set the number of operation blocks to be optimized in one shot.
int max_iterations
Maximal number of iterations allowed in the optimization process.