Sequential Quantum Gate Decomposer  v1.9.6
Powerful decomposition of general unitarias into one- and two-qubit gates gates
Generative_Quantum_Machine_Learning_Base.h
Go to the documentation of this file.
1 /*
2 Created on Fri Jun 26 14:13:26 2020
3 Copyright 2020 Peter Rakyta, Ph.D.
4 
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8 
9  http://www.apache.org/licenses/LICENSE-2.0
10 
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16 
17 @author: Peter Rakyta, Ph.D.
18 */
24 #ifndef GENERATIVE_QUANTUM_MACHINE_LEARNING_BASE_H
25 #define GENERATIVE_QUANTUM_MACHINE_LEARNING_BASE_H
26 
27 #include "Optimization_Interface.h"
28 #include "matrix_real.h"
29 
32 
33 
34 
40 public:
41 
42 
43 private:
44 
46  std::vector<int> sample_indices;
47 
49  std::vector<std::vector<int>> sample_bitstrings;
50 
53 
56 
59 
62 
65 
66  // Lookup table for the gauss kernels
67  std::vector<std::vector<double>> gaussian_lookup_table;
68 
69  // Decide to use lookup table
70  bool use_lookup;
71 
72  std::vector<std::vector<int>> all_bitstrings;
73 
74  // Number samples
76 
77  // The cliques in the graph
78  std::vector<std::vector<int>> cliques;
79 
81 
82  bool use_exact;
83 
84 public:
85 
86 
92 
93 
107 Generative_Quantum_Machine_Learning_Base( std::vector<int> sample_indices_in, std::vector<std::vector<int>> sample_bitstrings_in, Matrix_real P_star_in, Matrix_real sigma_in, int qbit_num_in, bool use_lookup_table_in, std::vector<std::vector<int>> cliques_in, bool use_exact, std::map<std::string, Config_Element>& config_in);
108 
113 
114 
122 double Gaussian_kernel(int x, int y, Matrix_real& sigma);
123 
129 
135 
139 void fill_lookup_table();
140 
146 double TV_of_the_distributions(Matrix& State_right);
147 
153 double MMD_of_the_distributions_approx(Matrix& State_right);
154 
160 double MMD_of_the_distributions_exact(Matrix& State_right);
161 
162 
168 virtual double optimization_problem(Matrix_real& parameters) override;
169 
170 
177 virtual double optimization_problem_non_static( Matrix_real parameters, void* void_instance) override;
178 
179 
181 
187 double optimization_problem( double* parameters);
188 
189 
197 virtual void optimization_problem_combined_non_static( Matrix_real parameters, void* void_instance, double* f0, Matrix_real& grad ) override;
198 
199 
206 virtual void optimization_problem_combined( Matrix_real parameters, double* f0, Matrix_real grad ) override;
207 
208 
215 static void optimization_problem_grad_vqe( Matrix_real parameters, void* void_instance, Matrix_real& grad );
216 
223 
227 void initialize_zero_state();
228 
229 
233 void start_optimization();
234 
235 
240 void set_ansatz(ansatz_type ansatz_in);
241 
242 
248 void generate_circuit( int layers, int inner_blocks );
249 
250 
257 void generate_clique_circuit(int i, std::vector<int>& qbits, std::vector<std::vector<int>>& res, std::vector<int>& subset);
258 
259 
264 void MultyRZ(std::vector<int>& qbits);
265 
270 void set_gate_structure( std::string filename );
271 
272 
277 void set_initial_state( Matrix initial_state_in );
278 
279 
280 
281 };
282 
283 #endif
virtual double optimization_problem(Matrix_real &parameters) override
The optimization problem of the final optimization.
virtual ~Generative_Quantum_Machine_Learning_Base()
Destructor of the class.
ansatz_type
Type definition of the fifferent types of ansatz.
static void optimization_problem_grad_vqe(Matrix_real parameters, void *void_instance, Matrix_real &grad)
Calculate the derivative of the cost function with respect to the free parameters.
void set_gate_structure(std::string filename)
Call to set custom layers to the gate structure that are intended to be used in the GQML process...
double expectation_value_P_star_P_star_exact()
Call to evaluate the expectation value of the square of the distribution.
void generate_circuit(int layers, int inner_blocks)
Call to generate the circuit ansatz.
double Gaussian_kernel(int x, int y, Matrix_real &sigma)
Call to evaluate the value of one gaussian kernel function.
double MMD_of_the_distributions_approx(Matrix &State_right)
Call to evaluate the approximated maximum mean discrepancy of the given distribution and the one crea...
void set_ansatz(ansatz_type ansatz_in)
Call to set the ansatz type.
Generative_Quantum_Machine_Learning_Base()
Nullary constructor of the class.
virtual void optimization_problem_combined_non_static(Matrix_real parameters, void *void_instance, double *f0, Matrix_real &grad) override
Call to calculate both the cost function and the its gradient components.
double MMD_of_the_distributions_exact(Matrix &State_right)
Call to evaluate the maximum mean discrepancy of the given distribution and the one created by our ci...
double ev_P_star_P_star
The expectation value of the the square of the given ditribution (only needed to calculate once) ...
double expectation_value_P_star_P_star_approx()
Call to evaluate the approximated expectation value of the square of the distribution.
std::vector< std::vector< int > > sample_bitstrings
Same as the x_vectors but in binary.
double TV_of_the_distributions(Matrix &State_right)
Call to evaluate the total variational distance of the given distribution and the one created by our ...
void export_current_cost_fnc(double current_minimum, Matrix_real &parameters) override
Call to print out into a file the current cost function and the second Rényi entropy on the subsyste...
Matrix initial_state
Quantum state used as an initial state in the VQE iterations.
A base class to determine the decomposition of an N-qubit unitary into a sequence of CNOT and U3 gate...
A base class to solve GQML problems This class can be used to approximate a given distribution via a ...
virtual void optimization_problem_combined(Matrix_real parameters, double *f0, Matrix_real grad) override
Call to calculate both the cost function and the its gradient components.
void start_optimization()
Call to start solving the GQML problem.
Double-precision complex matrix (float64).
Definition: matrix.h:38
Matrix_real sigma
Parameter of the Gaussian kernel.
void fill_lookup_table()
Call to calculate and save the values of the gaussian kernel needed for traing.
ansatz_type ansatz
Ansatz type (HEA stands for hardware efficient ansatz)
virtual double optimization_problem_non_static(Matrix_real parameters, void *void_instance) override
The optimization problem of the final optimization.
void set_initial_state(Matrix initial_state_in)
Call to set the initial quantum state in the VQE iterations.
double(Generative_Quantum_Machine_Learning_Base::* MMD_of_the_distributions)(Matrix &)
void generate_clique_circuit(int i, std::vector< int > &qbits, std::vector< std::vector< int >> &res, std::vector< int > &subset)
Call to generate the circuit ansatz for the given clique.
Matrix_real P_star
The distribution we are trying to approximate.
void initialize_zero_state()
Initialize the state used in the quantun circuit.
volatile double current_minimum
The current minimum of the optimization problem.
void MultyRZ(std::vector< int > &qbits)
Call to generate a MultiRZ gate.
std::vector< int > sample_indices
The state vector&#39;s corresponding indices of the training data.
Class to store data of complex arrays and its properties.
Definition: matrix_real.h:41
virtual double optimization_problem(const double *parameters)
This is an abstact definition of function giving the cost functions measuring the entaglement of the ...