|
10 | 10 | #pragma once
|
11 | 11 |
|
12 | 12 | #include "dd/DDDefinitions.hpp"
|
| 13 | +#include "ir/operations/OpType.hpp" |
13 | 14 |
|
14 |
| -#include <cmath> |
15 |
| -#include <complex> |
| 15 | +#include <vector> |
16 | 16 |
|
17 | 17 | namespace dd {
|
18 | 18 |
|
19 | 19 | // Gate matrices
|
20 |
| -constexpr GateMatrix I_MAT{1, 0, 0, 1}; |
21 |
| -constexpr GateMatrix H_MAT{SQRT2_2, SQRT2_2, SQRT2_2, -SQRT2_2}; |
22 |
| -constexpr GateMatrix X_MAT{0, 1, 1, 0}; |
23 |
| -constexpr GateMatrix Y_MAT{0, {0, -1}, {0, 1}, 0}; |
24 |
| -constexpr GateMatrix Z_MAT{1, 0, 0, -1}; |
25 |
| -constexpr GateMatrix S_MAT{1, 0, 0, {0, 1}}; |
26 |
| -constexpr GateMatrix SDG_MAT{1, 0, 0, {0, -1}}; |
27 |
| -constexpr GateMatrix T_MAT{1, 0, 0, {SQRT2_2, SQRT2_2}}; |
28 |
| -constexpr GateMatrix TDG_MAT{1, 0, 0, {SQRT2_2, -SQRT2_2}}; |
29 |
| -constexpr GateMatrix SX_MAT{ |
30 |
| - std::complex{0.5, 0.5}, {0.5, -0.5}, {0.5, -0.5}, {0.5, 0.5}}; |
31 |
| -constexpr GateMatrix SXDG_MAT{ |
32 |
| - std::complex{0.5, -0.5}, {0.5, 0.5}, {0.5, 0.5}, {0.5, -0.5}}; |
33 |
| -constexpr GateMatrix V_MAT{SQRT2_2, {0, -SQRT2_2}, {0, -SQRT2_2}, SQRT2_2}; |
34 |
| -constexpr GateMatrix VDG_MAT{SQRT2_2, {0, SQRT2_2}, {0, SQRT2_2}, SQRT2_2}; |
35 | 20 | constexpr GateMatrix MEAS_ZERO_MAT{1, 0, 0, 0};
|
36 | 21 | constexpr GateMatrix MEAS_ONE_MAT{0, 0, 0, 1};
|
37 | 22 |
|
38 |
| -inline GateMatrix uMat(const fp lambda, const fp phi, const fp theta) { |
39 |
| - return GateMatrix{{{std::cos(theta / 2.), 0.}, |
40 |
| - {-std::cos(lambda) * std::sin(theta / 2.), |
41 |
| - -std::sin(lambda) * std::sin(theta / 2.)}, |
42 |
| - {std::cos(phi) * std::sin(theta / 2.), |
43 |
| - std::sin(phi) * std::sin(theta / 2.)}, |
44 |
| - {std::cos(lambda + phi) * std::cos(theta / 2.), |
45 |
| - std::sin(lambda + phi) * std::cos(theta / 2.)}}}; |
46 |
| -} |
| 23 | +GateMatrix opToSingleQubitGateMatrix(qc::OpType t, |
| 24 | + const std::vector<fp>& params = {}); |
47 | 25 |
|
48 |
| -inline GateMatrix u2Mat(const fp lambda, const fp phi) { |
49 |
| - return GateMatrix{ |
50 |
| - SQRT2_2, |
51 |
| - {-std::cos(lambda) * SQRT2_2, -std::sin(lambda) * SQRT2_2}, |
52 |
| - {std::cos(phi) * SQRT2_2, std::sin(phi) * SQRT2_2}, |
53 |
| - {std::cos(lambda + phi) * SQRT2_2, std::sin(lambda + phi) * SQRT2_2}}; |
54 |
| -} |
| 26 | +TwoQubitGateMatrix opToTwoQubitGateMatrix(qc::OpType t, |
| 27 | + const std::vector<fp>& params = {}); |
55 | 28 |
|
56 |
| -inline GateMatrix pMat(const fp lambda) { |
57 |
| - return GateMatrix{1, 0, 0, {std::cos(lambda), std::sin(lambda)}}; |
58 |
| -} |
59 |
| - |
60 |
| -inline GateMatrix rxMat(const fp lambda) { |
61 |
| - return GateMatrix{{{std::cos(lambda / 2.), 0.}, |
62 |
| - {0., -std::sin(lambda / 2.)}, |
63 |
| - {0., -std::sin(lambda / 2.)}, |
64 |
| - {std::cos(lambda / 2.), 0.}}}; |
65 |
| -} |
66 |
| - |
67 |
| -inline GateMatrix ryMat(const fp lambda) { |
68 |
| - return GateMatrix{{{std::cos(lambda / 2.), 0.}, |
69 |
| - {-std::sin(lambda / 2.), 0.}, |
70 |
| - {std::sin(lambda / 2.), 0.}, |
71 |
| - {std::cos(lambda / 2.), 0.}}}; |
72 |
| -} |
73 |
| - |
74 |
| -inline GateMatrix rzMat(const fp lambda) { |
75 |
| - return GateMatrix{{{std::cos(lambda / 2.), -std::sin(lambda / 2.)}, |
76 |
| - 0, |
77 |
| - 0, |
78 |
| - {std::cos(lambda / 2.), std::sin(lambda / 2.)}}}; |
79 |
| -} |
80 |
| - |
81 |
| -constexpr TwoQubitGateMatrix CX_MAT{ |
82 |
| - {{1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 0, 1}, {0, 0, 1, 0}}}; |
83 |
| - |
84 |
| -constexpr TwoQubitGateMatrix CZ_MAT{ |
85 |
| - {{1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, -1}}}; |
86 |
| - |
87 |
| -constexpr TwoQubitGateMatrix SWAP_MAT{ |
88 |
| - {{1, 0, 0, 0}, {0, 0, 1, 0}, {0, 1, 0, 0}, {0, 0, 0, 1}}}; |
89 |
| - |
90 |
| -constexpr TwoQubitGateMatrix ISWAP_MAT{ |
91 |
| - {{1, 0, 0, 0}, {0, 0, {0, 1}, 0}, {0, {0, 1}, 0, 0}, {0, 0, 0, 1}}}; |
92 |
| - |
93 |
| -constexpr TwoQubitGateMatrix ISWAPDG_MAT{ |
94 |
| - {{1, 0, 0, 0}, {0, 0, {0, -1}, 0}, {0, {0, -1}, 0, 0}, {0, 0, 0, 1}}}; |
95 |
| - |
96 |
| -constexpr TwoQubitGateMatrix ECR_MAT{ |
97 |
| - {{0, 0, SQRT2_2, {0, SQRT2_2}}, |
98 |
| - {0, 0, {0, SQRT2_2}, SQRT2_2}, |
99 |
| - {SQRT2_2, {0, -SQRT2_2}, 0, 0}, |
100 |
| - {std::complex{0., -SQRT2_2}, SQRT2_2, 0, 0}}}; |
101 |
| - |
102 |
| -constexpr TwoQubitGateMatrix DCX_MAT{ |
103 |
| - {{1, 0, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}, {0, 1, 0, 0}}}; |
104 |
| - |
105 |
| -constexpr TwoQubitGateMatrix PERES_MAT{ |
106 |
| - {{0, 0, 0, 1}, {0, 0, 1, 0}, {1, 0, 0, 0}, {0, 1, 0, 0}}}; |
107 |
| - |
108 |
| -constexpr TwoQubitGateMatrix PERESDG_MAT{ |
109 |
| - {{0, 0, 1, 0}, {0, 0, 0, 1}, {0, 1, 0, 0}, {1, 0, 0, 0}}}; |
110 |
| - |
111 |
| -inline TwoQubitGateMatrix rxxMat(const fp theta) { |
112 |
| - const auto cosTheta = std::cos(theta / 2.); |
113 |
| - const auto sinTheta = std::sin(theta / 2.); |
114 |
| - |
115 |
| - return TwoQubitGateMatrix{{{cosTheta, 0, 0, {0., -sinTheta}}, |
116 |
| - {0, cosTheta, {0., -sinTheta}, 0}, |
117 |
| - {0, {0., -sinTheta}, cosTheta, 0}, |
118 |
| - {std::complex{0., -sinTheta}, 0, 0, cosTheta}}}; |
119 |
| -} |
120 |
| - |
121 |
| -inline TwoQubitGateMatrix ryyMat(const fp theta) { |
122 |
| - const auto cosTheta = std::cos(theta / 2.); |
123 |
| - const auto sinTheta = std::sin(theta / 2.); |
124 |
| - |
125 |
| - return TwoQubitGateMatrix{{{cosTheta, 0, 0, {0., sinTheta}}, |
126 |
| - {0, cosTheta, {0., -sinTheta}, 0}, |
127 |
| - {0, {0., -sinTheta}, cosTheta, 0}, |
128 |
| - {std::complex{0., sinTheta}, 0, 0, cosTheta}}}; |
129 |
| -} |
130 |
| - |
131 |
| -inline TwoQubitGateMatrix rzzMat(const fp theta) { |
132 |
| - const auto cosTheta = std::cos(theta / 2.); |
133 |
| - const auto sinTheta = std::sin(theta / 2.); |
134 |
| - |
135 |
| - return TwoQubitGateMatrix{{{std::complex{cosTheta, -sinTheta}, 0, 0, 0}, |
136 |
| - {0, {cosTheta, sinTheta}, 0, 0}, |
137 |
| - {0, 0, {cosTheta, sinTheta}, 0}, |
138 |
| - {0, 0, 0, {cosTheta, -sinTheta}}}}; |
139 |
| -} |
140 |
| - |
141 |
| -inline TwoQubitGateMatrix rzxMat(const fp theta) { |
142 |
| - const auto cosTheta = std::cos(theta / 2.); |
143 |
| - const auto sinTheta = std::sin(theta / 2.); |
144 |
| - |
145 |
| - return TwoQubitGateMatrix{{{cosTheta, {0., -sinTheta}, 0, 0}, |
146 |
| - {std::complex{0., -sinTheta}, cosTheta, 0, 0}, |
147 |
| - {0, 0, cosTheta, {0., sinTheta}}, |
148 |
| - {0, 0, {0., sinTheta}, cosTheta}}}; |
149 |
| -} |
150 |
| - |
151 |
| -inline TwoQubitGateMatrix xxMinusYYMat(const fp theta, const fp beta = 0.) { |
152 |
| - const auto cosTheta = std::cos(theta / 2.); |
153 |
| - const auto sinTheta = std::sin(theta / 2.); |
154 |
| - const auto cosBeta = std::cos(beta); |
155 |
| - const auto sinBeta = std::sin(beta); |
156 |
| - |
157 |
| - return TwoQubitGateMatrix{ |
158 |
| - {{cosTheta, 0, 0, {-sinBeta * sinTheta, -cosBeta * sinTheta}}, |
159 |
| - {0, 1, 0, 0}, |
160 |
| - {0, 0, 1, 0}, |
161 |
| - {std::complex{sinBeta * sinTheta, -cosBeta * sinTheta}, 0, 0, |
162 |
| - cosTheta}}}; |
163 |
| -} |
164 |
| - |
165 |
| -inline TwoQubitGateMatrix xxPlusYYMat(const fp theta, const fp beta = 0.) { |
166 |
| - const auto cosTheta = std::cos(theta / 2.); |
167 |
| - const auto sinTheta = std::sin(theta / 2.); |
168 |
| - const auto cosBeta = std::cos(beta); |
169 |
| - const auto sinBeta = std::sin(beta); |
170 |
| - |
171 |
| - return TwoQubitGateMatrix{ |
172 |
| - {{1, 0, 0, 0}, |
173 |
| - {0, cosTheta, {sinBeta * sinTheta, -cosBeta * sinTheta}, 0}, |
174 |
| - {0, {-sinBeta * sinTheta, -cosBeta * sinTheta}, cosTheta, 0}, |
175 |
| - {0, 0, 0, 1}}}; |
176 |
| -} |
177 | 29 | } // namespace dd
|
0 commit comments