7 template<
typename RealMatrixT,
typename RealT>
9 const RealMatrixT& precomputed_sincos,
19 const int theta_offset = 0 * precomputed_sincos.stride;
20 const int phi_offset = 1 * precomputed_sincos.stride;
21 const int lambda_offset = 2 * precomputed_sincos.stride;
22 const int gamma_offset = 3 * precomputed_sincos.stride;
23 sin_theta = precomputed_sincos[theta_offset + 0];
24 cos_theta = precomputed_sincos[theta_offset + 1];
25 sin_phi = precomputed_sincos[phi_offset + 0];
26 cos_phi = precomputed_sincos[phi_offset + 1];
27 sin_lambda = precomputed_sincos[lambda_offset + 0];
28 cos_lambda = precomputed_sincos[lambda_offset + 1];
29 sin_gamma = precomputed_sincos[gamma_offset + 0];
30 cos_gamma = precomputed_sincos[gamma_offset + 1];
36 CU::CU(
int qbit_num_in,
int target_qbit_in,
int control_qbit_in)
37 :
U3(qbit_num_in, target_qbit_in) {
42 std::string err(
"CU: control qubit index out of range.");
59 return {2.0, 1.0, 1.0, 1.0};
100 double sin_theta, cos_theta, sin_phi, cos_phi, sin_lambda, cos_lambda, sin_gamma, cos_gamma;
101 read_cu_trig<Matrix_real, double>(
103 sin_theta, cos_theta, sin_phi, cos_phi, sin_lambda, cos_lambda, sin_gamma, cos_gamma
105 cu_gate_kernel_from_trig_to<Matrix, double>(
106 output, sin_theta, cos_theta, sin_phi, cos_phi, sin_lambda, cos_lambda, sin_gamma, cos_gamma
112 float sin_theta, cos_theta, sin_phi, cos_phi, sin_lambda, cos_lambda, sin_gamma, cos_gamma;
113 read_cu_trig<Matrix_real_float, float>(
115 sin_theta, cos_theta, sin_phi, cos_phi, sin_lambda, cos_lambda, sin_gamma, cos_gamma
117 cu_gate_kernel_from_trig_to<Matrix_float, float>(
118 output, sin_theta, cos_theta, sin_phi, cos_phi, sin_lambda, cos_lambda, sin_gamma, cos_gamma
124 double sin_theta, cos_theta, sin_phi, cos_phi, sin_lambda, cos_lambda, sin_gamma, cos_gamma;
125 read_cu_trig<Matrix_real, double>(
127 sin_theta, cos_theta, sin_phi, cos_phi, sin_lambda, cos_lambda, sin_gamma, cos_gamma
129 cu_inverse_gate_kernel_from_trig_to<Matrix, double>(
130 output, sin_theta, cos_theta, sin_phi, cos_phi, sin_lambda, cos_lambda, sin_gamma, cos_gamma
136 float sin_theta, cos_theta, sin_phi, cos_phi, sin_lambda, cos_lambda, sin_gamma, cos_gamma;
137 read_cu_trig<Matrix_real_float, float>(
139 sin_theta, cos_theta, sin_phi, cos_phi, sin_lambda, cos_lambda, sin_gamma, cos_gamma
141 cu_inverse_gate_kernel_from_trig_to<Matrix_float, float>(
142 output, sin_theta, cos_theta, sin_phi, cos_phi, sin_lambda, cos_lambda, sin_gamma, cos_gamma
148 double sin_theta, cos_theta, sin_phi, cos_phi, sin_lambda, cos_lambda, sin_gamma, cos_gamma;
149 read_cu_trig<Matrix_real, double>(
151 sin_theta, cos_theta, sin_phi, cos_phi, sin_lambda, cos_lambda, sin_gamma, cos_gamma
154 if (param_idx == 0) {
155 u3_derivative_kernel_theta_from_trig_to<Matrix, double>(
156 output, sin_theta, cos_theta, sin_phi, cos_phi, sin_lambda, cos_lambda
158 multiply_2x2_by_phase<Matrix, double>(
output, sin_gamma, cos_gamma);
161 if (param_idx == 1) {
162 u3_derivative_kernel_phi_from_trig_to<Matrix, double>(
163 output, sin_theta, cos_theta, sin_phi, cos_phi, sin_lambda, cos_lambda
165 multiply_2x2_by_phase<Matrix, double>(
output, sin_gamma, cos_gamma);
168 if (param_idx == 2) {
169 u3_derivative_kernel_lambda_from_trig_to<Matrix, double>(
170 output, sin_theta, cos_theta, sin_phi, cos_phi, sin_lambda, cos_lambda
172 multiply_2x2_by_phase<Matrix, double>(
output, sin_gamma, cos_gamma);
175 if (param_idx == 3) {
176 cu_derivative_kernel_gamma_from_trig_to<Matrix, double>(
177 output, sin_theta, cos_theta, sin_phi, cos_phi, sin_lambda, cos_lambda, sin_gamma, cos_gamma
187 float sin_theta, cos_theta, sin_phi, cos_phi, sin_lambda, cos_lambda, sin_gamma, cos_gamma;
188 read_cu_trig<Matrix_real_float, float>(
190 sin_theta, cos_theta, sin_phi, cos_phi, sin_lambda, cos_lambda, sin_gamma, cos_gamma
193 if (param_idx == 0) {
194 u3_derivative_kernel_theta_from_trig_to<Matrix_float, float>(
195 output, sin_theta, cos_theta, sin_phi, cos_phi, sin_lambda, cos_lambda
197 multiply_2x2_by_phase<Matrix_float, float>(
output, sin_gamma, cos_gamma);
200 if (param_idx == 1) {
201 u3_derivative_kernel_phi_from_trig_to<Matrix_float, float>(
202 output, sin_theta, cos_theta, sin_phi, cos_phi, sin_lambda, cos_lambda
204 multiply_2x2_by_phase<Matrix_float, float>(
output, sin_gamma, cos_gamma);
207 if (param_idx == 2) {
208 u3_derivative_kernel_lambda_from_trig_to<Matrix_float, float>(
209 output, sin_theta, cos_theta, sin_phi, cos_phi, sin_lambda, cos_lambda
211 multiply_2x2_by_phase<Matrix_float, float>(
output, sin_gamma, cos_gamma);
214 if (param_idx == 3) {
215 cu_derivative_kernel_gamma_from_trig_to<Matrix_float, float>(
216 output, sin_theta, cos_theta, sin_phi, cos_phi, sin_lambda, cos_lambda, sin_gamma, cos_gamma
std::vector< Gate * > parents
list of parent gates to be applied in the circuit prior to this current gate
virtual void derivative_kernel_to(const Matrix_real &precomputed_sincos, int param_idx, Matrix &output) override
Copyright (C) Miklos Maroti, 2021 SPDX-License-Identifier: Apache-2.0.
static const double M_PIOver2
Class to store single-precision real arrays and properties.
virtual Matrix derivative_kernel(const Matrix_real &precomputed_sincos, int param_idx) 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.
virtual void gate_kernel_to(const Matrix_real &precomputed_sincos, Matrix &output) override
int target_qbit
The index of the qubit on which the operation acts (target_qbit >= 0)
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 Matrix inverse_gate_kernel(const Matrix_real &precomputed_sincos) 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 ...
virtual void inverse_gate_kernel_to(const Matrix_real &precomputed_sincos, Matrix &output) override
Double-precision complex matrix (float64).
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
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.
int qbit_num
number of qubits spanning the matrix of the operation
virtual CU * clone() override
Call to create a clone of the present class.
Class to store data of complex arrays and its properties.
virtual Matrix gate_kernel(const Matrix_real &precomputed_sincos) override
Compute the gate kernel matrix from precomputed trigonometric values.