bloqade-circuit 0.6.5__py3-none-any.whl → 0.6.7__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/squin/analysis/nsites/impls.py +7 -0
- bloqade/squin/cirq/__init__.py +31 -5
- bloqade/squin/cirq/emit/emit_circuit.py +21 -1
- bloqade/squin/cirq/emit/qubit.py +2 -2
- bloqade/squin/noise/rewrite.py +37 -8
- {bloqade_circuit-0.6.5.dist-info → bloqade_circuit-0.6.7.dist-info}/METADATA +1 -1
- {bloqade_circuit-0.6.5.dist-info → bloqade_circuit-0.6.7.dist-info}/RECORD +9 -9
- {bloqade_circuit-0.6.5.dist-info → bloqade_circuit-0.6.7.dist-info}/WHEEL +0 -0
- {bloqade_circuit-0.6.5.dist-info → bloqade_circuit-0.6.7.dist-info}/licenses/LICENSE +0 -0
|
@@ -81,6 +81,13 @@ class SquinOp(interp.MethodTable):
|
|
|
81
81
|
op_sites = frame.get(stmt.op)
|
|
82
82
|
return (op_sites,)
|
|
83
83
|
|
|
84
|
+
@interp.impl(op.stmts.PauliString)
|
|
85
|
+
def pauli_string(
|
|
86
|
+
self, interp: NSitesAnalysis, frame: interp.Frame, stmt: op.stmts.PauliString
|
|
87
|
+
):
|
|
88
|
+
s = stmt.string
|
|
89
|
+
return (NumberSites(sites=len(s)),)
|
|
90
|
+
|
|
84
91
|
|
|
85
92
|
@scf.dialect.register(key="op.nsites")
|
|
86
93
|
class ScfSquinOp(ScfTypeInfer):
|
bloqade/squin/cirq/__init__.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
from typing import Any, Sequence
|
|
2
|
+
from warnings import warn
|
|
2
3
|
|
|
3
4
|
import cirq
|
|
4
5
|
from kirin import ir, types
|
|
@@ -157,6 +158,8 @@ def load_circuit(
|
|
|
157
158
|
def emit_circuit(
|
|
158
159
|
mt: ir.Method,
|
|
159
160
|
qubits: Sequence[cirq.Qid] | None = None,
|
|
161
|
+
circuit_qubits: Sequence[cirq.Qid] | None = None,
|
|
162
|
+
args: tuple = (),
|
|
160
163
|
ignore_returns: bool = False,
|
|
161
164
|
) -> cirq.Circuit:
|
|
162
165
|
"""Converts a squin.kernel method to a cirq.Circuit object.
|
|
@@ -165,12 +168,14 @@ def emit_circuit(
|
|
|
165
168
|
mt (ir.Method): The kernel method from which to construct the circuit.
|
|
166
169
|
|
|
167
170
|
Keyword Args:
|
|
168
|
-
|
|
171
|
+
circuit_qubits (Sequence[cirq.Qid] | None):
|
|
169
172
|
A list of qubits to use as the qubits in the circuit. Defaults to None.
|
|
170
173
|
If this is None, then `cirq.LineQubit`s are inserted for every `squin.qubit.new`
|
|
171
174
|
statement in the order they appear inside the kernel.
|
|
172
175
|
**Note**: If a list of qubits is provided, make sure that there is a sufficient
|
|
173
176
|
number of qubits for the resulting circuit.
|
|
177
|
+
args (tuple):
|
|
178
|
+
The arguments of the kernel function from which to emit a circuit.
|
|
174
179
|
ignore_returns (bool):
|
|
175
180
|
If `False`, emitting a circuit from a kernel that returns a value will error.
|
|
176
181
|
Set it to `True` in order to ignore the return value(s). Defaults to `False`.
|
|
@@ -223,7 +228,7 @@ def emit_circuit(
|
|
|
223
228
|
# custom list of qubits on grid
|
|
224
229
|
qubits = [cirq.GridQubit(i, i+1) for i in range(5)]
|
|
225
230
|
|
|
226
|
-
circuit = squin.cirq.emit_circuit(main,
|
|
231
|
+
circuit = squin.cirq.emit_circuit(main, circuit_qubits=qubits)
|
|
227
232
|
print(circuit)
|
|
228
233
|
|
|
229
234
|
```
|
|
@@ -232,6 +237,12 @@ def emit_circuit(
|
|
|
232
237
|
and manipulate the qubits in other circuits directly written in cirq as well.
|
|
233
238
|
"""
|
|
234
239
|
|
|
240
|
+
if circuit_qubits is None and qubits is not None:
|
|
241
|
+
circuit_qubits = qubits
|
|
242
|
+
warn(
|
|
243
|
+
"The keyword argument `qubits` is deprecated. Use `circuit_qubits` instead."
|
|
244
|
+
)
|
|
245
|
+
|
|
235
246
|
if (
|
|
236
247
|
not ignore_returns
|
|
237
248
|
and isinstance(mt.code, func.Function)
|
|
@@ -242,17 +253,24 @@ def emit_circuit(
|
|
|
242
253
|
" Set `ignore_returns = True` in order to simply ignore the return values and emit a circuit."
|
|
243
254
|
)
|
|
244
255
|
|
|
256
|
+
if len(args) != len(mt.args):
|
|
257
|
+
raise ValueError(
|
|
258
|
+
f"The method from which you're trying to emit a circuit takes {len(mt.args)} as input, but you passed in {len(args)} via the `args` keyword!"
|
|
259
|
+
)
|
|
260
|
+
|
|
245
261
|
emitter = EmitCirq(qubits=qubits)
|
|
246
262
|
|
|
247
263
|
# Rewrite noise statements
|
|
248
264
|
mt_ = mt.similar(mt.dialects)
|
|
249
265
|
RewriteNoiseStmts(mt_.dialects)(mt_)
|
|
250
266
|
|
|
251
|
-
return emitter.run(mt_, args=
|
|
267
|
+
return emitter.run(mt_, args=args)
|
|
252
268
|
|
|
253
269
|
|
|
254
270
|
def dump_circuit(
|
|
255
271
|
mt: ir.Method,
|
|
272
|
+
circuit_qubits: Sequence[cirq.Qid] | None = None,
|
|
273
|
+
args: tuple = (),
|
|
256
274
|
qubits: Sequence[cirq.Qid] | None = None,
|
|
257
275
|
ignore_returns: bool = False,
|
|
258
276
|
**kwargs,
|
|
@@ -265,16 +283,24 @@ def dump_circuit(
|
|
|
265
283
|
mt (ir.Method): The kernel method from which to construct the circuit.
|
|
266
284
|
|
|
267
285
|
Keyword Args:
|
|
268
|
-
|
|
286
|
+
circuit_qubits (Sequence[cirq.Qid] | None):
|
|
269
287
|
A list of qubits to use as the qubits in the circuit. Defaults to None.
|
|
270
288
|
If this is None, then `cirq.LineQubit`s are inserted for every `squin.qubit.new`
|
|
271
289
|
statement in the order they appear inside the kernel.
|
|
272
290
|
**Note**: If a list of qubits is provided, make sure that there is a sufficient
|
|
273
291
|
number of qubits for the resulting circuit.
|
|
292
|
+
args (tuple):
|
|
293
|
+
The arguments of the kernel function from which to emit a circuit.
|
|
274
294
|
ignore_returns (bool):
|
|
275
295
|
If `False`, emitting a circuit from a kernel that returns a value will error.
|
|
276
296
|
Set it to `True` in order to ignore the return value(s). Defaults to `False`.
|
|
277
297
|
|
|
278
298
|
"""
|
|
279
|
-
circuit = emit_circuit(
|
|
299
|
+
circuit = emit_circuit(
|
|
300
|
+
mt,
|
|
301
|
+
circuit_qubits=circuit_qubits,
|
|
302
|
+
qubits=qubits,
|
|
303
|
+
args=args,
|
|
304
|
+
ignore_returns=ignore_returns,
|
|
305
|
+
)
|
|
280
306
|
return cirq.to_json(circuit, **kwargs)
|
|
@@ -2,7 +2,7 @@ from typing import Sequence
|
|
|
2
2
|
from dataclasses import field, dataclass
|
|
3
3
|
|
|
4
4
|
import cirq
|
|
5
|
-
from kirin import ir
|
|
5
|
+
from kirin import ir, interp
|
|
6
6
|
from kirin.emit import EmitABC, EmitError, EmitFrame
|
|
7
7
|
from kirin.interp import MethodTable, impl
|
|
8
8
|
from kirin.dialects import func
|
|
@@ -45,6 +45,26 @@ class EmitCirq(EmitABC[EmitCirqFrame, cirq.Circuit]):
|
|
|
45
45
|
def run_method(self, method: ir.Method, args: tuple[cirq.Circuit, ...]):
|
|
46
46
|
return self.run_callable(method.code, args)
|
|
47
47
|
|
|
48
|
+
def run_callable_region(
|
|
49
|
+
self,
|
|
50
|
+
frame: EmitCirqFrame,
|
|
51
|
+
code: ir.Statement,
|
|
52
|
+
region: ir.Region,
|
|
53
|
+
args: tuple,
|
|
54
|
+
):
|
|
55
|
+
if len(region.blocks) > 0:
|
|
56
|
+
block_args = list(region.blocks[0].args)
|
|
57
|
+
# NOTE: skip self arg
|
|
58
|
+
frame.set_values(block_args[1:], args)
|
|
59
|
+
|
|
60
|
+
results = self.eval_stmt(frame, code)
|
|
61
|
+
if isinstance(results, tuple):
|
|
62
|
+
if len(results) == 0:
|
|
63
|
+
return self.void
|
|
64
|
+
elif len(results) == 1:
|
|
65
|
+
return results[0]
|
|
66
|
+
raise interp.InterpreterError(f"Unexpected results {results}")
|
|
67
|
+
|
|
48
68
|
def emit_block(self, frame: EmitCirqFrame, block: ir.Block) -> cirq.Circuit:
|
|
49
69
|
for stmt in block.stmts:
|
|
50
70
|
result = self.eval_stmt(frame, stmt)
|
bloqade/squin/cirq/emit/qubit.py
CHANGED
|
@@ -49,7 +49,7 @@ class EmitCirqQubitMethods(MethodTable):
|
|
|
49
49
|
):
|
|
50
50
|
qbit = frame.get(stmt.qubit)
|
|
51
51
|
frame.circuit.append(cirq.measure(qbit))
|
|
52
|
-
return ()
|
|
52
|
+
return (emit.void,)
|
|
53
53
|
|
|
54
54
|
@impl(qubit.MeasureQubitList)
|
|
55
55
|
def measure_qubit_list(
|
|
@@ -57,4 +57,4 @@ class EmitCirqQubitMethods(MethodTable):
|
|
|
57
57
|
):
|
|
58
58
|
qbits = frame.get(stmt.qubits)
|
|
59
59
|
frame.circuit.append(cirq.measure(qbits))
|
|
60
|
-
return ()
|
|
60
|
+
return (emit.void,)
|
bloqade/squin/noise/rewrite.py
CHANGED
|
@@ -3,7 +3,7 @@ import itertools
|
|
|
3
3
|
from kirin import ir
|
|
4
4
|
from kirin.passes import Pass
|
|
5
5
|
from kirin.rewrite import Walk
|
|
6
|
-
from kirin.dialects import ilist
|
|
6
|
+
from kirin.dialects import py, ilist
|
|
7
7
|
from kirin.rewrite.abc import RewriteRule, RewriteResult
|
|
8
8
|
|
|
9
9
|
from .stmts import (
|
|
@@ -11,6 +11,7 @@ from .stmts import (
|
|
|
11
11
|
QubitLoss,
|
|
12
12
|
Depolarize,
|
|
13
13
|
PauliError,
|
|
14
|
+
Depolarize2,
|
|
14
15
|
NoiseChannel,
|
|
15
16
|
TwoQubitPauliChannel,
|
|
16
17
|
SingleQubitPauliChannel,
|
|
@@ -58,6 +59,18 @@ class _RewriteNoiseStmts(RewriteRule):
|
|
|
58
59
|
def rewrite_two_qubit_pauli_channel(
|
|
59
60
|
self, node: TwoQubitPauliChannel
|
|
60
61
|
) -> RewriteResult:
|
|
62
|
+
operator_list = self._insert_two_qubit_paulis_before_node(node)
|
|
63
|
+
stochastic_unitary = StochasticUnitaryChannel(
|
|
64
|
+
operators=operator_list, probabilities=node.params
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
node.replace_by(stochastic_unitary)
|
|
68
|
+
return RewriteResult(has_done_something=True)
|
|
69
|
+
|
|
70
|
+
@staticmethod
|
|
71
|
+
def _insert_two_qubit_paulis_before_node(
|
|
72
|
+
node: TwoQubitPauliChannel | Depolarize2,
|
|
73
|
+
) -> ir.ResultValue:
|
|
61
74
|
paulis = (Identity(sites=1), X(), Y(), Z())
|
|
62
75
|
for op in paulis:
|
|
63
76
|
op.insert_before(node)
|
|
@@ -71,12 +84,7 @@ class _RewriteNoiseStmts(RewriteRule):
|
|
|
71
84
|
operators.append(op.result)
|
|
72
85
|
|
|
73
86
|
(operator_list := ilist.New(values=operators)).insert_before(node)
|
|
74
|
-
|
|
75
|
-
operators=operator_list.result, probabilities=node.params
|
|
76
|
-
)
|
|
77
|
-
|
|
78
|
-
node.replace_by(stochastic_unitary)
|
|
79
|
-
return RewriteResult(has_done_something=True)
|
|
87
|
+
return operator_list.result
|
|
80
88
|
|
|
81
89
|
def rewrite_p_p_error(self, node: PPError) -> RewriteResult:
|
|
82
90
|
(operators := ilist.New(values=(node.op,))).insert_before(node)
|
|
@@ -95,8 +103,14 @@ class _RewriteNoiseStmts(RewriteRule):
|
|
|
95
103
|
op.insert_before(node)
|
|
96
104
|
operators.append(op.result)
|
|
97
105
|
|
|
106
|
+
# NOTE: need to divide the probability by 3 to get the correct total error rate
|
|
107
|
+
(three := py.Constant(3)).insert_before(node)
|
|
108
|
+
(p_over_3 := py.Div(node.p, three.result)).insert_before(node)
|
|
109
|
+
|
|
98
110
|
(operator_list := ilist.New(values=operators)).insert_before(node)
|
|
99
|
-
(ps := ilist.New(values=[
|
|
111
|
+
(ps := ilist.New(values=[p_over_3.result for _ in range(3)])).insert_before(
|
|
112
|
+
node
|
|
113
|
+
)
|
|
100
114
|
|
|
101
115
|
stochastic_unitary = StochasticUnitaryChannel(
|
|
102
116
|
operators=operator_list.result, probabilities=ps.result
|
|
@@ -105,6 +119,21 @@ class _RewriteNoiseStmts(RewriteRule):
|
|
|
105
119
|
|
|
106
120
|
return RewriteResult(has_done_something=True)
|
|
107
121
|
|
|
122
|
+
def rewrite_depolarize2(self, node: Depolarize2) -> RewriteResult:
|
|
123
|
+
operator_list = self._insert_two_qubit_paulis_before_node(node)
|
|
124
|
+
|
|
125
|
+
# NOTE: need to divide the probability by 15 to get the correct total error rate
|
|
126
|
+
(fifteen := py.Constant(15)).insert_before(node)
|
|
127
|
+
(p_over_15 := py.Div(node.p, fifteen.result)).insert_before(node)
|
|
128
|
+
(probs := ilist.New(values=[p_over_15.result] * 15)).insert_before(node)
|
|
129
|
+
|
|
130
|
+
stochastic_unitary = StochasticUnitaryChannel(
|
|
131
|
+
operators=operator_list, probabilities=probs.result
|
|
132
|
+
)
|
|
133
|
+
node.replace_by(stochastic_unitary)
|
|
134
|
+
|
|
135
|
+
return RewriteResult(has_done_something=True)
|
|
136
|
+
|
|
108
137
|
|
|
109
138
|
class RewriteNoiseStmts(Pass):
|
|
110
139
|
def unsafe_run(self, mt: ir.Method):
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: bloqade-circuit
|
|
3
|
-
Version: 0.6.
|
|
3
|
+
Version: 0.6.7
|
|
4
4
|
Summary: The software development toolkit for neutral atom arrays.
|
|
5
5
|
Author-email: Roger-luo <rluo@quera.com>, kaihsin <khwu@quera.com>, weinbe58 <pweinberg@quera.com>, johnzl-777 <jlong@quera.com>
|
|
6
6
|
License-File: LICENSE
|
|
@@ -139,19 +139,19 @@ bloqade/squin/analysis/address_impl.py,sha256=eMEGlkw88ozj8ZGHcfQ0qW2K_dNxYxnhwz
|
|
|
139
139
|
bloqade/squin/analysis/schedule.py,sha256=buuC4bFuLuaSDK2BZfkRkh8ZdNicz9HkEv3FAnsDViE,7880
|
|
140
140
|
bloqade/squin/analysis/nsites/__init__.py,sha256=RlQg7ivczXCXG5lMeL3ipYKj2oJKC4THu8orYf5PBYs,263
|
|
141
141
|
bloqade/squin/analysis/nsites/analysis.py,sha256=rIe1RU1MZRItcE2aB8DYahLrv73HfD3IHCX3E_EGQ1c,1773
|
|
142
|
-
bloqade/squin/analysis/nsites/impls.py,sha256=
|
|
142
|
+
bloqade/squin/analysis/nsites/impls.py,sha256=wSNWjNmgwCP35FgmreyLKmRYedxlebWi7LhsEq9jPs4,3097
|
|
143
143
|
bloqade/squin/analysis/nsites/lattice.py,sha256=ruh0808SHtj3ecuT-C3AZTsLY2j3DRhtezGiTZvcuVs,942
|
|
144
|
-
bloqade/squin/cirq/__init__.py,sha256=
|
|
144
|
+
bloqade/squin/cirq/__init__.py,sha256=7OYYboSl5lPwdWOKk4AJgm1s1lBX_WAstVqPfaynSv8,10156
|
|
145
145
|
bloqade/squin/cirq/lowering.py,sha256=F0_skv9lORxUFrhbNaN2ZQpqGnhPyslHt5E92uta5BQ,17959
|
|
146
|
-
bloqade/squin/cirq/emit/emit_circuit.py,sha256=
|
|
146
|
+
bloqade/squin/cirq/emit/emit_circuit.py,sha256=JVFXiaSB7A9kamRwCjLqs03Sel4PVCBT-6kRNRWX-jo,4393
|
|
147
147
|
bloqade/squin/cirq/emit/noise.py,sha256=rESjGC_66s2Y4FwwYda4rY3mYHYjbqLlKE_vnqpZDYI,1534
|
|
148
148
|
bloqade/squin/cirq/emit/op.py,sha256=z54NP5KqMxffXeFGWamEzvunpTNrxmYuluurk4j2-ps,4000
|
|
149
|
-
bloqade/squin/cirq/emit/qubit.py,sha256=
|
|
149
|
+
bloqade/squin/cirq/emit/qubit.py,sha256=IegghRU5E1urd0ddV1X2Fh_aEWAPmUPZLVj9AafN2Cg,1930
|
|
150
150
|
bloqade/squin/cirq/emit/runtime.py,sha256=dH7JSMt2mALPhVFjmZETQzvnTUQ3BFY5poe0YZpM5vQ,6819
|
|
151
151
|
bloqade/squin/noise/__init__.py,sha256=xST2qojx6ZApRoiKIXOtifDzSpTZgo-67ja309FFvWw,364
|
|
152
152
|
bloqade/squin/noise/_dialect.py,sha256=2IR98J-lXm5Y3srP9g-FD4JC-qTq2seureM6mKKq1xg,63
|
|
153
153
|
bloqade/squin/noise/_wrapper.py,sha256=P8fkr1_2U47PtvqnQqeTI7VzThNIK17cNh2QX6ABh_w,815
|
|
154
|
-
bloqade/squin/noise/rewrite.py,sha256
|
|
154
|
+
bloqade/squin/noise/rewrite.py,sha256=8v8AAi2G-ZatZ6dTpqc88hCBMMoWz2TK3nwkLkwk7Fo,5099
|
|
155
155
|
bloqade/squin/noise/stmts.py,sha256=F8AsDp2xsLez9vkSamDW985MUCubz3TMRrE0L745GmI,1875
|
|
156
156
|
bloqade/squin/op/__init__.py,sha256=6JOjPdzc6RKO4299ZFz4Jk-wtVyPlGTkakYewHBueXw,841
|
|
157
157
|
bloqade/squin/op/_dialect.py,sha256=66G1IYqmsqUEaCTyUqn2shSHmGYduiTU8GfDXcoMvw4,55
|
|
@@ -230,7 +230,7 @@ bloqade/visual/animation/runtime/atoms.py,sha256=EmjxhujLiHHPS_HtH_B-7TiqeHgvW5u
|
|
|
230
230
|
bloqade/visual/animation/runtime/ppoly.py,sha256=JB9IP53N1w6adBJEue6J5Nmj818Id9JvrlgrmiQTU1I,1385
|
|
231
231
|
bloqade/visual/animation/runtime/qpustate.py,sha256=rlmxQeJSvaohXrTpXQL5y-NJcpvfW33xPaYM1slv7cc,4270
|
|
232
232
|
bloqade/visual/animation/runtime/utils.py,sha256=ju9IzOWX-vKwfpqUjlUKu3Ssr_UFPFFq-tzH_Nqyo_c,1212
|
|
233
|
-
bloqade_circuit-0.6.
|
|
234
|
-
bloqade_circuit-0.6.
|
|
235
|
-
bloqade_circuit-0.6.
|
|
236
|
-
bloqade_circuit-0.6.
|
|
233
|
+
bloqade_circuit-0.6.7.dist-info/METADATA,sha256=n1lFzCB0O9SdZuCP9tn57cphpaOC57lIqQ75sXMnTIU,3849
|
|
234
|
+
bloqade_circuit-0.6.7.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
235
|
+
bloqade_circuit-0.6.7.dist-info/licenses/LICENSE,sha256=S5GIJwR6QCixPA9wryYb44ZEek0Nz4rt_zLUqP05UbU,13160
|
|
236
|
+
bloqade_circuit-0.6.7.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|