Sequential Quantum Gate Decomposer  v1.9.6
Powerful decomposition of general unitarias into one- and two-qubit gates gates
U1.cpp
Go to the documentation of this file.
2 #include "U1.h"
3 
4 U1::U1() : U1(-1, -1) {}
5 
6 U1::U1(int qbit_num_in, int target_qbit_in) : U3(qbit_num_in, target_qbit_in) {
7  name = "U1";
9  parameter_num = 1;
10  control_qbit = -1;
11 }
12 
13 U1::~U1() {}
14 
16  U1* ret = new U1(qbit_num, target_qbit);
18  ret->set_parents(parents);
19  ret->set_children(children);
20  return ret;
21 }
22 
23 std::vector<double> U1::get_parameter_multipliers() const {
24  return {1.0};
25 }
26 
27 Matrix U1::gate_kernel(const Matrix_real& precomputed_sincos) {
28  const int lambda_offset = 0 * precomputed_sincos.stride;
29  const double s_lambda = precomputed_sincos[lambda_offset + 0];
30  const double c_lambda = precomputed_sincos[lambda_offset + 1];
31  return u1_gate_kernel_from_trig<Matrix, double>(s_lambda, c_lambda);
32 }
33 
34 Matrix_float U1::gate_kernel(const Matrix_real_float& precomputed_sincos) {
35  const int lambda_offset = 0 * precomputed_sincos.stride;
36  const float s_lambda = precomputed_sincos[lambda_offset + 0];
37  const float c_lambda = precomputed_sincos[lambda_offset + 1];
38  return u1_gate_kernel_from_trig<Matrix_float, float>(s_lambda, c_lambda);
39 }
40 
41 Matrix U1::inverse_gate_kernel(const Matrix_real& precomputed_sincos) {
42  const int lambda_offset = 0 * precomputed_sincos.stride;
43  const double s_lambda = precomputed_sincos[lambda_offset + 0];
44  const double c_lambda = precomputed_sincos[lambda_offset + 1];
45  return u1_inverse_gate_kernel_from_trig<Matrix, double>(s_lambda, c_lambda);
46 }
47 
49  const int lambda_offset = 0 * precomputed_sincos.stride;
50  const float s_lambda = precomputed_sincos[lambda_offset + 0];
51  const float c_lambda = precomputed_sincos[lambda_offset + 1];
52  return u1_inverse_gate_kernel_from_trig<Matrix_float, float>(s_lambda, c_lambda);
53 }
54 
55 Matrix U1::derivative_kernel(const Matrix_real& precomputed_sincos, int param_idx) {
56  if (param_idx != 0) {
57  return Matrix();
58  }
59  const int lambda_offset = 0 * precomputed_sincos.stride;
60  const double s_lambda = precomputed_sincos[lambda_offset + 0];
61  const double c_lambda = precomputed_sincos[lambda_offset + 1];
62  return u1_derivative_kernel_from_trig<Matrix, double>(s_lambda, c_lambda);
63 }
64 
65 Matrix_float U1::derivative_kernel(const Matrix_real_float& precomputed_sincos, int param_idx) {
66  if (param_idx != 0) {
67  return Matrix_float();
68  }
69  const int lambda_offset = 0 * precomputed_sincos.stride;
70  const float s_lambda = precomputed_sincos[lambda_offset + 0];
71  const float c_lambda = precomputed_sincos[lambda_offset + 1];
72  return u1_derivative_kernel_from_trig<Matrix_float, float>(s_lambda, c_lambda);
73 }
74 
75 void U1::gate_kernel_to(const Matrix_real& precomputed_sincos, Matrix& output) {
76  u1_gate_kernel_from_trig_to<Matrix, double>(output, precomputed_sincos[0], precomputed_sincos[1]);
77 }
78 
79 void U1::gate_kernel_to(const Matrix_real_float& precomputed_sincos, Matrix_float& output) {
80  u1_gate_kernel_from_trig_to<Matrix_float, float>(output, precomputed_sincos[0], precomputed_sincos[1]);
81 }
82 
83 void U1::inverse_gate_kernel_to(const Matrix_real& precomputed_sincos, Matrix& output) {
84  u1_inverse_gate_kernel_from_trig_to<Matrix, double>(output, precomputed_sincos[0], precomputed_sincos[1]);
85 }
86 
88  u1_inverse_gate_kernel_from_trig_to<Matrix_float, float>(output, precomputed_sincos[0], precomputed_sincos[1]);
89 }
90 
91 void U1::derivative_kernel_to(const Matrix_real& precomputed_sincos, int param_idx, Matrix& output) {
92  if (param_idx != 0) {
93  output = Matrix();
94  return;
95  }
96  u1_derivative_kernel_from_trig_to<Matrix, double>(output, precomputed_sincos[0], precomputed_sincos[1]);
97 }
98 
99 void U1::derivative_kernel_to(const Matrix_real_float& precomputed_sincos, int param_idx, Matrix_float& output) {
100  if (param_idx != 0) {
101  output = Matrix_float();
102  return;
103  }
104  u1_derivative_kernel_from_trig_to<Matrix_float, float>(output, precomputed_sincos[0], precomputed_sincos[1]);
105 }
std::vector< Gate * > parents
list of parent gates to be applied in the circuit prior to this current gate
Definition: Gate.h:112
Copyright (C) Miklos Maroti, 2021 SPDX-License-Identifier: Apache-2.0.
Definition: U3.h:19
virtual Matrix derivative_kernel(const Matrix_real &precomputed_sincos, int param_idx) override
Definition: U1.cpp:55
Class to store single-precision real arrays and properties.
virtual Matrix gate_kernel(const Matrix_real &precomputed_sincos) override
Compute the gate kernel matrix from precomputed trigonometric values.
Definition: U1.cpp:27
int control_qbit
The index of the qubit which acts as a control qubit (control_qbit >= 0) in controlled operations...
Definition: Gate.h:100
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)
Definition: matrix_base.hpp:46
void set_children(std::vector< Gate *> &children_)
Call to set the children of the current gate.
Definition: Gate.cpp:2523
virtual Matrix inverse_gate_kernel(const Matrix_real &precomputed_sincos) override
Definition: U1.cpp:41
int target_qbit
The index of the qubit on which the operation acts (target_qbit >= 0)
Definition: Gate.h:98
Definition: U1.h:11
virtual void gate_kernel_to(const Matrix_real &precomputed_sincos, Matrix &output) override
Definition: U1.cpp:75
virtual std::vector< double > get_parameter_multipliers() const override
Returns the per-parameter multipliers relative to 2π used by extract_parameters. ...
Definition: U1.cpp:23
gate_type type
The type of the operation (see enumeration gate_type)
Definition: Gate.h:96
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 ...
Definition: Gate.cpp:2500
int get_parameter_start_idx()
Call to get the starting index of the parameters in the parameter array corresponding to the circuit ...
Definition: Gate.cpp:2535
virtual void inverse_gate_kernel_to(const Matrix_real &precomputed_sincos, Matrix &output) override
Definition: U1.cpp:83
Double-precision complex matrix (float64).
Definition: matrix.h:38
std::string name
A string labeling the gate operation.
Definition: Gate.h:92
Single-precision complex matrix (float32).
Definition: matrix_float.h:41
virtual void derivative_kernel_to(const Matrix_real &precomputed_sincos, int param_idx, Matrix &output) override
Definition: U1.cpp:91
std::vector< Gate * > children
list of child gates to be applied after this current gate
Definition: Gate.h:114
virtual U1 * clone() override
Call to create a clone of the present class.
Definition: U1.cpp:15
int parameter_num
the number of free parameters of the operation
Definition: Gate.h:108
~U1() override
Definition: U1.cpp:13
void set_parents(std::vector< Gate *> &parents_)
Call to set the parents of the current gate.
Definition: Gate.cpp:2511
int qbit_num
number of qubits spanning the matrix of the operation
Definition: Gate.h:94
U1()
Definition: U1.cpp:4
Class to store data of complex arrays and its properties.
Definition: matrix_real.h:41