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,
67 
68 
69 
73 class Gate : public logging {
74 
75 
76 protected:
77 
79  std::string name;
81  int qbit_num;
95  std::vector<Gate*> parents;
97  std::vector<Gate*> children;
98 
99 private:
100 
103 
104 public:
105 
110 Gate();
111 
115 virtual ~Gate();
116 
117 
123 Gate(int qbit_num_in);
124 
129 virtual Matrix get_matrix();
130 
136 virtual Matrix get_matrix(int parallel);
137 
138 
145 
146 
153 virtual Matrix get_matrix( Matrix_real& parameters, int parallel );
154 
155 
161 virtual void apply_to_list( std::vector<Matrix>& inputs, int parallel );
162 
163 
170 virtual void apply_to_list( Matrix_real& parameters_mtx, std::vector<Matrix>& inputs, int parallel );
171 
177 virtual void apply_to( Matrix& input, int parallel );
178 
185 virtual void apply_to( Matrix_real& parameter_mtx, Matrix& input, int parallel );
186 
187 
194 virtual std::vector<Matrix> apply_derivate_to( Matrix_real& parameters_mtx_in, Matrix& input, int parallel );
195 
196 
201 virtual void apply_from_right( Matrix& input );
202 
208 void set_matrix( Matrix input );
209 
210 
215 void set_control_qbit(int control_qbit_in);
216 
221 void set_target_qbit(int target_qbit_in);
222 
227 virtual void set_qbit_num( int qbit_num_in );
228 
233 virtual void reorder_qubits( std::vector<int> qbit_list );
234 
235 
240 int get_target_qbit();
241 
242 
247 int get_control_qbit();
248 
253 virtual std::vector<int> get_involved_qubits();
254 
255 
260 void add_child( Gate* child );
261 
262 
267 void add_parent( Gate* parent );
268 
269 
273 void clear_children();
274 
275 
279 void clear_parents();
280 
285 int get_parameter_num();
286 
287 
293 
298 int get_qbit_num();
299 
300 
305 void set_parameter_start_idx(int start_idx);
306 
307 
312 void set_parents( std::vector<Gate*>& parents_ );
313 
314 
319 void set_children( std::vector<Gate*>& children_ );
320 
321 
322 
327 std::vector<Gate*> get_parents();
328 
329 
334 std::vector<Gate*> get_children();
335 
336 
342 
343 
348 std::string get_name();
349 
354 virtual Gate* clone();
355 
356 
364 virtual Matrix calc_one_qubit_u3(double Theta, double Phi, double Lambda );
365 
370 virtual Matrix calc_one_qubit_u3( );
371 
379 virtual void parameters_for_calc_one_qubit(double& ThetaOver2, double& Phi, double& Lambda);
380 
387 
388 
389 
390 
391 protected:
400 void apply_kernel_to( Matrix& u3_1qbit, Matrix& input, bool deriv=false, int parallel=0 );
401 
402 
403 
410 void apply_kernel_from_right( Matrix& u3_1qbit, Matrix& input );
411 
412 
413 };
414 
415 #endif //GATE
std::vector< Gate * > parents
list of parent gates to be applied in the circuit prior to this current gate
Definition: Gate.h:95
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:87
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:85
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:89
int parameter_start_idx
the index in the parameter array (corrensponding to the encapsulated circuit) where the gate paramete...
Definition: Gate.h:93
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:83
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:79
std::vector< Gate * > children
list of child gates to be applied after this current gate
Definition: Gate.h:97
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:73
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:91
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:81
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:102
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