Sequential Quantum Gate Decomposer  v1.9.3
Powerful decomposition of general unitarias into one- and two-qubit gates gates
custom_kernel_1qubit_gate.cpp
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 
25 
26 
27 //static tbb::spin_mutex my_mutex;
32 
33  // A string labeling the gate operation
34  name = "custom_kernel";
35 
36  // number of qubits spanning the matrix of the gate
37  qbit_num = -1;
38  // the size of the matrix
39  matrix_size = -1;
40  // A string describing the type of the gate
42 
43  // The index of the qubit on which the gate acts (target_qbit >= 0)
44  target_qbit = -1;
45  // The index of the qubit which acts as a control qubit (control_qbit >= 0) in controlled gates
46  control_qbit = -1;
47 
48  parameter_num = 0;
49 
50 
51 
52 }
53 
54 
55 
62 custom_kernel_1qubit_gate::custom_kernel_1qubit_gate(int qbit_num_in, int target_qbit_in, Matrix& kernel_in) {
63 
64  // A string labeling the gate operation
65  name = "custom_kernel";
66  //The stringstream input to store the output messages.
67  std::stringstream sstream;
68 
69 
70  // number of qubits spanning the matrix of the gate
71  qbit_num = qbit_num_in;
72  // the size of the matrix
74  // A string describing the type of the gate
76 
77  kernel = kernel_in;
78 
79 
80  if (target_qbit_in >= qbit_num) {
81  sstream << "The index of the target qubit is larger than the number of qubits" << std::endl;
82  print(sstream, 1);
83 
84  throw "The index of the target qubit is larger than the number of qubits";
85  }
86 
87  // The index of the qubit on which the gate acts (target_qbit >= 0)
88  target_qbit = target_qbit_in;
89  // The index of the qubit which acts as a control qubit (control_qbit >= 0) in controlled gates
90  control_qbit = -1;
91 
92  parameter_num = 0;
93 
94 
95 }
96 
97 
102 
103 
104 }
105 
106 
107 
108 
114 void
116 
117 
118  if (input.rows != matrix_size ) {
119  std::string err("Wrong matrix size in custom_kernel_1qubit_gate gate apply");
120  throw err;
121  }
122 
123 
124  apply_kernel_to( kernel, input );
125 
126 
127 }
128 
129 
130 
136 void
138 
139 
140  if (input.cols != matrix_size ) {
141  std::string err("Wrong matrix size in U3 apply_from_right");
142  throw err;
143  }
144 
145 
147 
148 
149 
150 }
151 
152 
158 
160 
162 
163  return ret;
164 
165 }
166 
167 
168 
169 
Header file for a class representing a single qubit gate with custom gate kernel. ...
void print(const std::stringstream &sstream, int verbose_level=1) const
Call to print output messages in the function of the verbosity level.
Definition: logging.cpp:55
A class representing a custom_kernel_1qubit_gate gate.
int control_qbit
The index of the qubit which acts as a control qubit (control_qbit >= 0) in controlled operations...
Definition: Gate.h:87
int target_qbit
The index of the qubit on which the operation acts (target_qbit >= 0)
Definition: Gate.h:85
void apply_from_right(Matrix_real &parameters, Matrix &input)
Call to apply the gate on the input array/matrix by input*U3.
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
custom_kernel_1qubit_gate * clone()
Call to create a clone of the present class.
int matrix_size
The size N of the NxN matrix associated with the operations.
Definition: Gate.h:89
custom_kernel_1qubit_gate()
Nullacustom_kernel_1qubit_gate constructor of the class.
gate_type type
The type of the operation (see enumeration gate_type)
Definition: Gate.h:83
int rows
The number of rows.
Definition: matrix_base.hpp:42
int cols
The number of columns.
Definition: matrix_base.hpp:44
void apply_to(Matrix &input)
Call to apply the gate on the input array/matrix by U3*input.
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
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
int Power_of_2(int n)
Calculates the n-th power of 2.
Definition: common.cpp:117
Class to store data of complex arrays and its properties.
Definition: matrix.h:38
std::string name
A string labeling the gate operation.
Definition: Gate.h:79
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
int parameter_num
the number of free parameters of the operation
Definition: Gate.h:91
int qbit_num
number of qubits spanning the matrix of the operation
Definition: Gate.h:81
~custom_kernel_1qubit_gate()
Destructor of the class.
Class to store data of complex arrays and its properties.
Definition: matrix_real.h:39