Sequential Quantum Gate Decomposer  v1.9.3
Powerful decomposition of general unitarias into one- and two-qubit gates gates
Gate.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 GATE_H
24 #define GATE_H
25 
26 #include <vector>
27 #include "common.h"
28 #include "matrix.h"
29 #include "logging.h"
30 #include "matrix_real.h"
31 
32 
34 typedef enum gate_type {GENERAL_OPERATION=1,
68 
69 
70 
74 class Gate : public logging {
75 
76 
77 protected:
78 
80  std::string name;
82  int qbit_num;
96  std::vector<Gate*> parents;
98  std::vector<Gate*> children;
99 
100 private:
101 
104 
105 public:
106 
111 Gate();
112 
116 virtual ~Gate();
117 
118 
124 Gate(int qbit_num_in);
125 
130 virtual Matrix get_matrix();
131 
137 virtual Matrix get_matrix(int parallel);
138 
139 
146 
147 
154 virtual Matrix get_matrix( Matrix_real& parameters, int parallel );
155 
156 
162 virtual void apply_to_list( std::vector<Matrix>& inputs, int parallel );
163 
164 
171 virtual void apply_to_list( Matrix_real& parameters_mtx, std::vector<Matrix>& inputs, int parallel );
172 
178 virtual void apply_to( Matrix& input, int parallel );
179 
186 virtual void apply_to( Matrix_real& parameter_mtx, Matrix& input, int parallel );
187 
188 
195 virtual std::vector<Matrix> apply_derivate_to( Matrix_real& parameters_mtx_in, Matrix& input, int parallel );
196 
197 
202 virtual void apply_from_right( Matrix& input );
203 
209 void set_matrix( Matrix input );
210 
211 
216 void set_control_qbit(int control_qbit_in);
217 
222 void set_target_qbit(int target_qbit_in);
223 
228 virtual void set_qbit_num( int qbit_num_in );
229 
234 virtual void reorder_qubits( std::vector<int> qbit_list );
235 
236 
241 int get_target_qbit();
242 
243 
248 int get_control_qbit();
249 
254 virtual std::vector<int> get_involved_qubits();
255 
256 
261 void add_child( Gate* child );
262 
263 
268 void add_parent( Gate* parent );
269 
270 
274 void clear_children();
275 
276 
280 void clear_parents();
281 
286 int get_parameter_num();
287 
288 
294 
299 int get_qbit_num();
300 
301 
306 void set_parameter_start_idx(int start_idx);
307 
308 
313 void set_parents( std::vector<Gate*>& parents_ );
314 
315 
320 void set_children( std::vector<Gate*>& children_ );
321 
322 
323 
328 std::vector<Gate*> get_parents();
329 
330 
335 std::vector<Gate*> get_children();
336 
337 
343 
344 
349 std::string get_name();
350 
355 virtual Gate* clone();
356 
357 
365 virtual Matrix calc_one_qubit_u3(double Theta, double Phi, double Lambda );
366 
371 virtual Matrix calc_one_qubit_u3( );
372 
380 virtual void parameters_for_calc_one_qubit(double& ThetaOver2, double& Phi, double& Lambda);
381 
388 
389 
390 
391 
392 protected:
401 void apply_kernel_to( Matrix& u3_1qbit, Matrix& input, bool deriv=false, int parallel=0 );
402 
403 
404 
411 void apply_kernel_from_right( Matrix& u3_1qbit, Matrix& input );
412 
413 
414 };
415 
416 #endif //GATE
std::vector< Gate * > parents
list of parent gates to be applied in the circuit prior to this current gate
Definition: Gate.h:96
Gate()
Default constructor of the class.
Definition: Gate.cpp:39
virtual void parameters_for_calc_one_qubit(double &ThetaOver2, double &Phi, double &Lambda)
Calculate the matrix of a U3 gate gate corresponding to the given parameters acting on a single qbit ...
Definition: Gate.cpp:767
void add_child(Gate *child)
Call to add a child gate to the current gate.
Definition: Gate.cpp:426
virtual Matrix get_matrix()
Call to retrieve the operation matrix.
Definition: Gate.cpp:129
void clear_children()
Call to erase data on children.
Definition: Gate.cpp:441
int control_qbit
The index of the qubit which acts as a control qubit (control_qbit >= 0) in controlled operations...
Definition: Gate.h:88
virtual std::vector< Matrix > apply_derivate_to(Matrix_real &parameters_mtx_in, Matrix &input, int parallel)
Call to evaluate the derivate of the circuit on an inout with respect to all of the free parameters...
Definition: Gate.cpp:271
virtual Gate * clone()
Call to create a clone of the present class.
Definition: Gate.cpp:513
void set_children(std::vector< Gate *> &children_)
Call to set the children of the current gate.
Definition: Gate.cpp:802
virtual void set_qbit_num(int qbit_num_in)
Set the number of qubits spanning the matrix of the operation.
Definition: Gate.cpp:102
int target_qbit
The index of the qubit on which the operation acts (target_qbit >= 0)
Definition: Gate.h:86
void apply_kernel_from_right(Matrix &u3_1qbit, Matrix &input)
Call to apply the gate kernel on the input state or unitary from right (no AVX support) ...
Definition: Gate.cpp:613
virtual ~Gate()
Destructor of the class.
Definition: Gate.cpp:95
Header file for a class containing basic methods for setting up the verbosity level.
int matrix_size
The size N of the NxN matrix associated with the operations.
Definition: Gate.h:90
int parameter_start_idx
the index in the parameter array (corrensponding to the encapsulated circuit) where the gate paramete...
Definition: Gate.h:94
A class containing basic methods for setting up the verbosity level.
Definition: logging.h:43
gate_type type
The type of the operation (see enumeration gate_type)
Definition: Gate.h:84
virtual void apply_from_right(Matrix &input)
Call to apply the gate on the input array/matrix by input*Gate.
Definition: Gate.cpp:285
gate_type get_type()
Call to get the type of the operation.
Definition: Gate.cpp:495
Header file of complex array storage array with automatic and thread safe reference counting...
void set_control_qbit(int control_qbit_in)
Call to set the control qubit for the gate operation.
Definition: Gate.cpp:308
void set_parameter_start_idx(int start_idx)
Call to set the starting index of the parameters in the parameter array corresponding to the circuit ...
Definition: Gate.cpp:779
std::vector< Gate * > get_parents()
Call to get the parents of the current gate.
Definition: Gate.cpp:463
int get_parameter_start_idx()
Call to get the starting index of the parameters in the parameter array corresponding to the circuit ...
Definition: Gate.cpp:814
void add_parent(Gate *parent)
Call to add a parent gate to the current gate.
Definition: Gate.cpp:409
void set_target_qbit(int target_qbit_in)
Call to set the target qubit for the gate operation.
Definition: Gate.cpp:324
virtual Matrix_real extract_parameters(Matrix_real &parameters)
Call to extract parameters from the parameter array corresponding to the circuit, in which the gate i...
Definition: Gate.cpp:827
void clear_parents()
Call to erase data on parents.
Definition: Gate.cpp:451
virtual Matrix calc_one_qubit_u3()
Calculate the matrix of the constans gates.
Definition: Gate.cpp:750
void set_matrix(Matrix input)
Call to set the stored matrix in the operation.
Definition: Gate.cpp:299
std::vector< Gate * > get_children()
Call to get the children of the current gate.
Definition: Gate.cpp:474
Class to store data of complex arrays and its properties.
Definition: matrix.h:38
int get_parameter_num()
Call to get the number of free parameters.
Definition: Gate.cpp:486
std::string name
A string labeling the gate operation.
Definition: Gate.h:80
std::vector< Gate * > children
list of child gates to be applied after this current gate
Definition: Gate.h:98
int get_target_qbit()
Call to get the index of the target qubit.
Definition: Gate.cpp:370
void apply_kernel_to(Matrix &u3_1qbit, Matrix &input, bool deriv=false, int parallel=0)
Call to apply the gate kernel on the input state or unitary with optional AVX support.
Definition: Gate.cpp:537
Base class for the representation of general gate operations.
Definition: Gate.h:74
std::string get_name()
Call to get the name label of the gate.
Definition: Gate.cpp:839
virtual std::vector< int > get_involved_qubits()
Call to get the qubits involved in the gate operation.
Definition: Gate.cpp:386
int parameter_num
the number of free parameters of the operation
Definition: Gate.h:92
Header file for commonly used functions and wrappers to CBLAS functions.
virtual void apply_to_list(std::vector< Matrix > &inputs, int parallel)
Call to apply the gate on a list of inputs.
Definition: Gate.cpp:187
void set_parents(std::vector< Gate *> &parents_)
Call to set the parents of the current gate.
Definition: Gate.cpp:790
int qbit_num
number of qubits spanning the matrix of the operation
Definition: Gate.h:82
int get_qbit_num()
Call to get the number of qubits composing the unitary.
Definition: Gate.cpp:504
gate_type
Type definition of operation types (also generalized for decomposition classes derived from the class...
Definition: Gate.h:34
virtual void apply_to(Matrix &input, int parallel)
Call to apply the gate on the input array/matrix.
Definition: Gate.cpp:237
virtual void reorder_qubits(std::vector< int > qbit_list)
Call to reorder the qubits in the matrix of the operation.
Definition: Gate.cpp:339
Matrix matrix_alloc
Matrix of the operation.
Definition: Gate.h:103
int get_control_qbit()
Call to get the index of the control qubit.
Definition: Gate.cpp:378
Class to store data of complex arrays and its properties.
Definition: matrix_real.h:39