29 template<
typename RealMatrixT,
typename RealT>
31 const RealMatrixT& precomputed_sincos,
37 const int theta_offset = 0 * precomputed_sincos.stride;
38 const int phi_offset = 1 * precomputed_sincos.stride;
39 s_theta = precomputed_sincos[theta_offset + 0];
40 c_theta = precomputed_sincos[theta_offset + 1];
41 s_phi = precomputed_sincos[phi_offset + 0];
42 c_phi = precomputed_sincos[phi_offset + 1];
77 CROT::CROT(
int qbit_num_in,
int target_qbit_in,
int control_qbit_in) {
94 std::stringstream sstream;
95 sstream <<
"The index of the control qubit is larger than the number of qubits in CROT gate." << std::endl;
176 double s_theta, c_theta, s_phi, c_phi;
177 read_crot_trig<Matrix_real, double>(precomputed_sincos, s_theta, c_theta, s_phi, c_phi);
178 build_crot_gate_kernel_from_trig_to<Matrix, double>(
output, s_theta, c_theta, s_phi, c_phi);
183 float s_theta, c_theta, s_phi, c_phi;
184 read_crot_trig<Matrix_real_float, float>(precomputed_sincos, s_theta, c_theta, s_phi, c_phi);
185 build_crot_gate_kernel_from_trig_to<Matrix_float, float>(
output, s_theta, c_theta, s_phi, c_phi);
190 double s_theta, c_theta, s_phi, c_phi;
191 read_crot_trig<Matrix_real, double>(precomputed_sincos, s_theta, c_theta, s_phi, c_phi);
192 build_crot_inverse_gate_kernel_from_trig_to<Matrix, double>(
output, s_theta, c_theta, s_phi, c_phi);
197 float s_theta, c_theta, s_phi, c_phi;
198 read_crot_trig<Matrix_real_float, float>(precomputed_sincos, s_theta, c_theta, s_phi, c_phi);
199 build_crot_inverse_gate_kernel_from_trig_to<Matrix_float, float>(
output, s_theta, c_theta, s_phi, c_phi);
204 double s_theta, c_theta, s_phi, c_phi;
205 read_crot_trig<Matrix_real, double>(precomputed_sincos, s_theta, c_theta, s_phi, c_phi);
206 if (param_idx == 0) {
207 build_crot_theta_derivative_kernel_from_trig_to<Matrix, double>(
output, s_theta, c_theta, s_phi, c_phi);
210 if (param_idx == 1) {
211 build_crot_phi_derivative_kernel_from_trig_to<Matrix, double>(
output, s_theta, c_theta, s_phi, c_phi);
219 float s_theta, c_theta, s_phi, c_phi;
220 read_crot_trig<Matrix_real_float, float>(precomputed_sincos, s_theta, c_theta, s_phi, c_phi);
221 if (param_idx == 0) {
222 build_crot_theta_derivative_kernel_from_trig_to<Matrix_float, float>(
output, s_theta, c_theta, s_phi, c_phi);
225 if (param_idx == 1) {
226 build_crot_phi_derivative_kernel_from_trig_to<Matrix_float, float>(
output, s_theta, c_theta, s_phi, c_phi);
234 double s_theta, c_theta, s_phi, c_phi;
235 read_crot_trig<Matrix_real, double>(precomputed_sincos, s_theta, c_theta, s_phi, c_phi);
236 if (param_idx == 0) {
237 build_crot_theta_derivative_aux_kernel_from_trig_to<Matrix, double>(
output, s_theta, c_theta, s_phi, c_phi);
240 if (param_idx == 1) {
241 build_crot_phi_derivative_aux_kernel_from_trig_to<Matrix, double>(
output, s_theta, c_theta, s_phi, c_phi);
249 float s_theta, c_theta, s_phi, c_phi;
250 read_crot_trig<Matrix_real_float, float>(precomputed_sincos, s_theta, c_theta, s_phi, c_phi);
251 if (param_idx == 0) {
252 build_crot_theta_derivative_aux_kernel_from_trig_to<Matrix_float, float>(
output, s_theta, c_theta, s_phi, c_phi);
255 if (param_idx == 1) {
256 build_crot_phi_derivative_aux_kernel_from_trig_to<Matrix_float, float>(
output, s_theta, c_theta, s_phi, c_phi);
std::vector< Gate * > parents
list of parent gates to be applied in the circuit prior to this current gate
void print(const std::stringstream &sstream, int verbose_level=1) const
Call to print output messages in the function of the verbosity level.
virtual CROT * clone() override
Call to create a clone of the present class.
Class to store single-precision real arrays and properties.
int control_qbit
The index of the qubit which acts as a control qubit (control_qbit >= 0) in controlled operations...
~CROT() override
Destructor of the class.
void set_children(std::vector< Gate *> &children_)
Call to set the children of the current gate.
Header file for a class representing a controlled rotation gate around the Y axis.
int target_qbit
The index of the qubit on which the operation acts (target_qbit >= 0)
virtual Matrix derivative_kernel(const Matrix_real &precomputed_sincos, int param_idx) override
std::vector< double > get_parameter_multipliers() const override
Returns the per-parameter multipliers relative to 2Ï used by extract_parameters. ...
virtual Matrix gate_kernel(const Matrix_real &precomputed_sincos) override
Compute the gate kernel matrix from precomputed trigonometric values.
int matrix_size
The size N of the NxN matrix associated with the operations.
A class representing a CROT gate.
gate_type type
The type of the operation (see enumeration gate_type)
virtual void derivative_aux_kernel_to(const Matrix_real &precomputed_sincos, int param_idx, Matrix &output) override
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 ...
int get_parameter_start_idx()
Call to get the starting index of the parameters in the parameter array corresponding to the circuit ...
int Power_of_2(int n)
Calculates the n-th power of 2.
Double-precision complex matrix (float64).
virtual void derivative_kernel_to(const Matrix_real &precomputed_sincos, int param_idx, Matrix &output) override
virtual void inverse_gate_kernel_to(const Matrix_real &precomputed_sincos, Matrix &output) override
std::string name
A string labeling the gate operation.
Single-precision complex matrix (float32).
std::vector< Gate * > children
list of child gates to be applied after this current gate
virtual void gate_kernel_to(const Matrix_real &precomputed_sincos, Matrix &output) override
int parameter_num
the number of free parameters of the operation
CROT()
Nullary constructor of the class.
void set_parents(std::vector< Gate *> &parents_)
Call to set the parents of the current gate.
int qbit_num
number of qubits spanning the matrix of the operation
virtual Matrix derivative_aux_kernel(const Matrix_real &precomputed_sincos, int param_idx) override
Class to store data of complex arrays and its properties.
virtual Matrix inverse_gate_kernel(const Matrix_real &precomputed_sincos) override