10 template <
typename RealMatrixT,
typename RealT>
11 void read_u3_trig(
const RealMatrixT& precomputed_sincos, RealT& sin_theta, RealT& cos_theta, RealT& sin_phi, RealT& cos_phi, RealT& sin_lambda, RealT& cos_lambda) {
12 const int theta_offset = 0 * precomputed_sincos.stride;
13 const int phi_offset = 1 * precomputed_sincos.stride;
14 const int lambda_offset = 2 * precomputed_sincos.stride;
15 sin_theta = precomputed_sincos[theta_offset + 0];
16 cos_theta = precomputed_sincos[theta_offset + 1];
17 sin_phi = precomputed_sincos[phi_offset + 0];
18 cos_phi = precomputed_sincos[phi_offset + 1];
19 sin_lambda = precomputed_sincos[lambda_offset + 0];
20 cos_lambda = precomputed_sincos[lambda_offset + 1];
27 U3::U3(
int qbit_num_in,
int target_qbit_in) :
Gate(qbit_num_in) {
34 std::string err(
"U3: target qubit index out of range.");
50 return {2.0, 1.0, 1.0};
90 double sin_theta, cos_theta, sin_phi, cos_phi, sin_lambda, cos_lambda;
91 read_u3_trig<Matrix_real, double>(precomputed_sincos, sin_theta, cos_theta, sin_phi, cos_phi, sin_lambda, cos_lambda);
92 calc_one_qubit_u3_from_trig_to<Matrix, double>(
output, sin_theta, cos_theta, sin_phi, cos_phi, sin_lambda, cos_lambda);
96 float sin_theta, cos_theta, sin_phi, cos_phi, sin_lambda, cos_lambda;
97 read_u3_trig<Matrix_real_float, float>(precomputed_sincos, sin_theta, cos_theta, sin_phi, cos_phi, sin_lambda, cos_lambda);
98 calc_one_qubit_u3_from_trig_to<Matrix_float, float>(
output, sin_theta, cos_theta, sin_phi, cos_phi, sin_lambda, cos_lambda);
102 double sin_theta, cos_theta, sin_phi, cos_phi, sin_lambda, cos_lambda;
103 read_u3_trig<Matrix_real, double>(precomputed_sincos, sin_theta, cos_theta, sin_phi, cos_phi, sin_lambda, cos_lambda);
104 calc_one_qubit_u3_inverse_from_trig_to<Matrix, double>(
output, sin_theta, cos_theta, sin_phi, cos_phi, sin_lambda, cos_lambda);
108 float sin_theta, cos_theta, sin_phi, cos_phi, sin_lambda, cos_lambda;
109 read_u3_trig<Matrix_real_float, float>(precomputed_sincos, sin_theta, cos_theta, sin_phi, cos_phi, sin_lambda, cos_lambda);
110 calc_one_qubit_u3_inverse_from_trig_to<Matrix_float, float>(
output, sin_theta, cos_theta, sin_phi, cos_phi, sin_lambda, cos_lambda);
114 double sin_theta, cos_theta, sin_phi, cos_phi, sin_lambda, cos_lambda;
115 read_u3_trig<Matrix_real, double>(precomputed_sincos, sin_theta, cos_theta, sin_phi, cos_phi, sin_lambda, cos_lambda);
116 if (param_idx == 0) {
117 u3_derivative_kernel_theta_from_trig_to<Matrix, double>(
output, sin_theta, cos_theta, sin_phi, cos_phi, sin_lambda, cos_lambda);
120 if (param_idx == 1) {
121 u3_derivative_kernel_phi_from_trig_to<Matrix, double>(
output, sin_theta, cos_theta, sin_phi, cos_phi, sin_lambda, cos_lambda);
124 if (param_idx == 2) {
125 u3_derivative_kernel_lambda_from_trig_to<Matrix, double>(
output, sin_theta, cos_theta, sin_phi, cos_phi, sin_lambda, cos_lambda);
132 float sin_theta, cos_theta, sin_phi, cos_phi, sin_lambda, cos_lambda;
133 read_u3_trig<Matrix_real_float, float>(precomputed_sincos, sin_theta, cos_theta, sin_phi, cos_phi, sin_lambda, cos_lambda);
134 if (param_idx == 0) {
135 u3_derivative_kernel_theta_from_trig_to<Matrix_float, float>(
output, sin_theta, cos_theta, sin_phi, cos_phi, sin_lambda, cos_lambda);
138 if (param_idx == 1) {
139 u3_derivative_kernel_phi_from_trig_to<Matrix_float, float>(
output, sin_theta, cos_theta, sin_phi, cos_phi, sin_lambda, cos_lambda);
142 if (param_idx == 2) {
143 u3_derivative_kernel_lambda_from_trig_to<Matrix_float, float>(
output, sin_theta, cos_theta, sin_phi, cos_phi, sin_lambda, cos_lambda);
150 double sin_theta, cos_theta;
151 double sin_phi, cos_phi;
152 double sin_lambda, cos_lambda;
156 return calc_one_qubit_u3_from_trig<Matrix, double>(sin_theta, cos_theta, sin_phi, cos_phi, sin_lambda, cos_lambda);
160 float sin_theta, cos_theta;
161 float sin_phi, cos_phi;
162 float sin_lambda, cos_lambda;
166 return calc_one_qubit_u3_from_trig<Matrix_float, float>(sin_theta, cos_theta, sin_phi, cos_phi, sin_lambda, cos_lambda);
void qgd_sincos< float >(float x, float *s, float *c)
std::vector< Gate * > parents
list of parent gates to be applied in the circuit prior to this current gate
Copyright (C) Miklos Maroti, 2021 SPDX-License-Identifier: Apache-2.0.
Class to store single-precision real arrays and properties.
void qgd_sincos< double >(double x, double *s, double *c)
virtual void gate_kernel_to(const Matrix_real &precomputed_sincos, Matrix &output) override
int control_qbit
The index of the qubit which acts as a control qubit (control_qbit >= 0) in controlled operations...
void set_children(std::vector< Gate *> &children_)
Call to set the children of the current gate.
int target_qbit
The index of the qubit on which the operation acts (target_qbit >= 0)
virtual Matrix gate_kernel(const Matrix_real &precomputed_sincos) override
Compute the gate kernel matrix from precomputed trigonometric values.
virtual std::vector< double > get_parameter_multipliers() const override
Returns the per-parameter multipliers relative to 2Ï used by extract_parameters. ...
gate_type type
The type of the operation (see enumeration gate_type)
virtual void derivative_kernel_to(const Matrix_real &precomputed_sincos, int param_idx, Matrix &output) override
virtual Matrix inverse_gate_kernel(const Matrix_real &precomputed_sincos) override
virtual void inverse_gate_kernel_to(const Matrix_real &precomputed_sincos, 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 ...
Double-precision complex matrix (float64).
virtual Matrix derivative_kernel(const Matrix_real &precomputed_sincos, int param_idx) override
Matrix_float u3_matrix_kernel_f(float ThetaOver2, float Phi, float Lambda)
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
Base class for the representation of general gate operations.
int parameter_num
the number of free parameters of the operation
void set_parents(std::vector< Gate *> &parents_)
Call to set the parents of the current gate.
Matrix u3_matrix_kernel(double ThetaOver2, double Phi, double Lambda)
int qbit_num
number of qubits spanning the matrix of the operation
virtual U3 * clone() override
Call to create a clone of the present class.
Class to store data of complex arrays and its properties.