Sequential Quantum Gate Decomposer  v1.9.3
Powerful decomposition of general unitarias into one- and two-qubit gates gates
Decomposition_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 */
23 #ifndef DECOMPOSITION_BASE_H
24 #define DECOMPOSITION_BASE_H
25 
26 
27 #include "Gates_block.h"
28 #include "CZ.h"
29 #include "CH.h"
30 #include "CNOT.h"
31 #include "CROT.h"
32 #include "R.h"
33 #include "U3.h"
34 #include "RX.h"
35 #include "H.h"
36 #include "X.h"
37 #include "Y.h"
38 #include "Z.h"
39 #include "SX.h"
40 #include "RY.h"
41 #include "CRY.h"
42 #include "RZ.h"
43 #include "RZ_P.h"
44 #include "SYC.h"
45 #include "UN.h"
46 #include "ON.h"
47 #include "Adaptive.h"
48 #include "CZ_NU.h"
49 #include "Composite.h"
50 #include <map>
51 #include <cstdlib>
52 #include <time.h>
53 #include <ctime>
54 #include <cfloat>
55 #include <limits>
56 #include <tbb/cache_aligned_allocator.h>
57 
58 #include "config_element.h"
59 
60 #include <random>
61 
64 
65 #ifndef OPENBLAS_CONST
66 # define OPENBLAS_CONST const
67 #endif
68 #if defined(OS_WINDOWS) && defined(__64BIT__)
69 typedef long long BLASLONG;
70 typedef unsigned long long BLASULONG;
71 #else
72 typedef long BLASLONG;
73 typedef unsigned long BLASULONG;
74 #endif
75 typedef BLASLONG blasint;
76 #if defined(OS_WINDOWS) && defined(__64BIT__)
77 #define blasabs(x) llabs(x)
78 #else
79 #define blasabs(x) labs(x)
80 #endif
81 
83 
88 
89 
90 public:
91 
94 
96  static std::map<int,int> max_layer_num_def;
97 
100 
103 
105  std::string project_name;
106 
108  std::map<std::string, Config_Element> config;
109 
110 
111 protected:
112 
114  std::map<int,int> max_layer_num;
115 
117  std::map<int,int> iteration_loops;
118 
121 
124 
126  //double* optimized_parameters;
127 
130 
133 
136 
139 
142 
145 
148 
151 
154 
157 
160 
161 
163  std::mt19937 gen;
164 
165 
166 
167 public:
168 
173 
181 Decomposition_Base( Matrix Umtx_in, int qbit_num_in, std::map<std::string, Config_Element>& config_in, guess_type initial_guess_in);
182 
186 virtual ~Decomposition_Base();
187 
188 
193 void set_optimization_blocks( int optimization_block_in );
194 
199 void set_max_iteration( int max_outer_iterations_in);
200 
201 
206 void list_gates( int start_index );
207 
208 
214 void solve_optimization_problem( double* solution_guess, int solution_guess_num );
215 
216 
222 virtual void solve_layer_optimization_problem( int num_of_parameters, Matrix_real solution_guess_gsl);
223 
224 
225 
230 virtual double optimization_problem( const double* parameters );
231 
237 
238 
243 Matrix get_Umtx();
244 
249 int get_Umtx_size();
250 
256 
261 void get_optimized_parameters( double* ret );
262 
263 
269 
270 
276 
277 
284 Matrix apply_gate( Matrix& gate_mtx, Matrix& input_matrix );
285 
290 void reorder_qubits( std::vector<int> qbit_list);
291 
298 int set_max_layer_num( int n, int max_layer_num_in );
299 
305 int set_max_layer_num( std::map<int, int> max_layer_num_in );
306 
307 
314 int set_iteration_loops( int n, int iteration_loops_in );
315 
321 int set_iteration_loops( std::map<int, int> iteration_loops_in );
322 
323 
327 static void Init_max_layer_num();
328 
329 
334 void set_optimization_tolerance( double tolerance_in );
335 
336 
341 void set_convergence_threshold( double convergence_threshold_in );
342 
343 
348 double get_decomposition_error( );
349 
350 
355 double get_current_minimum( );
356 
361 std::string get_project_name();
366 void set_project_name(std::string& project_name_new);
367 
372 void calculate_new_global_phase_factor( QGD_Complex16 global_phase_factor_new );
373 
379 
384 void set_global_phase(double new_global_phase);
385 
386 
391 void apply_global_phase_factor(QGD_Complex16 global_phase_factor, Matrix& u3_gate);
392 
398 
403 void export_unitary(std::string& filename);
409 
410 
416 
417 
422 void set_qbit_num( int qbit_num_in );
423 
424 
425 
426 };
427 #endif //DECOMPOSITION_BASE
void list_gates(int start_index)
Call to print the gates decomposing the initial unitary.
std::string get_project_name()
Call to get the current name of the project.
A class representing a U3 gate.
Definition: X.h:36
Header file for a class representing a rotation gate around the X axis.
BLASLONG blasint
Header file for a class for a composite gate operation.
Matrix get_decomposed_matrix()
Calculate the decomposed matrix resulted by the effect of the optimized gates on the unitary Umtx...
void set_project_name(std::string &project_name_new)
Call to set the name of the project.
bool decomposition_finalized
The optimized parameters for the gates.
Header file for a class representing the X gate.
Matrix get_Umtx()
Call to retrive a pointer to the unitary to be transformed.
Header file for a class representing the Y gate.
double current_minimum
The current minimum of the optimization problem.
bool optimization_problem_solved
logical value describing whether the optimization problem was solved or not
Header file for a class representing a controlled rotation gate around the Y axis.
int finalizing_gates_num
number of finalizing (deterministic) opertaions rotating the disentangled qubits into state |0>...
Header file for a class representing the SX axis.
Header file for a class representing a controlled rotation gate around the Y axis.
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.
double get_current_minimum()
Call to get the obtained minimum of the cost function.
Header file for a class representing a CH operation.
Header file for a class responsible for grouping gates into subcircuits. (Subcircuits can be nested) ...
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...
Header file for a class representing a rotation gate around the Z axis.
Matrix apply_gate(Matrix &gate_mtx, Matrix &input_matrix)
Apply an gates on the input matrix.
guess_type initial_guess
type to guess the initial values for the optimization. Possible values: ZEROS=0, RANDOM=1, CLOSE_TO_ZERO=2
#define OPENBLAS_CONST
static void Init_max_layer_num()
Initializes default layer numbers.
void apply_global_phase_factor()
Call to apply the current global phase to the unitary matrix.
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.
Header file for a class representing a CNOT operation.
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...
void set_global_phase(double new_global_phase)
Call to set global phase.
QGD_Complex16 get_global_phase_factor()
Get the global phase of the Unitary matrix.
Header file for a class representing a rotation gate around the Z axis.
double get_decomposition_error()
Call to get the error of the decomposition.
int get_Umtx_size()
Call to get the size of the unitary to be transformed.
double convergence_threshold
The convergence threshold in the optimization process.
Header file for a class describing a universal parameter with name and value stored in a config map...
Header file for a class representing the Hadamard gate.
Matrix_real get_optimized_parameters()
Call to get the optimized parameters.
double cblas_dznrm2(OPENBLAS_CONST blasint N, OPENBLAS_CONST void *X, OPENBLAS_CONST blasint incX)
Header file for a class for the representation of general gate operations on the first qbit_num-1 qub...
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 set_optimized_parameters(double *parameters, int num_of_parameters)
Call to set the optimized parameters for initial optimization.
Header file for a class representing a CZ operation.
int num_threads
Store the number of OpenMP threads. (During the calculations OpenMP multithreading is turned off...
Structure type representing complex numbers in the SQUANDER package.
Definition: QGDTypes.h:38
A class containing basic methods for the decomposition process.
void set_optimization_tolerance(double tolerance_in)
Call to set the tolerance of the optimization processes.
Class to store data of complex arrays and its properties.
Definition: matrix.h:38
virtual ~Decomposition_Base()
Destructor of the class.
Header file for a class representing a gate used in adaptive decomposition.
QGD_Complex16 global_phase_factor
The global phase.
void set_convergence_threshold(double convergence_threshold_in)
Call to set the threshold of convergence in the optimization processes.
A class responsible for grouping two-qubit (CNOT,CZ,CH) and one-qubit gates into layers.
Definition: Gates_block.h:41
void calculate_new_global_phase_factor(QGD_Complex16 global_phase_factor_new)
Calculate the new global phase of the Unitary matrix after removing a trivial U3 matrix.
Header file for a class representing a U3 gate.
void reorder_qubits(std::vector< int > qbit_list)
Call to reorder the qubits in the matrix of the gate.
guess_type
Type definition of the types of the initial guess.
Header file for a class representing a rotation gate around the X axis.
std::map< std::string, Config_Element > config
config metadata utilized during the optimization
Header file for a class representing a rotation gate around the Y axis.
virtual void solve_layer_optimization_problem(int num_of_parameters, Matrix_real solution_guess_gsl)
Abstarct function to be used to solve a single sub-layer optimization problem.
unsigned long BLASULONG
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...
void export_unitary(std::string &filename)
exports unitary matrix to binary file
Header file for a class representing the Z gate.
Header file for a class for the representation of general gate operations on the first qbit_num-1 qub...
int finalizing_parameter_num
the number of the finalizing (deterministic) parameters of gates rotating the disentangled qubits int...
void set_max_iteration(int max_outer_iterations_in)
Call to set the maximal number of the iterations in the optimization process.
bool check_optimization_solution()
check_optimization_solution
int optimization_block
number of gate blocks used in one shot of the optimization process
double decomposition_error
error of the final decomposition
int set_iteration_loops(int n, int iteration_loops_in)
Set the number of iteration loops during the subdecomposition of the n-th qubit.
Matrix import_unitary_from_binary(std::string &filename)
Import a Unitary matrix from a file.
Matrix_real optimized_parameters_mtx
The optimized parameters for the gates.
int get_parallel_configuration()
Get the parallel configuration from the config.
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 gate blocks to be optimized in one shot.
Class to store data of complex arrays and its properties.
Definition: matrix_real.h:39
Decomposition_Base()
Nullary constructor of the class.
long BLASLONG
std::mt19937 gen
Standard mersenne_twister_engine seeded with rd()
Header file for a class representing a Sycamore gate.
virtual double optimization_problem(const double *parameters)
This is an abstact definition of function giving the cost functions measuring the entaglement of the ...