Sequential Quantum Gate Decomposer  v1.9.3
Powerful decomposition of general unitarias into one- and two-qubit gates gates
N_Qubit_Decomposition_adaptive.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 You should have received a copy of the GNU General Public License
18 along with this program. If not, see http://www.gnu.org/licenses/.
19 
20 @author: Peter Rakyta, Ph.D.
21 */
26 #ifndef N_Qubit_Decomposition_adaptive_H
27 #define N_Qubit_Decomposition_adaptive_H
28 
29 #include "Optimization_Interface.h"
30 
31 #ifdef __cplusplus
32 extern "C"
33 {
34 #endif
35 
37 int LAPACKE_zggev ( int matrix_layout,
38  char jobvl,
39  char jobvr,
40  int n,
41  QGD_Complex16 * a,
42  int lda,
43  QGD_Complex16 * b,
44  int ldb,
46  QGD_Complex16 * beta,
47  QGD_Complex16 * vl,
48  int ldvl,
49  QGD_Complex16 * vr,
50  int ldvr
51  );
52 
53 #ifdef __cplusplus
54 }
55 #endif
56 
57 
63 
64 
65 public:
66 
67 protected:
68 
69 
75  std::vector<matrix_base<int>> topology;
78 
79 
80 
81 public:
82 
88 
89 
99 N_Qubit_Decomposition_adaptive( Matrix Umtx_in, int qbit_num_in, int level_limit_in, int level_limit_min_in, std::map<std::string, Config_Element>& config, int accelerator_num=0 );
100 
101 
111 N_Qubit_Decomposition_adaptive( Matrix Umtx_in, int qbit_num_in, int level_limit_in, int level_limit_min_in, std::vector<matrix_base<int>> topology_in, std::map<std::string, Config_Element>& config, int accelerator_num=0 );
112 
113 
114 
119 
120 
125 virtual void start_decomposition();
126 
130 virtual void get_initial_circuit();
131 
135 virtual void compress_circuit();
136 
140 virtual void finalize_circuit();
141 
146 Gates_block* optimize_imported_gate_structure(Matrix_real& optimized_parameters_mtx_loc);
147 
148 
154 
155 
156 
161 Gates_block* compress_gate_structure( Gates_block* gate_structure, int uncompressed_iter_num );
162 
171 Gates_block* compress_gate_structure( Gates_block* gate_structure, int layer_idx, Matrix_real& optimized_parameters, double& currnt_minimum_loc, int& iteration_num );
172 
179 
185 virtual unsigned int get_panelty( Gates_block* gate_structure, Matrix_real& optimized_parameters );
186 
187 
194 virtual Gates_block* remove_trivial_gates( Gates_block* gate_structure, Matrix_real& optimized_parameters, double& currnt_minimum_loc );
195 
202 Matrix_real create_reduced_parameters( Gates_block* gate_structure, Matrix_real& optimized_parameters, int layer_idx );
203 
204 
208 void add_adaptive_layers();
209 
214 
219 
220 
224 void add_finalyzing_layer();
225 
226 
231 
232 
233 
238 void set_adaptive_gate_structure( std::string filename );
239 
240 
245  void set_unitary_from_file( std::string filename );
246 
247 
252  void set_unitary( Matrix& Umtx_new ) ;
253 
258 void add_adaptive_gate_structure( std::string filename );
259 
264 
265 
271 
272 double extract_theta_from_layer( Gates_block* gate_structure, int layer_idx, Matrix_real& optimized_parameters);
273 
274 };
275 
276 
277 
278 
279 
280 
281 #endif
virtual unsigned int get_panelty(Gates_block *gate_structure, Matrix_real &optimized_parameters)
Call to get the panelty derived from the number of CRY and CNOT gates in the circuit.
Gates_block * optimize_imported_gate_structure(Matrix_real &optimized_parameters_mtx_loc)
Call to optimize an imported gate structure.
void add_adaptive_layers()
Call to add adaptive layers to the gate structure stored by the class.
void add_finalyzing_layer()
Call to add finalyzing layer (single qubit rotations on all of the qubits) to the gate structure stor...
Gates_block * compress_gate_structure(Gates_block *gate_structure, int uncompressed_iter_num)
Call to run compression iterations on the circuit.
bool randomized_adaptive_layers
Boolean variable to determine whether randomized adaptive layers are used or not. ...
int level_limit
The maximal number of adaptive layers used in the decomposition.
int LAPACKE_zggev(int matrix_layout, char jobvl, char jobvr, int n, QGD_Complex16 *a, int lda, QGD_Complex16 *b, int ldb, QGD_Complex16 *alpha, QGD_Complex16 *beta, QGD_Complex16 *vl, int ldvl, QGD_Complex16 *vr, int ldvr)
Definition of the zggev function from Lapacke to calculate the eigenvalues of a complex matrix...
std::vector< matrix_base< int > > topology
A vector of index pairs encoding the connectivity between the qubits.
virtual ~N_Qubit_Decomposition_adaptive()
Destructor of the class.
Matrix_real create_reduced_parameters(Gates_block *gate_structure, Matrix_real &optimized_parameters, int layer_idx)
Call to remove those parameters from the array, which correspond to gates that are about to be remove...
N_Qubit_Decomposition_adaptive()
Nullary constructor of the class.
int accelerator_num
number of utilized accelerators
int level_limit_min
The minimal number of adaptive layers used in the decomposition.
void apply_imported_gate_structure()
Call to apply the imported gate structure on the unitary.
void set_unitary_from_file(std::string filename)
Set unitary matrix from file.
void set_adaptive_gate_structure(std::string filename)
Call to set custom layers to the gate structure that are intended to be used in the decomposition...
A base class to determine the decomposition of an N-qubit unitary into a sequence of CNOT and U3 gate...
virtual Gates_block * remove_trivial_gates(Gates_block *gate_structure, Matrix_real &optimized_parameters, double &currnt_minimum_loc)
Call to remove those blocks from the circuit that contain a trivial CRY gate (i.e.
virtual void compress_circuit()
Compress the circuit.
Structure type representing complex numbers in the SQUANDER package.
Definition: QGDTypes.h:38
void add_adaptive_gate_structure(std::string filename)
Call to append custom layers to the gate structure that are intended to be used in the decomposition...
A base class to determine the decomposition of an N-qubit unitary into a sequence of CNOT and U3 gate...
virtual void get_initial_circuit()
get initial circuit
Gates_block * construct_adaptive_gate_layers()
Call to construct adaptive layers.
Class to store data of complex arrays and its properties.
Definition: matrix.h:38
A class responsible for grouping two-qubit (CNOT,CZ,CH) and one-qubit gates into layers.
Definition: Gates_block.h:41
virtual void finalize_circuit()
Finalize the circuit.
void add_layer_to_imported_gate_structure()
Call to add an adaptive layer to the gate structure previously imported gate structure.
std::map< std::string, Config_Element > config
config metadata utilized during the optimization
double extract_theta_from_layer(Gates_block *gate_structure, int layer_idx, Matrix_real &optimized_parameters)
virtual void start_decomposition()
Start the disentanglig process of the unitary.
void set_unitary(Matrix &Umtx_new)
Set unitary matrix.
Gates_block * determine_initial_gate_structure(Matrix_real &optimized_parameters_mtx)
Call determine the gate structrue of the decomposing circuit.
Matrix_real optimized_parameters_mtx
The optimized parameters for the gates.
Gates_block * replace_trivial_CRY_gates(Gates_block *gate_structure, Matrix_real &optimized_parameters)
Call to replace CRY gates in the circuit that are close to either an identity or to a CNOT gate...
Class to store data of complex arrays and its properties.
Definition: matrix_real.h:39