63 SYC::SYC(
int qbit_num_in,
int target_qbit_in,
int control_qbit_in) {
78 std::stringstream sstream;
79 sstream <<
"The index of the target qubit is larger than the number of qubits" << std::endl;
81 throw "The index of the target qubit is larger than the number of qubits";
89 std::stringstream sstream;
90 sstream <<
"The index of the control qubit is larger than the number of qubits" << std::endl;
92 throw "The index of the control qubit is larger than the number of qubits";
114 return get_matrix(
false );
144 std::string err(
"SYC::apply_to: Wrong input size in SYC gate apply.");
151 int loopSize = index_step_target < index_step_control ? index_step_target : index_step_control;
156 int idx01 = index_step_target;
157 int idx10 = index_step_control;
158 int idx11 = index_step_target + index_step_control;
168 for (
int jdx=0; jdx<iterations; jdx++ ) {
170 tbb::parallel_for(0, loopSize, 1, [&](
int idx) {
174 int idx01_loc = idx01 + idx;
175 int idx10_loc = idx10 + idx;
176 int idx11_loc = idx11 + idx;
180 int offset01 = idx01_loc*input.
stride;
181 int offset10 = idx10_loc*input.
stride;
182 int offset11 = idx11_loc*input.
stride;
185 for (
int col_idx=0; col_idx<input.
cols; col_idx++) {
190 input[ offset01 + col_idx ].real = element10.
imag;
191 input[ offset01 + col_idx ].imag = -element10.
real;
193 input[ offset10 + col_idx ].real = element01.
imag;
194 input[ offset10 + col_idx ].imag = -element01.
real;
200 factor.
real = sqrt(3)/2;
202 input[ offset11 + col_idx ] =
mult(element11, factor);
214 idx00 = idx00 + 2*loopSize;
215 idx01 = idx01 + 2*loopSize;
216 idx10 = idx10 + 2*loopSize;
217 idx11 = idx11 + 2*loopSize;
223 idx00 = idx00 + 2*loopSize*iterations;
224 idx01 = idx01 + 2*loopSize*iterations;
225 idx10 = idx10 + 2*loopSize*iterations;
226 idx11 = idx11 + 2*loopSize*iterations;
251 int loopSize = index_step_target < index_step_control ? index_step_target : index_step_control;
257 tbb::parallel_for(0,
matrix_size, 1, [&](
int idx) {
259 int offset = idx*input.
stride;
263 int idx01 = index_step_target;
264 int idx10 = index_step_control;
265 int idx11 = index_step_target + index_step_control;
269 for (
int jdx=0; jdx<iterations; jdx++ ) {
272 for (
int idx=0; idx<loopSize; idx++ ) {
276 int idx01_loc = idx01 + idx;
277 int idx10_loc = idx10 + idx;
278 int idx11_loc = idx11 + idx;
283 input[ offset + idx01_loc ].real = element10.
imag;
284 input[ offset + idx01_loc ].imag = -element10.
real;
286 input[ offset + idx10_loc ].real = element01.
imag;
287 input[ offset + idx10_loc ].imag = -element01.
real;
293 factor.
real = sqrt(3)/2;
295 input[ offset + idx11_loc ] =
mult(element11, factor);
299 idx00 = idx00 + 2*loopSize;
300 idx01 = idx01 + 2*loopSize;
301 idx10 = idx10 + 2*loopSize;
302 idx11 = idx11 + 2*loopSize;
307 idx00 = idx00 + 2*loopSize*iterations;
308 idx01 = idx01 + 2*loopSize*iterations;
309 idx10 = idx10 + 2*loopSize*iterations;
310 idx11 = idx11 + 2*loopSize*iterations;
parameter_num
[set adaptive gate structure]
int stride
The column stride of the array. (The array elements in one row are a_0, a_1, ... a_{cols-1}, 0, 0, 0, 0. The number of zeros is stride-cols)
void set_children(std::vector< Gate *> &children_)
Call to set the children of the current gate.
virtual void set_qbit_num(int qbit_num_in)
Set the number of qubits spanning the matrix of the operation.
SYC()
Nullary constructor of the class.
SYC * clone()
Call to create a clone of the present class.
void apply_from_right(Matrix &input)
Call to apply the gate on the input array/matrix by input*SYC.
QGD_Complex16 mult(QGD_Complex16 &a, QGD_Complex16 &b)
Call to calculate the product of two complex scalars.
int rows
The number of rows.
int cols
The number of columns.
void set_qbit_num(int qbit_num)
Call to set the number of qubits spanning the matrix of the operation.
void apply_to(Matrix &input, int parallel)
Call to apply the gate on the input array/matrix by SYC*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 ...
~SYC()
Destructor of the class.
def apply_to(self, parameters_mtx, unitary_mtx, parallel=1)
Structure type representing complex numbers in the SQUANDER package.
int Power_of_2(int n)
Calculates the n-th power of 2.
void reorder_qubits(std::vector< int > qbit_list)
Call to reorder the qubits in the matrix of the operation.
Class to store data of complex arrays and its properties.
Matrix get_matrix()
Call to retrieve the operation matrix.
Matrix create_identity(int matrix_size)
Call to create an identity matrix.
void set_parents(std::vector< Gate *> &parents_)
Call to set the parents of the current gate.
A class representing a SYC operation.
double real
the real part of a complex number
virtual void reorder_qubits(std::vector< int > qbit_list)
Call to reorder the qubits in the matrix of the operation.
double imag
the imaginary part of a complex number
Header file for a class representing a Sycamore gate.