63 CZ_NU::CZ_NU(
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;
88 std::stringstream sstream;
89 sstream <<
"The index of the control qubit is larger than the number of qubits" << std::endl;
114 return get_matrix( parameters,
false );
127 apply_to( parameters, CZ_matrix, parallel);
144 std::string err(
"CZ_NU::apply_to: Wrong matrix size in CZ_NU gate apply.");
148 double param = parameters[0];
150 Matrix u3_1qbit = calc_one_qubit_u3( param );
151 apply_kernel_to(u3_1qbit, input,
false, parallel);
165 std::stringstream sstream;
166 sstream <<
"Wrong matrix size in CRY apply_from_right" << std::endl;
168 throw "Wrong matrix size in CRY apply_from_right";
171 double param = parameters[0];
173 Matrix u3_1qbit = calc_one_qubit_u3( param );
174 apply_kernel_from_right(u3_1qbit, input);
189 if ( parallel == 0 ) {
190 work_batch = inputs.size();
197 tbb::parallel_for( tbb::blocked_range<int>(0,inputs.size(),work_batch), [&](tbb::blocked_range<int> r) {
198 for (
int idx=r.begin(); idx<r.end(); ++idx) {
200 Matrix* input = &inputs[idx];
202 apply_to( parameters_mtx, *input, parallel );
222 std::stringstream sstream;
223 sstream <<
"Wrong matrix size in CRY gate apply" << std::endl;
225 throw "Wrong matrix size in CRY gate apply";
228 std::vector<Matrix> ret;
230 double param = parameters_mtx[0]+M_PI/2;
237 Matrix u3_1qbit = calc_one_qubit_u3( param );
242 apply_kernel_to(u3_1qbit, res_mtx, deriv, parallel);
244 ret.push_back(res_mtx);
308 u3_1qbit[0].real = 1.0; u3_1qbit[0].imag = 0.0;
309 u3_1qbit[1].real = 0.0; u3_1qbit[1].imag = 0.0;
310 u3_1qbit[2].real = 0.0; u3_1qbit[2].imag = 0.0;
311 u3_1qbit[3].real = cos( param); u3_1qbit[3].imag = 0.0;
Matrix calc_one_qubit_u3()
Set static values for matrix of the gates.
CZ_NU()
Nullary constructor of the class.
parameter_num
[set adaptive gate structure]
void apply_to(Matrix_real ¶meters, Matrix &input, int parallel)
Call to apply the gate on the input array/matrix CZ*input.
void set_optimized_parameters(double param)
Call to set the final optimized parameters of the gate.
virtual void set_qbit_num(int qbit_num_in)
Set the number of qubits spanning the matrix of the operation.
void apply_from_right(Matrix_real ¶meters, Matrix &input)
Call to apply the gate on the input array/matrix by input*CZ.
void apply_to_list(Matrix_real ¶meters, std::vector< Matrix > &inputs, int parallel)
Call to apply the gate on the input array/matrix by CZ_NU*input.
int rows
The number of rows.
int cols
The number of columns.
~CZ_NU()
Destructor of the class.
virtual CZ_NU * clone()
Call to create a clone of the present class.
def apply_to(self, parameters_mtx, unitary_mtx, parallel=1)
int Power_of_2(int n)
Calculates the n-th power of 2.
Matrix_real get_optimized_parameters()
Call to get the final optimized parameters of the gate.
Class to store data of complex arrays and its properties.
A class representing a CZ operation.
Matrix create_identity(int matrix_size)
Call to create an identity matrix.
void set_qbit_num(int qbit_num)
Call to set the number of qubits spanning the matrix of the operation.
Matrix copy()
Call to create a copy of the matrix.
void reorder_qubits(std::vector< int > qbit_list)
Call to reorder the qubits in the matrix of the operation.
Matrix get_matrix()
Call to retrieve the operation matrix.
virtual 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.
std::vector< Matrix > apply_derivate_to(Matrix_real ¶meters_mtx, Matrix &input, int parallel)
Call to evaluate the derivate of the circuit on an input with respect to all of the free parameters...