38 extern "C" int LAPACKE_dgesv(
int matrix_layout,
int n,
int nrhs,
double *a,
int lda,
int *ipiv,
double *b,
int ldb);
86 std::uniform_int_distribution<> distrib_int(0, INT_MAX);
87 int id = distrib_int(
gen);
125 max_layer_num.insert( std::pair<int, int>(it->first, it->second) );
150 std::uniform_int_distribution<> distrib_int(0, INT_MAX);
151 id = distrib_int(
gen);
163 #elif defined __GROQ__ 211 std::string
filename(
"costfuncs_and_entropy.txt");
217 const char* c_filename = filename.c_str();
218 pFile = fopen(c_filename,
"a");
221 fputs (
"File error",stderr);
222 std::string error(
"Cannot open file.");
228 std::uniform_int_distribution<> distrib(0,
qbit_num-2);
230 memset(input_state.
get_data(), 0.0, (input_state.
size()*2)*
sizeof(
double) );
231 input_state[0].real = 1.0;
239 fprintf(pFile,
"%i\t%f\t%f\n", (
int)
number_of_iters, current_minimum, renyi_entropy);
273 for (
int qbit=0; qbit<
qbit_num; qbit++) {
357 double d = 1.0/decomposed_matrix.
cols;
362 double d = 1.0/decomposed_matrix.
cols;
372 std::string err(
"Optimization_Interface::optimization_problem: Cost function variant not implmented.");
386 std::stringstream sstream;
387 sstream <<
"***************************************************************" << std::endl;
388 sstream <<
"Final fine tuning of the parameters in the " <<
qbit_num <<
"-qubit decomposition" << std::endl;
389 sstream <<
"***************************************************************" << std::endl;
455 std::string error(
"Optimization_Interface::solve_layer_optimization_problem: unimplemented optimization algorithm");
471 std::uniform_real_distribution<> distrib_prob(0.0, 1.0);
472 std::uniform_real_distribution<> distrib_real(-2*M_PI, 2*M_PI);
476 if (
config.count(
"Randomized_Radius") > 0 ) {
477 config[
"Randomized_Radius"].get_property( radius_loc );
485 int changed_parameters = 0;
488 output[jdx] = (
cost_fnc!=
VQE) ? input[jdx] + distrib_real(
gen)*std::sqrt(f0)*radius_loc : input[jdx] + distrib_real(
gen)*radius_loc;
489 changed_parameters++;
492 output[jdx] = input[jdx];
530 std::stringstream sstream;
531 sstream <<
"Optimization_Interface::optimization_problem: Number of free paramaters should be " <<
parameter_num <<
", but got " << parameters.
size() << std::endl;
533 std::string err(
"Optimization_Interface::optimization_problem: Wrong number of parameters.");
556 double d = 1.0/matrix_new.
cols;
561 double d = 1.0/matrix_new.
cols;
571 std::string err(
"Optimization_Interface::optimization_problem: Cost function variant not implmented.");
584 Optimization_Interface::optimization_problem_batched_DFE( std::vector<Matrix_real>& parameters_vec) {
587 Matrix_real cost_fnc_mtx(parameters_vec.size(), 1);
589 int gatesNum, gateSetNum, redundantGateSets;
590 DFEgate_kernel_type* DFEgates = convert_to_batched_DFE_gates( parameters_vec, gatesNum, gateSetNum, redundantGateSets );
604 int mpi_starting_gateSetIdx = gateSetNum/
world_size * current_rank;
616 int bytes = mpi_trace_DFE_mtx.
size()*
sizeof(double);
617 MPI_Allgather(mpi_trace_DFE_mtx.
get_data(), bytes, MPI_BYTE, trace_DFE_mtx.
get_data(), bytes, MPI_BYTE, MPI_COMM_WORLD);
629 for (
int idx=0; idx<parameters_vec.size(); idx++ ) {
630 cost_fnc_mtx[idx] = 1-trace_DFE_mtx[idx*3]/
Umtx.
cols;
634 for (
int idx=0; idx<parameters_vec.size(); idx++ ) {
639 for (
int idx=0; idx<parameters_vec.size(); idx++ ) {
644 std::string err(
"Optimization_Interface::optimization_problem_batched: Cost function variant not implmented for DFE.");
673 throw std::string(
"Optimization_Interface::optimization_problem_Groq should be implemented in derrived classes.");
687 Optimization_Interface::optimization_problem_batched_Groq( std::vector<Matrix_real>& parameters_vec) {
689 int task_num = parameters_vec.
size();
699 int chosen_device = 0;
701 for(
int idx=0; idx<task_num; idx++ ) {
702 cost_fnc_mtx[idx] = optimization_problem_Groq( parameters_vec[idx], chosen_device );
708 for(
int idx=0; idx<task_num; idx=idx+2 ) {
709 tbb::parallel_invoke(
710 [&]() { cost_fnc_mtx[idx] = optimization_problem_Groq( parameters_vec[idx], 0 ); },
711 [&]() {
if ( (idx+1) < task_num ) cost_fnc_mtx[idx+1] = optimization_problem_Groq( parameters_vec[idx+1], 1 ); }
717 throw std::string(
"Unsupported number of Groq accelerators.");
740 return optimization_problem_batched_DFE( parameters_vec );
742 #elif defined __GROQ__ 744 return optimization_problem_batched_Groq( parameters_vec );
749 Matrix_real cost_fnc_mtx(parameters_vec.size(), 1);
757 int batch_element_num = parameters_vec.size();
758 int mpi_batch_element_num = batch_element_num /
world_size;
759 int mpi_batch_element_remainder = batch_element_num %
world_size;
761 if ( mpi_batch_element_remainder > 0 ) {
762 std::string err(
"Optimization_Interface::optimization_problem_batched: The size of the batch should be divisible with the number of processes.");
766 int mpi_starting_batchIdx = mpi_batch_element_num * current_rank;
769 Matrix_real cost_fnc_mtx_loc(mpi_batch_element_num, 1);
773 work_batch = mpi_batch_element_num;
776 tbb::parallel_for( tbb::blocked_range<int>(0, (
int)mpi_batch_element_num, work_batch), [&](tbb::blocked_range<int> r) {
777 for (
int idx=r.begin(); idx<r.end(); ++idx) {
786 int bytes = cost_fnc_mtx_loc.
size()*
sizeof(double);
787 MPI_Allgather(cost_fnc_mtx_loc.
get_data(), bytes, MPI_BYTE, cost_fnc_mtx.get_data(), bytes, MPI_BYTE, MPI_COMM_WORLD);
794 work_batch = parameters_vec.size();
797 tbb::parallel_for( tbb::blocked_range<int>(0, (
int)parameters_vec.size(), work_batch), [&](tbb::blocked_range<int> r) {
798 for (
int idx=r.begin(); idx<r.end(); ++idx) {
825 std::vector<Gate*> gates_loc = instance->
get_gates();
837 instance->
apply_to( parameters, matrix_new );
857 ret_temp[0].real = trace_temp.
real;
858 ret_temp[0].imag = trace_temp.
imag;
859 double d = 1.0/matrix_new.
cols;
860 return 1.0-d*d*trace_temp.
real*trace_temp.
real-d*d*trace_temp.
imag*trace_temp.
imag;
865 double d = 1.0/matrix_new.
cols;
866 for (
int idx=0; idx<3; idx++){ret_temp[idx].real=ret[idx].real;ret_temp[idx].imag=ret[idx].imag;}
873 double d = 1.0/matrix_new.
cols;
874 for (
int idx=0; idx<4; idx++){ret_temp[idx].real=ret[idx].real;ret_temp[idx].imag=ret[idx].imag;}
875 return 1.0 - d*d*(ret[0].real*ret[0].real+ret[0].imag*ret[0].imag+std::sqrt(instance->
get_previous_cost_function_value())*(correction1_scale*(ret[1].
real*ret[1].
real+ret[1].imag*ret[1].imag)+correction2_scale*(ret[2].real*ret[2].real+ret[2].imag*ret[2].imag)));
882 ret_temp[0].real = trace_temp.
real;
883 ret_temp[0].imag = trace_temp.
imag;
884 double d = matrix_new.
cols;
885 return 1.0-((trace_temp.
real*trace_temp.
real+trace_temp.
imag*trace_temp.
imag)/d+1)/(d+1);
888 std::string err(
"Optimization_Interface::optimization_problem: Cost function variant not implmented.");
985 int gatesNum, redundantGateSets, gateSetNum;
986 DFEgate_kernel_type* DFEgates = instance->convert_to_DFE_gates_with_derivates( parameters, gatesNum, gateSetNum, redundantGateSets );
995 int mpi_gateSetNum = gateSetNum / instance->world_size;
996 int mpi_starting_gateSetIdx = gateSetNum/instance->world_size * instance->current_rank;
1003 calcqgdKernelDFE( Umtx_loc.
rows, Umtx_loc.
cols, DFEgates+mpi_starting_gateSetIdx*gatesNum, gatesNum, mpi_gateSetNum, trace_offset_loc, mpi_trace_DFE_mtx.
get_data() );
1006 int bytes = mpi_trace_DFE_mtx.
size()*
sizeof(double);
1007 MPI_Allgather(mpi_trace_DFE_mtx.
get_data(), bytes, MPI_BYTE, trace_DFE_mtx.
get_data(), bytes, MPI_BYTE, MPI_COMM_WORLD);
1019 std::stringstream sstream;
1020 sstream << *f0 <<
" " << 1.0 - trace_DFE_mtx[0]/Umtx_loc.
cols <<
" " << trace_DFE_mtx[1]/Umtx_loc.
cols <<
" " << trace_DFE_mtx[2]/Umtx_loc.
cols << std::endl;
1021 instance->
print(sstream, 5);
1025 *f0 = 1-trace_DFE_mtx[0]/Umtx_loc.
cols;
1028 *f0 = 1 - (trace_DFE_mtx[0] + std::sqrt(prev_cost_fnv_val)*trace_DFE_mtx[1]*
correction1_scale)/Umtx_loc.
cols;
1031 *f0 = 1 - (trace_DFE_mtx[0] + std::sqrt(prev_cost_fnv_val)*(trace_DFE_mtx[1]*correction1_scale + trace_DFE_mtx[2]*
correction2_scale))/Umtx_loc.
cols;
1034 std::string err(
"Optimization_Interface::optimization_problem_combined: Cost function variant not implmented.");
1041 for (
int idx=0; idx<parameter_num_loc; idx++) {
1044 grad[idx] = -trace_DFE_mtx[3*(idx+1)]/Umtx_loc.
cols;
1047 grad[idx] = -(trace_DFE_mtx[3*(idx+1)] + std::sqrt(prev_cost_fnv_val)*trace_DFE_mtx[3*(idx+1)+1]*correction1_scale)/Umtx_loc.
cols;
1050 grad[idx] = -(trace_DFE_mtx[3*(idx+1)] + std::sqrt(prev_cost_fnv_val)*(trace_DFE_mtx[3*(idx+1)+1]*correction1_scale + trace_DFE_mtx[3*(idx+1)+2]*
correction2_scale))/Umtx_loc.
cols;
1053 std::string err(
"Optimization_Interface::optimization_problem_combined: Cost function variant not implmented.");
1075 tbb::tick_count t0_CPU = tbb::tick_count::now();
1081 std::vector<Matrix> Umtx_deriv;
1084 int work_batch = 10;
1086 if( parallel == 0 ) {
1088 *f0 = instance->
optimization_problem(parameters, reinterpret_cast<void*>(instance), trace_tmp);
1092 work_batch = parameter_num_loc;
1096 tbb::parallel_invoke(
1098 *f0 = instance->
optimization_problem(parameters, reinterpret_cast<void*>(instance), trace_tmp);
1110 tbb::parallel_for( tbb::blocked_range<int>(0,parameter_num_loc,work_batch), [&](tbb::blocked_range<int> r) {
1111 for (
int idx=r.begin(); idx<r.end(); ++idx) {
1122 grad_comp = (deriv_tmp[0] - std::sqrt(prev_cost_fnv_val)*deriv_tmp[1]*correction1_scale - 1.0);
1126 grad_comp = (deriv_tmp[0] - std::sqrt(prev_cost_fnv_val)*(deriv_tmp[1]*correction1_scale + deriv_tmp[2]*
correction2_scale) - 1.0);
1129 double d = 1.0/Umtx_deriv[idx].cols;
1131 grad_comp = -2.0*d*d*trace_tmp[0].real*deriv_tmp.
real-2.0*d*d*trace_tmp[0].imag*deriv_tmp.
imag;
1135 double d = 1.0/Umtx_deriv[idx].cols;
1136 grad_comp = -2.0*d*d* (trace_tmp[0].real*deriv_tmp[0].real+trace_tmp[0].imag*deriv_tmp[0].imag+std::sqrt(prev_cost_fnv_val)*correction1_scale*(trace_tmp[1].real*deriv_tmp[1].real+trace_tmp[1].imag*deriv_tmp[1].imag));
1140 double d = 1.0/Umtx_deriv[idx].cols;
1141 grad_comp = -2.0*d*d* (trace_tmp[0].real*deriv_tmp[0].real+trace_tmp[0].imag*deriv_tmp[0].imag+std::sqrt(prev_cost_fnv_val)*(correction1_scale*(trace_tmp[1].real*deriv_tmp[1].real+trace_tmp[1].imag*deriv_tmp[1].imag) + correction2_scale*(trace_tmp[2].
real*deriv_tmp[2].
real+trace_tmp[2].imag*deriv_tmp[2].imag)));
1147 double d = Umtx_deriv[idx].cols;
1149 grad_comp = -2.0/d/(d+1)*trace_tmp[0].
real*deriv_tmp.
real-2.0/d/(d+1)*trace_tmp[0].imag*deriv_tmp.
imag;
1152 std::string err(
"Optimization_Interface::optimization_problem_combined: Cost function variant not implmented.");
1156 grad[idx] = grad_comp;
1166 std::stringstream sstream;
1167 sstream << *f0 << std::endl;
1168 instance->
print(sstream, 5);
1224 Umtx = Umtx_loc.
copy();
1225 instance->
apply_to( parameters, Umtx );
1234 tbb::parallel_invoke(
1237 Umtx = Umtx_loc.
copy();
1238 instance->
apply_to( parameters, Umtx );
1290 std::stringstream sstream;
1291 sstream <<
"Optimization_Interface::set_cost_function_variant: Cost function variant set to " <<
cost_fnc << std::endl;
1397 std::string error(
"Optimization_Interface::set_optimizer: unimplemented optimization algorithm");
1495 std::string error(
"Optimization_Interface::set_trace_offset: trace offset must be smaller or equal to the difference of the rows and columns in the input unitary.");
1504 std::stringstream sstream;
1505 sstream <<
"Optimization_Interface::set_trace_offset: trace offset set to " <<
trace_offset << std::endl;
1514 Optimization_Interface::upload_Umtx_to_DFE() {
optimization_aglorithms alg
The optimization algorithm to be used in the optimization.
bool adaptive_eta
logical variable indicating whether adaptive learning reate is used in the ADAM algorithm ...
Header file for a class containing basic methods for the decomposition process.
void export_current_cost_fnc(double current_minimum)
Call to print out into a file the current cost function and the second Rényi entropy on the subsyste...
void print(const std::stringstream &sstream, int verbose_level=1) const
Call to print output messages in the function of the verbosity level.
int get_num_iters()
Get the number of processed iterations during the optimization process.
void set_optimizer(optimization_aglorithms alg_in)
Call to set the optimizer engine to be used in solving the optimization problem.
void solve_layer_optimization_problem_AGENTS(int num_of_parameters, Matrix_real &solution_guess)
Call to solve layer by layer the optimization problem via the AGENT algorithm.
Matrix get_Umtx()
Call to retrive a pointer to the unitary to be transformed.
void set_custom_gate_structure(Gates_block *gate_structure_in)
Call to set custom layers to the gate structure that are intended to be used in the subdecomposition...
Matrix_real get_cost_function_with_correction(Matrix matrix, int qbit_num, int trace_offset=0)
Call co calculate the cost function of the optimization process, and the first correction to the cost...
double current_minimum
The current minimum of the optimization problem.
void add_gate(Gate *gate)
Append a general gate to the list of gates.
static void optimization_problem_combined_unitary(Matrix_real parameters, void *void_instance, Matrix &Umtx, std::vector< Matrix > &Umtx_deriv)
Call to calculate both the effect of the circuit on th eunitary and it's gradient componets...
double correction1_scale
prefactor of the single-bitflip errors in the cost function. (see Eq. (21) in arXiv:2210.09191)
void lock_lib()
Call to lock the access to the execution of the DFE library.
double get_correction2_scale()
Call to get the prefactor of the two-bitflip errors in the cost function.
cost_function_type cost_fnc
The chosen variant of the cost function.
void uploadMatrix2DFE(Matrix &input)
Call to upload the input matrix to the DFE engine.
void add_u1(int target_qbit)
Append a U1 gate to the list of gates.
std::vector< Gate * > get_gates()
Call to get the gates stored in the class.
void release_gates()
Call to release the stored gates.
int get_accelerator_num()
Get the number of accelerators to be reserved on DFEs on users demand.
double optimization_problem(double *parameters)
Evaluate the optimization problem of the optimization.
void solve_layer_optimization_problem_GRAD_DESCEND(int num_of_parameters, Matrix_real &solution_guess)
Call to solve layer by layer the optimization problem via the GRAD_DESCEND (line search in the direct...
void set_trace_offset(int trace_offset_in)
Set the trace offset used in the evaluation of the cost function.
double prev_cost_fnv_val
the previous value of the cost funtion to be used to evaluate bitflip errors in the cost funtion (see...
int trace_offset
The offset in the first columns from which the "trace" is calculated. In this case Tr(A) = sum_(i-off...
tbb::spin_mutex my_mutex_optimization_interface
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...
void set_random_shift_count_max(int random_shift_count_max_in)
Call to set the maximal number of parameter randomization tries to escape a local minimum...
Matrix_real get_cost_function_with_correction2(Matrix matrix, int qbit_num, int trace_offset=0)
Call co calculate the cost function of the optimization process, and the first correction to the cost...
virtual void apply_to(Matrix_real ¶meters_mtx, Matrix &input, int parallel=0)
Call to apply the gate on the input array/matrix Gates_block*input.
scalar * get_data() const
Call to get the pointer to the stored data.
virtual double optimization_problem_non_static(Matrix_real parameters, void *void_instance)
The optimization problem of the final optimization.
double correction2_scale
prefactor of the double-bitflip errors in the cost function. (see Eq. (21) in arXiv:2210.09191)
cost_function_type get_cost_function_variant()
Call to get the variant of the cost function used in the calculations.
int get_trace_offset()
Get the trace ffset used in the evaluation of the cost function.
void set_qbit_num(int qbit_num_in)
Set the number of qubits spanning the matrix of the gates stored in the block of gates.
int max_outer_iterations
Maximal number of iterations allowed in the optimization process.
void unlock_lib()
Call to unlock the access to the execution of the DFE library.
optimization_aglorithms
implemented optimization strategies
int LAPACKE_dgesv(int matrix_layout, int n, int nrhs, double *a, int lda, int *ipiv, double *b, int ldb)
std::string project_name
the name of the project
int init_dfe_lib(const int accelerator_num, int qbit_num, int initialize_id_in)
Call to initialize the DFE library support and allocate the requested devices.
void set_max_inner_iterations(int max_inner_iterations_in)
Call to set the maximal number of iterations for which an optimization engine tries to solve the opti...
void solve_layer_optimization_problem_BAYES_AGENTS(int num_of_parameters, Matrix_real &solution_guess)
Call to solve layer by layer the optimization problem via Bayes & Agents algorithm.
gate_type type
The type of the operation (see enumeration gate_type)
QGD_Complex16 get_trace(Matrix &matrix)
Call to calculate the real and imaginary parts of the trace.
int get_parameter_num()
Call to get the number of free parameters.
double get_infidelity(Matrix &matrix)
Call to calculate infidelity.
double get_second_Renyi_entropy(Matrix_real ¶meters_mtx, Matrix &input_state, matrix_base< int > &qbit_list)
Call to evaluate the seconf Rényi entropy.
int accelerator_num
number of utilized accelerators
int rows
The number of rows.
int cols
The number of columns.
int number_of_iters
number of iterations
virtual void add_finalyzing_layer()
Call to add further layer to the gate structure used in the subdecomposition.
A base class to determine the decomposition of an N-qubit unitary into a sequence of CNOT and U3 gate...
void combine(Gates_block *op_block)
Call to append the gates of an gate block to the current block.
double randomization_rate
randomization rate
std::map< int, int > iteration_loops
A map of <int n: int num> indicating the number of iteration in each step of the decomposition.
void solve_layer_optimization_problem_BFGS2(int num_of_parameters, Matrix_real solution_guess)
Call to solve layer by layer the optimization problem via BBFG algorithm.
double get_cost_function(Matrix matrix, int trace_offset=0)
Call co calculate the cost function during the final optimization process.
Structure type representing complex numbers in the SQUANDER package.
double CPU_time
time spent on optimization
A class containing basic methods for the decomposition process.
double circuit_simulation_time
Time spent on circuit simulation/cost function evaluation.
virtual std::vector< Matrix > apply_derivate_to(Matrix_real ¶meters_mtx, Matrix &input, int parallel)
Call to evaluate the derivate of the circuit on an inout with respect to all of the free parameters...
decomposed_matrix
the unitary matrix from the result object
int Power_of_2(int n)
Calculates the n-th power of 2.
void solve_layer_optimization_problem_BFGS(int num_of_parameters, Matrix_real &solution_guess)
Call to solve layer by layer the optimization problem via BBFG algorithm.
Class to store data of complex arrays and its properties.
Matrix get_trace_with_correction(Matrix &matrix, int qbit_num)
Call co calculate the Hilbert Schmidt testof the optimization process, and the first correction to th...
double get_previous_cost_function_value()
Call to retrieve the previous value of the cost funtion to be used to evaluate bitflip errors in the ...
void calc_decomposition_error(Matrix &decomposed_matrix)
Calculate the error of the decomposition according to the spectral norm of , where is the unitary pr...
int size() const
Call to get the number of the allocated elements.
Gates_block()
Default constructor of the class.
cost_function_type
Type definition of the fifferent types of the cost function.
A class responsible for grouping two-qubit (CNOT,CZ,CH) and one-qubit gates into layers.
int get_initialize_id()
Call to get the identification number of the inititalization of the library.
guess_type
Type definition of the types of the initial guess.
Fixed point data related to a gate operation.
static void optimization_problem_combined(Matrix_real parameters, void *void_instance, double *f0, Matrix_real &grad)
Call to calculate both the cost function and the its gradient components.
std::map< std::string, Config_Element > config
config metadata utilized during the optimization
void solve_layer_optimization_problem_ADAM(int num_of_parameters, Matrix_real &solution_guess)
Call to solve layer by layer the optimization problem via ADAM algorithm.
void unload_dfe_lib()
Call to unload the DFE libarary and release the allocated devices.
double get_cost_function_sum_of_squares(Matrix &matrix)
static void optimization_problem_grad(Matrix_real parameters, void *void_instance, Matrix_real &grad)
Calculate the derivative of the cost function with respect to the free parameters.
int parameter_num
the number of free parameters of the operation
void solve_layer_optimization_problem(int num_of_parameters, Matrix_real solution_guess)
Call to solve layer by layer the optimization problem via calling one of the implemented algorithms...
Header file for the paralleized calculation of the cost function of the final optimization problem (s...
void solve_layer_optimization_problem_GRAD_DESCEND_PARAMETER_SHIFT_RULE(int num_of_parameters, Matrix_real &solution_guess)
Call to solve layer by layer the optimization problem via the GRAD_DESCEND_PARAMETER_SHIFT_RULE algor...
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.
virtual ~Optimization_Interface()
Destructor of the class.
double get_correction1_scale()
Call to get the prefactor of the single-bitflip errors in the cost function.
Header file for a class ???
int calcqgdKernelDFE(size_t rows, size_t cols, DFEgate_kernel_type *gates, int gatesNum, int gateSetNum, int traceOffset, double *trace)
Call to execute the calculation on the reserved DFE engines.
void solve_layer_optimization_problem_COSINE(int num_of_parameters, Matrix_real &solution_guess)
Call to solve layer by layer the optimization problem via the COSINE algorithm.
Matrix copy()
Call to create a copy of the matrix.
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...
double real
the real part of a complex number
void final_optimization()
final optimization procedure improving the accuracy of the decompositin when all the qubits were alre...
int qbit_num
number of qubits spanning the matrix of the operation
bool optimize_layer_num
logical value. Set true to optimize the minimum number of gate layers required in the decomposition...
int get_qbit_num()
Call to get the number of qubits composing the unitary.
void randomize_parameters(Matrix_real &input, Matrix_real &output, const double &f0)
Call to randomize the parameter.
bool check_optimization_solution()
check_optimization_solution
double decomposition_error
error of the final decomposition
int max_inner_iterations
the maximal number of iterations for which an optimization engine tries to solve the optimization pro...
void solve_layer_optimization_problem_AGENTS_COMBINED(int num_of_parameters, Matrix_real &solution_guess)
Call to solve layer by layer the optimization problem via the AGENT COMBINED algorithm.
int random_shift_count_max
the maximal number of parameter randomization tries to escape a local minimum.
Optimization_Interface()
Nullary constructor of the class.
void solve_layer_optimization_problem_ADAM_BATCHED(int num_of_parameters, Matrix_real &solution_guess_)
Call to solve layer by layer the optimization problem via batched ADAM algorithm. ...
Matrix_real optimized_parameters_mtx
The optimized parameters for the gates.
int get_parallel_configuration()
Get the parallel configuration from the config.
void set_cost_function_variant(cost_function_type variant)
Call to set the variant of the cost function used in the calculations.
Matrix get_trace_with_correction2(Matrix &matrix, int qbit_num)
Call co calculate the Hilbert Schmidt testof the optimization process, and the first correction to th...
double radius
parameter to contron the radius of parameter randomization around the curren tminimum ...
Matrix_real optimization_problem_batched(std::vector< Matrix_real > ¶meters_vec)
The cost function of the optimization with batched input (implemented only for the Frobenius norm cos...
double global_target_minimum
The global target minimum of the optimization problem.
Class to store data of complex arrays and its properties.
double get_hilbert_schmidt_test(Matrix &matrix)
Call co calculate the cost function of the optimization process according to https://arxiv.org/pdf/2210.09191.pdf.
virtual void optimization_problem_combined_non_static(Matrix_real parameters, void *void_instance, double *f0, Matrix_real &grad)
Call to calculate both the cost function and the its gradient components.
void solve_layer_optimization_problem_BAYES_OPT(int num_of_parameters, Matrix_real &solution_guess)
Call to solve layer by layer the optimization problem via Bayes algorithm.
std::mt19937 gen
Standard mersenne_twister_engine seeded with rd()
double imag
the imaginary part of a complex number