bloqade-circuit 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of bloqade-circuit might be problematic. Click here for more details.
- bloqade/analysis/__init__.py +0 -0
- bloqade/analysis/address/__init__.py +11 -0
- bloqade/analysis/address/analysis.py +60 -0
- bloqade/analysis/address/impls.py +228 -0
- bloqade/analysis/address/lattice.py +85 -0
- bloqade/noise/__init__.py +1 -0
- bloqade/noise/native/__init__.py +20 -0
- bloqade/noise/native/_dialect.py +3 -0
- bloqade/noise/native/_wrappers.py +34 -0
- bloqade/noise/native/model.py +347 -0
- bloqade/noise/native/rewrite.py +35 -0
- bloqade/noise/native/stmts.py +46 -0
- bloqade/pyqrack/__init__.py +18 -0
- bloqade/pyqrack/base.py +131 -0
- bloqade/pyqrack/noise/__init__.py +0 -0
- bloqade/pyqrack/noise/native.py +100 -0
- bloqade/pyqrack/qasm2/__init__.py +0 -0
- bloqade/pyqrack/qasm2/core.py +79 -0
- bloqade/pyqrack/qasm2/parallel.py +46 -0
- bloqade/pyqrack/qasm2/uop.py +247 -0
- bloqade/pyqrack/reg.py +109 -0
- bloqade/pyqrack/target.py +112 -0
- bloqade/qasm2/__init__.py +19 -0
- bloqade/qasm2/_wrappers.py +674 -0
- bloqade/qasm2/dialects/__init__.py +10 -0
- bloqade/qasm2/dialects/core/__init__.py +3 -0
- bloqade/qasm2/dialects/core/_dialect.py +3 -0
- bloqade/qasm2/dialects/core/_emit.py +68 -0
- bloqade/qasm2/dialects/core/_typeinfer.py +23 -0
- bloqade/qasm2/dialects/core/address.py +38 -0
- bloqade/qasm2/dialects/core/stmts.py +94 -0
- bloqade/qasm2/dialects/expr/__init__.py +3 -0
- bloqade/qasm2/dialects/expr/_dialect.py +3 -0
- bloqade/qasm2/dialects/expr/_emit.py +103 -0
- bloqade/qasm2/dialects/expr/_from_python.py +86 -0
- bloqade/qasm2/dialects/expr/_interp.py +75 -0
- bloqade/qasm2/dialects/expr/stmts.py +262 -0
- bloqade/qasm2/dialects/glob.py +45 -0
- bloqade/qasm2/dialects/indexing.py +64 -0
- bloqade/qasm2/dialects/inline.py +76 -0
- bloqade/qasm2/dialects/noise.py +16 -0
- bloqade/qasm2/dialects/parallel.py +110 -0
- bloqade/qasm2/dialects/uop/__init__.py +4 -0
- bloqade/qasm2/dialects/uop/_dialect.py +3 -0
- bloqade/qasm2/dialects/uop/_emit.py +211 -0
- bloqade/qasm2/dialects/uop/schedule.py +89 -0
- bloqade/qasm2/dialects/uop/stmts.py +325 -0
- bloqade/qasm2/emit/__init__.py +1 -0
- bloqade/qasm2/emit/base.py +72 -0
- bloqade/qasm2/emit/gate.py +102 -0
- bloqade/qasm2/emit/main.py +106 -0
- bloqade/qasm2/emit/target.py +165 -0
- bloqade/qasm2/glob.py +24 -0
- bloqade/qasm2/groups.py +120 -0
- bloqade/qasm2/parallel.py +48 -0
- bloqade/qasm2/parse/__init__.py +37 -0
- bloqade/qasm2/parse/ast.py +235 -0
- bloqade/qasm2/parse/build.py +289 -0
- bloqade/qasm2/parse/lowering.py +553 -0
- bloqade/qasm2/parse/parser.py +5 -0
- bloqade/qasm2/parse/print.py +293 -0
- bloqade/qasm2/parse/qasm2.lark +75 -0
- bloqade/qasm2/parse/visitor.py +16 -0
- bloqade/qasm2/parse/visitor.pyi +39 -0
- bloqade/qasm2/passes/__init__.py +5 -0
- bloqade/qasm2/passes/fold.py +94 -0
- bloqade/qasm2/passes/glob.py +119 -0
- bloqade/qasm2/passes/noise.py +61 -0
- bloqade/qasm2/passes/parallel.py +176 -0
- bloqade/qasm2/passes/py2qasm.py +63 -0
- bloqade/qasm2/passes/qasm2py.py +61 -0
- bloqade/qasm2/rewrite/__init__.py +12 -0
- bloqade/qasm2/rewrite/desugar.py +28 -0
- bloqade/qasm2/rewrite/glob.py +103 -0
- bloqade/qasm2/rewrite/heuristic_noise.py +247 -0
- bloqade/qasm2/rewrite/native_gates.py +447 -0
- bloqade/qasm2/rewrite/parallel_to_uop.py +83 -0
- bloqade/qasm2/rewrite/register.py +45 -0
- bloqade/qasm2/rewrite/uop_to_parallel.py +395 -0
- bloqade/qasm2/types.py +39 -0
- bloqade/qbraid/__init__.py +2 -0
- bloqade/qbraid/lowering.py +324 -0
- bloqade/qbraid/schema.py +252 -0
- bloqade/qbraid/simulation_result.py +99 -0
- bloqade/qbraid/target.py +86 -0
- bloqade/squin/__init__.py +2 -0
- bloqade/squin/analysis/__init__.py +0 -0
- bloqade/squin/analysis/nsites/__init__.py +8 -0
- bloqade/squin/analysis/nsites/analysis.py +52 -0
- bloqade/squin/analysis/nsites/impls.py +69 -0
- bloqade/squin/analysis/nsites/lattice.py +49 -0
- bloqade/squin/analysis/schedule.py +244 -0
- bloqade/squin/groups.py +38 -0
- bloqade/squin/op/__init__.py +132 -0
- bloqade/squin/op/_dialect.py +3 -0
- bloqade/squin/op/complex.py +6 -0
- bloqade/squin/op/stmts.py +220 -0
- bloqade/squin/op/traits.py +43 -0
- bloqade/squin/op/types.py +10 -0
- bloqade/squin/qubit.py +118 -0
- bloqade/squin/wire.py +103 -0
- bloqade/stim/__init__.py +6 -0
- bloqade/stim/_wrappers.py +186 -0
- bloqade/stim/dialects/__init__.py +5 -0
- bloqade/stim/dialects/aux/__init__.py +11 -0
- bloqade/stim/dialects/aux/_dialect.py +3 -0
- bloqade/stim/dialects/aux/emit.py +102 -0
- bloqade/stim/dialects/aux/interp.py +39 -0
- bloqade/stim/dialects/aux/lowering.py +40 -0
- bloqade/stim/dialects/aux/stmts/__init__.py +14 -0
- bloqade/stim/dialects/aux/stmts/annotate.py +47 -0
- bloqade/stim/dialects/aux/stmts/const.py +95 -0
- bloqade/stim/dialects/aux/types.py +19 -0
- bloqade/stim/dialects/collapse/__init__.py +3 -0
- bloqade/stim/dialects/collapse/_dialect.py +3 -0
- bloqade/stim/dialects/collapse/emit.py +68 -0
- bloqade/stim/dialects/collapse/stmts/__init__.py +3 -0
- bloqade/stim/dialects/collapse/stmts/measure.py +45 -0
- bloqade/stim/dialects/collapse/stmts/pp_measure.py +14 -0
- bloqade/stim/dialects/collapse/stmts/reset.py +26 -0
- bloqade/stim/dialects/gate/__init__.py +3 -0
- bloqade/stim/dialects/gate/_dialect.py +3 -0
- bloqade/stim/dialects/gate/emit.py +87 -0
- bloqade/stim/dialects/gate/stmts/__init__.py +14 -0
- bloqade/stim/dialects/gate/stmts/base.py +31 -0
- bloqade/stim/dialects/gate/stmts/clifford_1q.py +53 -0
- bloqade/stim/dialects/gate/stmts/clifford_2q.py +11 -0
- bloqade/stim/dialects/gate/stmts/control_2q.py +21 -0
- bloqade/stim/dialects/gate/stmts/pp.py +15 -0
- bloqade/stim/dialects/noise/__init__.py +3 -0
- bloqade/stim/dialects/noise/_dialect.py +3 -0
- bloqade/stim/dialects/noise/emit.py +66 -0
- bloqade/stim/dialects/noise/stmts.py +77 -0
- bloqade/stim/emit/__init__.py +1 -0
- bloqade/stim/emit/stim.py +54 -0
- bloqade/stim/groups.py +26 -0
- bloqade/test_utils.py +35 -0
- bloqade/types.py +24 -0
- bloqade/visual/__init__.py +1 -0
- bloqade/visual/animation/__init__.py +0 -0
- bloqade/visual/animation/animate.py +267 -0
- bloqade/visual/animation/base.py +346 -0
- bloqade/visual/animation/gate_event.py +24 -0
- bloqade/visual/animation/runtime/__init__.py +0 -0
- bloqade/visual/animation/runtime/aod.py +36 -0
- bloqade/visual/animation/runtime/atoms.py +55 -0
- bloqade/visual/animation/runtime/ppoly.py +50 -0
- bloqade/visual/animation/runtime/qpustate.py +119 -0
- bloqade/visual/animation/runtime/utils.py +43 -0
- bloqade_circuit-0.1.0.dist-info/METADATA +70 -0
- bloqade_circuit-0.1.0.dist-info/RECORD +153 -0
- bloqade_circuit-0.1.0.dist-info/WHEEL +4 -0
- bloqade_circuit-0.1.0.dist-info/licenses/LICENSE +234 -0
|
@@ -0,0 +1,674 @@
|
|
|
1
|
+
from kirin.lowering import wraps
|
|
2
|
+
|
|
3
|
+
from .types import Bit, CReg, QReg, Qubit
|
|
4
|
+
from .dialects import uop, core, expr, inline as inline_
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@wraps(inline_.InlineQASM)
|
|
8
|
+
def inline(text: str) -> None:
|
|
9
|
+
"""
|
|
10
|
+
Inline QASM code into the current program.
|
|
11
|
+
|
|
12
|
+
Args:
|
|
13
|
+
text: The QASM code to inline.
|
|
14
|
+
"""
|
|
15
|
+
...
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@wraps(core.QRegNew)
|
|
19
|
+
def qreg(n_qubits: int) -> QReg:
|
|
20
|
+
"""
|
|
21
|
+
Create a new quantum register with `n_qubits` qubits.
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
n_qubits: The number of qubits in the register.
|
|
25
|
+
|
|
26
|
+
Returns:
|
|
27
|
+
The newly created quantum register.
|
|
28
|
+
|
|
29
|
+
"""
|
|
30
|
+
...
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@wraps(core.CRegNew)
|
|
34
|
+
def creg(n_bits: int) -> CReg:
|
|
35
|
+
"""
|
|
36
|
+
Create a new classical register with `n_bits` bits.
|
|
37
|
+
|
|
38
|
+
Args:
|
|
39
|
+
n_bits: The number of bits in the register.
|
|
40
|
+
|
|
41
|
+
Returns:
|
|
42
|
+
The newly created classical register.
|
|
43
|
+
|
|
44
|
+
"""
|
|
45
|
+
...
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
@wraps(core.Reset)
|
|
49
|
+
def reset(qarg: Qubit) -> None:
|
|
50
|
+
"""
|
|
51
|
+
Reset the qubit `qarg` to the |0⟩ state.
|
|
52
|
+
|
|
53
|
+
Args:
|
|
54
|
+
qarg: The qubit to reset.
|
|
55
|
+
|
|
56
|
+
"""
|
|
57
|
+
|
|
58
|
+
...
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
@wraps(core.Measure)
|
|
62
|
+
def measure(qarg: Qubit, cbit: Bit) -> None:
|
|
63
|
+
"""
|
|
64
|
+
Measure the qubit `qarg` and store the result in the classical bit `cbit`.
|
|
65
|
+
|
|
66
|
+
Args:
|
|
67
|
+
qarg: The qubit to measure.
|
|
68
|
+
cbit: The classical bit to store the result in.
|
|
69
|
+
"""
|
|
70
|
+
...
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
@wraps(uop.CX)
|
|
74
|
+
def cx(ctrl: Qubit, qarg: Qubit) -> None:
|
|
75
|
+
"""
|
|
76
|
+
Controlled-X (CNOT) gate.
|
|
77
|
+
|
|
78
|
+
Args:
|
|
79
|
+
ctrl: The control qubit.
|
|
80
|
+
qarg: The target qubit.
|
|
81
|
+
"""
|
|
82
|
+
...
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
@wraps(uop.UGate)
|
|
86
|
+
def u(qarg: Qubit, theta: float, phi: float, lam: float) -> None:
|
|
87
|
+
"""
|
|
88
|
+
U gate.
|
|
89
|
+
|
|
90
|
+
Note:
|
|
91
|
+
See https://arxiv.org/pdf/1707.03429 for definition of angles.
|
|
92
|
+
|
|
93
|
+
Args:
|
|
94
|
+
qarg: The qubit to apply the gate to.
|
|
95
|
+
theta: The angle of rotation
|
|
96
|
+
phi: The angle of rotation
|
|
97
|
+
lam: The angle of rotation
|
|
98
|
+
|
|
99
|
+
"""
|
|
100
|
+
...
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
@wraps(uop.UGate)
|
|
104
|
+
def u3(qarg: Qubit, theta: float, phi: float, lam: float) -> None:
|
|
105
|
+
"""
|
|
106
|
+
U3 gate, same as u
|
|
107
|
+
|
|
108
|
+
Note:
|
|
109
|
+
See https://arxiv.org/pdf/1707.03429 for definition of angles.
|
|
110
|
+
|
|
111
|
+
Args:
|
|
112
|
+
qarg: The qubit to apply the gate to.
|
|
113
|
+
theta: The angle of rotation
|
|
114
|
+
phi: The angle of rotation
|
|
115
|
+
lam: The angle of rotation
|
|
116
|
+
|
|
117
|
+
"""
|
|
118
|
+
...
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
@wraps(uop.Barrier)
|
|
122
|
+
def barrier(qargs: tuple[Qubit, ...]) -> None:
|
|
123
|
+
"""
|
|
124
|
+
Barrier instruction.
|
|
125
|
+
|
|
126
|
+
Args:
|
|
127
|
+
qargs: The qubits to apply the barrier to.
|
|
128
|
+
"""
|
|
129
|
+
|
|
130
|
+
...
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
@wraps(uop.Id)
|
|
134
|
+
def id(qarg: Qubit) -> None:
|
|
135
|
+
"""
|
|
136
|
+
Identity gate.
|
|
137
|
+
|
|
138
|
+
Args:
|
|
139
|
+
qarg: The qubit to apply the gate to.
|
|
140
|
+
|
|
141
|
+
"""
|
|
142
|
+
...
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
@wraps(uop.H)
|
|
146
|
+
def h(qarg: Qubit) -> None:
|
|
147
|
+
"""
|
|
148
|
+
Hadamard gate.
|
|
149
|
+
|
|
150
|
+
Args:
|
|
151
|
+
qarg: The qubit to apply the gate to.
|
|
152
|
+
|
|
153
|
+
"""
|
|
154
|
+
...
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
@wraps(uop.X)
|
|
158
|
+
def x(qarg: Qubit) -> None:
|
|
159
|
+
"""
|
|
160
|
+
Pauli-X gate.
|
|
161
|
+
|
|
162
|
+
Args:
|
|
163
|
+
qarg: The qubit to apply the gate to.
|
|
164
|
+
"""
|
|
165
|
+
|
|
166
|
+
...
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
@wraps(uop.Y)
|
|
170
|
+
def y(qarg: Qubit) -> None:
|
|
171
|
+
"""
|
|
172
|
+
Pauli-Y gate.
|
|
173
|
+
|
|
174
|
+
Args:
|
|
175
|
+
qarg: The qubit to apply the gate to.
|
|
176
|
+
|
|
177
|
+
"""
|
|
178
|
+
...
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
@wraps(uop.Z)
|
|
182
|
+
def z(qarg: Qubit) -> None:
|
|
183
|
+
"""
|
|
184
|
+
Pauli-Z gate.
|
|
185
|
+
|
|
186
|
+
Args:
|
|
187
|
+
qarg: The qubit to apply the gate to.
|
|
188
|
+
|
|
189
|
+
"""
|
|
190
|
+
...
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
@wraps(uop.U1)
|
|
194
|
+
def p(qarg: Qubit, lam: float) -> None:
|
|
195
|
+
"""
|
|
196
|
+
Phase gate.
|
|
197
|
+
|
|
198
|
+
This is equivalent to u(0,0,lam), and u1(lam)
|
|
199
|
+
|
|
200
|
+
Args:
|
|
201
|
+
qarg: The qubit to apply the gate to.
|
|
202
|
+
lam: The angle of phase.
|
|
203
|
+
|
|
204
|
+
"""
|
|
205
|
+
...
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
@wraps(uop.S)
|
|
209
|
+
def s(qarg: Qubit) -> None:
|
|
210
|
+
"""
|
|
211
|
+
S gate.
|
|
212
|
+
|
|
213
|
+
Args:
|
|
214
|
+
qarg: The qubit to apply the gate to.
|
|
215
|
+
"""
|
|
216
|
+
|
|
217
|
+
...
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
@wraps(uop.Sdag)
|
|
221
|
+
def sdg(qarg: Qubit) -> None:
|
|
222
|
+
"""
|
|
223
|
+
Hermitian conjugate of the S gate.
|
|
224
|
+
|
|
225
|
+
Args:
|
|
226
|
+
qarg: The qubit to apply the gate to.
|
|
227
|
+
|
|
228
|
+
"""
|
|
229
|
+
|
|
230
|
+
...
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
@wraps(uop.SX)
|
|
234
|
+
def sx(qarg: Qubit) -> None:
|
|
235
|
+
"""
|
|
236
|
+
Sqrt(X) gate.
|
|
237
|
+
|
|
238
|
+
Args:
|
|
239
|
+
qarg: The qubit to apply the gate to.
|
|
240
|
+
"""
|
|
241
|
+
|
|
242
|
+
...
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
@wraps(uop.SXdag)
|
|
246
|
+
def sxdg(qarg: Qubit) -> None:
|
|
247
|
+
"""
|
|
248
|
+
Hermitian conjugate of Sqrt(X) gate.
|
|
249
|
+
|
|
250
|
+
Args:
|
|
251
|
+
qarg: The qubit to apply the gate to.
|
|
252
|
+
"""
|
|
253
|
+
|
|
254
|
+
...
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
@wraps(uop.T)
|
|
258
|
+
def t(qarg: Qubit) -> None:
|
|
259
|
+
"""
|
|
260
|
+
T gate.
|
|
261
|
+
|
|
262
|
+
Args:
|
|
263
|
+
qarg: The qubit to apply the gate to.
|
|
264
|
+
"""
|
|
265
|
+
|
|
266
|
+
...
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
@wraps(uop.Tdag)
|
|
270
|
+
def tdg(qarg: Qubit) -> None:
|
|
271
|
+
"""
|
|
272
|
+
Hermitian conjugate of the T gate.
|
|
273
|
+
|
|
274
|
+
Args:
|
|
275
|
+
qarg: The qubit to apply the gate to.
|
|
276
|
+
|
|
277
|
+
"""
|
|
278
|
+
|
|
279
|
+
...
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
@wraps(uop.RX)
|
|
283
|
+
def rx(qarg: Qubit, theta: float) -> None:
|
|
284
|
+
"""
|
|
285
|
+
Single qubit rotation about the X axis on block sphere
|
|
286
|
+
|
|
287
|
+
Args:
|
|
288
|
+
qarg: The qubit to apply the gate to.
|
|
289
|
+
theta: The angle of rotation.
|
|
290
|
+
"""
|
|
291
|
+
...
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
@wraps(uop.RY)
|
|
295
|
+
def ry(qarg: Qubit, theta: float) -> None:
|
|
296
|
+
"""
|
|
297
|
+
Single qubit rotation about the Y axis on block sphere
|
|
298
|
+
|
|
299
|
+
Args:
|
|
300
|
+
qarg: The qubit to apply the gate to.
|
|
301
|
+
theta: The angle of rotation.
|
|
302
|
+
|
|
303
|
+
"""
|
|
304
|
+
|
|
305
|
+
...
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
@wraps(uop.RZ)
|
|
309
|
+
def rz(qarg: Qubit, theta: float) -> None:
|
|
310
|
+
"""
|
|
311
|
+
Single qubit rotation about the Z axis on block sphere
|
|
312
|
+
|
|
313
|
+
Args:
|
|
314
|
+
qarg: The qubit to apply the gate to.
|
|
315
|
+
theta: The angle of rotation.
|
|
316
|
+
"""
|
|
317
|
+
...
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
@wraps(uop.U1)
|
|
321
|
+
def u1(qarg: Qubit, lam: float) -> None:
|
|
322
|
+
"""
|
|
323
|
+
1 Parameter single qubit unitary gate.
|
|
324
|
+
|
|
325
|
+
This is equivalent to u(0,0,lambda).
|
|
326
|
+
|
|
327
|
+
Args:
|
|
328
|
+
qarg: The qubit to apply the gate to.
|
|
329
|
+
lam: The angle of rotation.
|
|
330
|
+
"""
|
|
331
|
+
...
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
@wraps(uop.U2)
|
|
335
|
+
def u2(qarg: Qubit, phi: float, lam: float) -> None:
|
|
336
|
+
"""
|
|
337
|
+
2 Parameter single qubit unitary gate.
|
|
338
|
+
|
|
339
|
+
This is equivalent to u(pi/2,phi,lambda)
|
|
340
|
+
|
|
341
|
+
Args:
|
|
342
|
+
qarg: The qubit to apply the gate to.
|
|
343
|
+
phi: The angle of rotation.
|
|
344
|
+
lam: The angle of rotation.
|
|
345
|
+
"""
|
|
346
|
+
...
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
@wraps(uop.CZ)
|
|
350
|
+
def cz(ctrl: Qubit, qarg: Qubit) -> None:
|
|
351
|
+
"""
|
|
352
|
+
Controlled-Z gate.
|
|
353
|
+
|
|
354
|
+
Args:
|
|
355
|
+
ctrl: The control qubit.
|
|
356
|
+
qarg: The target qubit
|
|
357
|
+
"""
|
|
358
|
+
...
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
@wraps(uop.CSX)
|
|
362
|
+
def csx(ctrl: Qubit, qarg: Qubit) -> None:
|
|
363
|
+
"""
|
|
364
|
+
Controlled-Sqrt(X) gate.
|
|
365
|
+
|
|
366
|
+
Args:
|
|
367
|
+
ctrl: The control qubit.
|
|
368
|
+
qarg: The target qubit
|
|
369
|
+
"""
|
|
370
|
+
...
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
@wraps(uop.CY)
|
|
374
|
+
def cy(ctrl: Qubit, qarg: Qubit) -> None:
|
|
375
|
+
"""
|
|
376
|
+
Controlled-Y gate.
|
|
377
|
+
|
|
378
|
+
Args:
|
|
379
|
+
ctrl: The control qubit.
|
|
380
|
+
qarg: The target qubit
|
|
381
|
+
"""
|
|
382
|
+
|
|
383
|
+
...
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
@wraps(uop.CH)
|
|
387
|
+
def ch(ctrl: Qubit, qarg: Qubit) -> None:
|
|
388
|
+
"""
|
|
389
|
+
Controlled-Hadamard gate.
|
|
390
|
+
|
|
391
|
+
Args:
|
|
392
|
+
ctrl: The control qubit.
|
|
393
|
+
qarg: The target qubit
|
|
394
|
+
|
|
395
|
+
"""
|
|
396
|
+
|
|
397
|
+
...
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
@wraps(uop.Swap)
|
|
401
|
+
def swap(ctrl: Qubit, qarg: Qubit) -> None:
|
|
402
|
+
"""
|
|
403
|
+
Swap gate.
|
|
404
|
+
|
|
405
|
+
Args:
|
|
406
|
+
ctrl: The first qubit.
|
|
407
|
+
qarg: The second qubit.
|
|
408
|
+
"""
|
|
409
|
+
...
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
@wraps(uop.CCX)
|
|
413
|
+
def ccx(ctrl1: Qubit, ctrl2: Qubit, qarg: Qubit) -> None:
|
|
414
|
+
"""
|
|
415
|
+
Toffoli gate.
|
|
416
|
+
|
|
417
|
+
Args:
|
|
418
|
+
ctrl1: The first control qubit.
|
|
419
|
+
ctrl2: The second control qubit.
|
|
420
|
+
qarg: The target qubit.
|
|
421
|
+
"""
|
|
422
|
+
...
|
|
423
|
+
|
|
424
|
+
|
|
425
|
+
@wraps(uop.CSwap)
|
|
426
|
+
def cswap(ctrl: Qubit, qarg1: Qubit, qarg2: Qubit) -> None:
|
|
427
|
+
"""
|
|
428
|
+
Controlled Swap gate (Fredkin gate).
|
|
429
|
+
|
|
430
|
+
Args:
|
|
431
|
+
ctrl: The control qubit.
|
|
432
|
+
qarg1: The first target qubit.
|
|
433
|
+
qarg2: The second target qubit.
|
|
434
|
+
"""
|
|
435
|
+
...
|
|
436
|
+
|
|
437
|
+
|
|
438
|
+
@wraps(uop.CRX)
|
|
439
|
+
def crx(ctrl: Qubit, qarg: Qubit, lam: float) -> None:
|
|
440
|
+
"""
|
|
441
|
+
Controlled Rx rotation gate.
|
|
442
|
+
|
|
443
|
+
Args:
|
|
444
|
+
ctrl: The control qubit.
|
|
445
|
+
qarg: The target qubit.
|
|
446
|
+
lam: The angle of rotation.
|
|
447
|
+
|
|
448
|
+
"""
|
|
449
|
+
|
|
450
|
+
...
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
@wraps(uop.CRY)
|
|
454
|
+
def cry(ctrl: Qubit, qarg: Qubit, lam: float) -> None:
|
|
455
|
+
"""
|
|
456
|
+
Controlled Ry rotation gate.
|
|
457
|
+
|
|
458
|
+
Args:
|
|
459
|
+
ctrl: The control qubit.
|
|
460
|
+
qarg: The target qubit.
|
|
461
|
+
lam: The angle of rotation.
|
|
462
|
+
|
|
463
|
+
"""
|
|
464
|
+
|
|
465
|
+
...
|
|
466
|
+
|
|
467
|
+
|
|
468
|
+
@wraps(uop.CRZ)
|
|
469
|
+
def crz(ctrl: Qubit, qarg: Qubit, lam: float) -> None:
|
|
470
|
+
"""
|
|
471
|
+
Controlled Rz rotation gate.
|
|
472
|
+
|
|
473
|
+
Args:
|
|
474
|
+
ctrl: The control qubit.
|
|
475
|
+
qarg: The target qubit.
|
|
476
|
+
lam: The angle of rotation.
|
|
477
|
+
|
|
478
|
+
"""
|
|
479
|
+
...
|
|
480
|
+
|
|
481
|
+
|
|
482
|
+
@wraps(uop.CU1)
|
|
483
|
+
def cu1(ctrl: Qubit, qarg: Qubit, lam: float) -> None:
|
|
484
|
+
"""
|
|
485
|
+
Controlled phase rotation gate.
|
|
486
|
+
|
|
487
|
+
Args:
|
|
488
|
+
ctrl: The control qubit.
|
|
489
|
+
qarg: The target qubit.
|
|
490
|
+
lam: The angle of rotation.
|
|
491
|
+
"""
|
|
492
|
+
|
|
493
|
+
...
|
|
494
|
+
|
|
495
|
+
|
|
496
|
+
@wraps(uop.CU1)
|
|
497
|
+
def cp(ctrl: Qubit, qarg: Qubit, lam: float) -> None:
|
|
498
|
+
"""
|
|
499
|
+
Controlled phase rotation gate. Same as cu1
|
|
500
|
+
|
|
501
|
+
Args:
|
|
502
|
+
ctrl: The control qubit.
|
|
503
|
+
qarg: The target qubit.
|
|
504
|
+
lam: The angle of rotation.
|
|
505
|
+
"""
|
|
506
|
+
|
|
507
|
+
...
|
|
508
|
+
|
|
509
|
+
|
|
510
|
+
@wraps(uop.CU3)
|
|
511
|
+
def cu3(ctrl: Qubit, qarg: Qubit, theta: float, phi: float, lam: float) -> None:
|
|
512
|
+
"""
|
|
513
|
+
Controlled 3-parameter unitary gate.
|
|
514
|
+
|
|
515
|
+
Args:
|
|
516
|
+
ctrl: The control qubit.
|
|
517
|
+
qarg: The target qubit.
|
|
518
|
+
theta: The angle of rotation.
|
|
519
|
+
phi: The angle of rotation.
|
|
520
|
+
lam: The angle of rotation.
|
|
521
|
+
|
|
522
|
+
"""
|
|
523
|
+
...
|
|
524
|
+
|
|
525
|
+
|
|
526
|
+
@wraps(uop.CU)
|
|
527
|
+
def cu(
|
|
528
|
+
ctrl: Qubit, qarg: Qubit, theta: float, phi: float, lam: float, gamma: float
|
|
529
|
+
) -> None:
|
|
530
|
+
"""
|
|
531
|
+
Controlled 4-parameter unitary gate.
|
|
532
|
+
|
|
533
|
+
This is equal to:
|
|
534
|
+
|
|
535
|
+
gate cu(theta,phi,lambda,gamma) c, t{
|
|
536
|
+
p(gamma) c;
|
|
537
|
+
p((lambda+phi)/2) c;
|
|
538
|
+
p((lambda-phi)/2) t;
|
|
539
|
+
cx c,t;
|
|
540
|
+
u(-theta/2,0,-(phi+lambda)/2) t;
|
|
541
|
+
cx c,t;
|
|
542
|
+
u(theta/2,phi,0) t;
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
Args:
|
|
546
|
+
ctrl: The control qubit.
|
|
547
|
+
qarg: The target qubit.
|
|
548
|
+
theta: The angle of rotation.
|
|
549
|
+
phi: The angle of rotation.
|
|
550
|
+
lam: The angle of rotation.
|
|
551
|
+
gamma: The angle of rotation.
|
|
552
|
+
"""
|
|
553
|
+
...
|
|
554
|
+
|
|
555
|
+
|
|
556
|
+
@wraps(uop.RXX)
|
|
557
|
+
def rxx(ctrl: Qubit, qarg: Qubit, theta: float) -> None:
|
|
558
|
+
"""
|
|
559
|
+
XX rotation gate.
|
|
560
|
+
|
|
561
|
+
Args:
|
|
562
|
+
ctrl: The first qubit.
|
|
563
|
+
qarg: The second qubit.
|
|
564
|
+
theta: The angle of rotation.
|
|
565
|
+
|
|
566
|
+
"""
|
|
567
|
+
...
|
|
568
|
+
|
|
569
|
+
|
|
570
|
+
@wraps(uop.RZZ)
|
|
571
|
+
def rzz(ctrl: Qubit, qarg: Qubit, theta: float) -> None:
|
|
572
|
+
"""
|
|
573
|
+
ZZ rotation gate.
|
|
574
|
+
|
|
575
|
+
Args:
|
|
576
|
+
ctrl: The first qubit.
|
|
577
|
+
qarg: The second qubit.
|
|
578
|
+
theta: The angle of rotation.
|
|
579
|
+
|
|
580
|
+
"""
|
|
581
|
+
...
|
|
582
|
+
|
|
583
|
+
|
|
584
|
+
@wraps(expr.Sin)
|
|
585
|
+
def sin(value: float) -> float:
|
|
586
|
+
"""
|
|
587
|
+
Sine math function.
|
|
588
|
+
|
|
589
|
+
Args:
|
|
590
|
+
value: The value to take the sine of.
|
|
591
|
+
|
|
592
|
+
Returns:
|
|
593
|
+
The sine of `value`.
|
|
594
|
+
|
|
595
|
+
"""
|
|
596
|
+
...
|
|
597
|
+
|
|
598
|
+
|
|
599
|
+
@wraps(expr.Cos)
|
|
600
|
+
def cos(value: float) -> float:
|
|
601
|
+
"""
|
|
602
|
+
Cosine math function.
|
|
603
|
+
|
|
604
|
+
Args:
|
|
605
|
+
value: The value to take the cosine of.
|
|
606
|
+
|
|
607
|
+
Returns:
|
|
608
|
+
The cosine of `value`.
|
|
609
|
+
|
|
610
|
+
"""
|
|
611
|
+
|
|
612
|
+
...
|
|
613
|
+
|
|
614
|
+
|
|
615
|
+
@wraps(expr.Tan)
|
|
616
|
+
def tan(value: float) -> float:
|
|
617
|
+
"""
|
|
618
|
+
Tangent math function.
|
|
619
|
+
|
|
620
|
+
Args:
|
|
621
|
+
value: The value to take the tangent of.
|
|
622
|
+
|
|
623
|
+
Returns:
|
|
624
|
+
The tangent of `value`.
|
|
625
|
+
|
|
626
|
+
"""
|
|
627
|
+
|
|
628
|
+
...
|
|
629
|
+
|
|
630
|
+
|
|
631
|
+
@wraps(expr.Exp)
|
|
632
|
+
def exp(value: float) -> float:
|
|
633
|
+
"""
|
|
634
|
+
Exponential math function.
|
|
635
|
+
|
|
636
|
+
Args:
|
|
637
|
+
value: The value to exponentiate.
|
|
638
|
+
|
|
639
|
+
Returns:
|
|
640
|
+
The exponential of `value`.
|
|
641
|
+
|
|
642
|
+
"""
|
|
643
|
+
|
|
644
|
+
...
|
|
645
|
+
|
|
646
|
+
|
|
647
|
+
@wraps(expr.Log)
|
|
648
|
+
def ln(value: float) -> float:
|
|
649
|
+
"""
|
|
650
|
+
logarithm math function.
|
|
651
|
+
|
|
652
|
+
Args:
|
|
653
|
+
value: The value to take the natural logarithm of.
|
|
654
|
+
|
|
655
|
+
Returns:
|
|
656
|
+
The natural logarithm of `value`.
|
|
657
|
+
|
|
658
|
+
"""
|
|
659
|
+
|
|
660
|
+
...
|
|
661
|
+
|
|
662
|
+
|
|
663
|
+
@wraps(expr.Sqrt)
|
|
664
|
+
def sqrt(value: float) -> float:
|
|
665
|
+
"""
|
|
666
|
+
Square root math function.
|
|
667
|
+
|
|
668
|
+
Args:
|
|
669
|
+
value: The value to take the square root of.
|
|
670
|
+
|
|
671
|
+
Returns:
|
|
672
|
+
The square root of `value`.
|
|
673
|
+
"""
|
|
674
|
+
...
|