52 if (
gates.size() == 0 ) {
57 if (solution_guess.
size() == 0 ) {
68 int iteration_loops_max;
73 iteration_loops_max = 1;
77 int random_shift_count = 0;
78 long long sub_iter_idx = 0;
85 tbb::tick_count bfgs_start = tbb::tick_count::now();
90 std::uniform_real_distribution<> distrib_real(0.0, 2*M_PI);
93 std::uniform_int_distribution<> distrib_int(0, 5000);
96 long long max_inner_iterations_loc;
97 if (
config.count(
"max_inner_iterations_bfgs2") > 0 ) {
98 config[
"max_inner_iterations_bfgs2"].get_property( max_inner_iterations_loc );
100 else if (
config.count(
"max_inner_iterations") > 0 ) {
101 config[
"max_inner_iterations"].get_property( max_inner_iterations_loc );
108 long long export_circuit_2_binary_loc;
109 if (
config.count(
"export_circuit_2_binary_bfgs2") > 0 ) {
110 config[
"export_circuit_2_binary_bfgs2"].get_property( export_circuit_2_binary_loc );
112 else if (
config.count(
"export_circuit_2_binary") > 0 ) {
113 config[
"export_circuit_2_binary"].get_property( export_circuit_2_binary_loc );
116 export_circuit_2_binary_loc = 0;
121 double optimization_tolerance_loc;
122 if (
config.count(
"optimization_tolerance_adam") > 0 ) {
123 config[
"optimization_tolerance_adam"].get_property( optimization_tolerance_loc );
125 else if (
config.count(
"optimization_tolerance") > 0 ) {
126 config[
"optimization_tolerance"].get_property( optimization_tolerance_loc );
134 int output_periodicity;
135 if (
config.count(
"output_periodicity_cosine") > 0 ) {
137 config[
"output_periodicity_cosine"].get_property( value );
138 output_periodicity = (
int) value;
140 if (
config.count(
"output_periodicity") > 0 ) {
142 config[
"output_periodicity"].get_property( value );
143 output_periodicity = (
int) value;
146 output_periodicity = 0;
151 std::stringstream sstream;
152 sstream <<
"max_inner_iterations: " << max_inner_iterations_loc << std::endl;
157 for (
long long iter_idx=0; iter_idx<iteration_loops_max; iter_idx++) {
163 if (sub_iter_idx == 1 ) {
164 current_minimum_hold = f;
168 if (current_minimum_hold*0.95 > f || (current_minimum_hold*0.97 > f && f < 1e-3) || (current_minimum_hold*0.99 > f && f < 1e-4) ) {
170 current_minimum_hold = f;
180 if ( iter_idx % 5000 == 0 ) {
181 std::stringstream sstream;
182 sstream <<
"BFGS2: processed iterations " << (double)iter_idx/max_inner_iterations_loc*100 <<
"\%, current minimum:" <<
current_minimum << std::endl;
185 if ( export_circuit_2_binary_loc>0) {
186 std::string
filename(
"initial_circuit_iteration.binary");
220 if ( output_periodicity>0 && iter_idx % output_periodicity == 0 ) {
237 tbb::tick_count bfgs_end = tbb::tick_count::now();
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.
double current_minimum
The current minimum of the optimization problem.
int get_accelerator_num()
Get the number of accelerators to be reserved on DFEs on users demand.
scalar * get_data() const
Call to get the pointer to the stored data.
std::vector< Gate * > gates
The list of stored gates.
A class implementing the BFGS optimizer based on conjugate gradient direction method of M...
std::string project_name
the name of the project
double optimization_tolerance
The maximal allowed error of the optimization problem (The error of the decomposition would scale wit...
double Start_Optimization(Matrix_real &x, long maximal_iterations_in=5001)
Call this method to start the optimization.
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 CPU_time
time spent on optimization
int verbose
Set the verbosity level of the output messages.
int size() const
Call to get the number of the allocated elements.
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
Header file for the paralleized calculation of the cost function of the final optimization problem (s...
void export_gate_list_to_binary(Matrix_real ¶meters, Gates_block *gates_block, const std::string &filename, int verbosity)
?????????
int qbit_num
number of qubits spanning the matrix of the operation
Header file for DFE support in unitary simulation.
int max_inner_iterations
the maximal number of iterations for which an optimization engine tries to solve the optimization pro...
int random_shift_count_max
the maximal number of parameter randomization tries to escape a local minimum.
Matrix_real optimized_parameters_mtx
The optimized parameters for the gates.
Class to store data of complex arrays and its properties.
std::mt19937 gen
Standard mersenne_twister_engine seeded with rd()