162 if (
gates == NULL ) {
186 total_counts_probs[ row_idx ] = parameter_num*20;
194 memset( total_counts.
get_data(), 0, total_counts.
size()*
sizeof(
int ) );
211 std::uniform_real_distribution<> distrib_to_choose(0.0, 1.0);
212 double random_num = distrib_to_choose( gen );
214 int selected_idx = 0;
224 random_num = distrib_to_choose( gen );
226 double prob_tmp = 0.0;
229 if ( prob_tmp >= random_num ) {
234 prob_tmp += current_probs[idx];
242 std::uniform_int_distribution<> distrib_int(0,
parameter_num-1);
243 selected_idx = distrib_int( gen );
271 double prob_sum = 0.0;
280 counts_loc_old += counts_loc_new;
293 prob_sum += prob_new;
327 std::string
filename =
"probabilities.bin";
329 const char* c_filename = filename.c_str();
330 pFile = fopen(c_filename,
"wb");
332 fputs (
"File error",stderr);
333 std::string error(
"Cannot open file.");
338 fwrite(&
iteration_num,
sizeof(
unsigned long long), 1, pFile);
343 fwrite( &element_num,
sizeof(
int), 1, pFile);
347 fwrite( &element_num,
sizeof(
int), 1, pFile);
366 std::string
filename =
"probabilities.bin";
368 const char* c_filename = filename.c_str();
369 pFile = fopen(c_filename,
"rb");
371 fputs (
"File error",stderr);
372 std::string error(
"Cannot open file.");
381 fread( &element_num,
sizeof(
int), 1, pFile);
385 fread( &element_num,
sizeof(
int), 1, pFile);
matrix_base< int > total_counts
total counts in one row of parameter_counts — reset when probabilites are updated ...
A class for RL_experience optimization according to https://towardsdatascience.com/how-to-implement-a...
Matrix_real copy() const
Call to create a copy of the matrix.
void import_probabilities()
???????????
int stride
The column stride of the array. (The array elements in one row are a_0, a_1, ... a_{cols-1}, 0, 0, 0, 0. The number of zeros is stride-cols)
Matrix_real parameter_probs
int parameter_num
number of involved parameters
matrix_base< scalar > copy() const
Call to create a copy of the matrix.
std::vector< int > history
scalar * get_data() const
Call to get the pointer to the stored data.
void reset()
?????????????
RL_experience copy()
Call to make a copy of the current instance.
int get_parameter_num()
Call to get the number of free parameters.
RL_experience()
Nullary constructor of the class.
RL_experience & operator=(const RL_experience &experience)
Assignment operator.
matrix_base< unsigned long long > total_counts_probs
total counts used to evasluate one row in parameter_probs
Gates_block * gates
attribute stroing the gate structure
int draw(const int &curent_index, std::mt19937 &gen)
Call to draw the next index.
int size() const
Call to get the number of the allocated elements.
A class responsible for grouping two-qubit (CNOT,CZ,CH) and one-qubit gates into layers.
unsigned long long iteration_num
virtual ~RL_experience()
Destructor of the class.
Header file for a class ???
void update_probs()
Call to update the trained probabilities and reset the counts.
Class to store data of complex arrays and its properties.
void export_probabilities()
???????????
matrix_base< int > parameter_counts
array containing the counts of successive parameters used in the optimization. Element (i...