bloqade-circuit 0.2.3__py3-none-any.whl → 0.4.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/address/impls.py +3 -2
- bloqade/pyqrack/device.py +1 -3
- bloqade/pyqrack/noise/native.py +8 -8
- bloqade/pyqrack/qasm2/core.py +4 -1
- bloqade/pyqrack/squin/op.py +7 -0
- bloqade/pyqrack/squin/qubit.py +5 -27
- bloqade/pyqrack/squin/runtime.py +18 -0
- bloqade/pyqrack/squin/wire.py +4 -22
- bloqade/pyqrack/task.py +13 -5
- bloqade/qasm2/__init__.py +1 -0
- bloqade/qasm2/_qasm_loading.py +151 -0
- bloqade/qasm2/dialects/core/__init__.py +9 -1
- bloqade/qasm2/dialects/expr/__init__.py +18 -1
- bloqade/{noise/native → qasm2/dialects/noise}/__init__.py +1 -7
- bloqade/qasm2/dialects/noise/_dialect.py +3 -0
- bloqade/{noise → qasm2/dialects/noise}/fidelity.py +4 -4
- bloqade/qasm2/dialects/noise/model.py +278 -0
- bloqade/{noise/native → qasm2/dialects/noise}/stmts.py +1 -1
- bloqade/qasm2/dialects/uop/__init__.py +39 -3
- bloqade/qasm2/dialects/uop/schedule.py +1 -1
- bloqade/qasm2/emit/impls/__init__.py +1 -0
- bloqade/qasm2/emit/impls/noise.py +89 -0
- bloqade/qasm2/emit/main.py +23 -4
- bloqade/qasm2/emit/target.py +19 -4
- bloqade/qasm2/noise.py +67 -0
- bloqade/qasm2/parse/__init__.py +7 -4
- bloqade/qasm2/parse/lowering.py +20 -130
- bloqade/qasm2/parse/qasm2.lark +1 -1
- bloqade/qasm2/passes/__init__.py +1 -0
- bloqade/qasm2/passes/fold.py +6 -0
- bloqade/qasm2/passes/glob.py +12 -8
- bloqade/qasm2/passes/noise.py +27 -16
- bloqade/qasm2/passes/parallel.py +9 -0
- bloqade/qasm2/passes/unroll_if.py +25 -0
- bloqade/qasm2/rewrite/__init__.py +3 -0
- bloqade/qasm2/rewrite/desugar.py +3 -2
- bloqade/qasm2/rewrite/native_gates.py +67 -4
- bloqade/qasm2/rewrite/noise/__init__.py +0 -0
- bloqade/qasm2/rewrite/{heuristic_noise.py → noise/heuristic_noise.py} +32 -62
- bloqade/{noise/native/rewrite.py → qasm2/rewrite/noise/remove_noise.py} +2 -2
- bloqade/qasm2/rewrite/split_ifs.py +66 -0
- bloqade/qbraid/lowering.py +8 -8
- bloqade/squin/__init__.py +7 -1
- bloqade/squin/analysis/nsites/__init__.py +1 -0
- bloqade/squin/analysis/nsites/impls.py +16 -1
- bloqade/squin/groups.py +4 -4
- bloqade/squin/lowering.py +27 -0
- bloqade/squin/noise/__init__.py +7 -26
- bloqade/squin/noise/_wrapper.py +25 -0
- bloqade/squin/op/__init__.py +34 -159
- bloqade/squin/op/_wrapper.py +105 -0
- bloqade/squin/op/stdlib.py +62 -0
- bloqade/squin/op/stmts.py +10 -0
- bloqade/squin/passes/__init__.py +1 -0
- bloqade/squin/passes/stim.py +68 -0
- bloqade/squin/qubit.py +32 -37
- bloqade/squin/rewrite/__init__.py +11 -0
- bloqade/squin/rewrite/desugar.py +65 -0
- bloqade/squin/rewrite/qubit_to_stim.py +61 -0
- bloqade/squin/rewrite/squin_measure.py +73 -0
- bloqade/squin/rewrite/stim_rewrite_util.py +153 -0
- bloqade/squin/rewrite/wire_identity_elimination.py +24 -0
- bloqade/squin/rewrite/wire_to_stim.py +52 -0
- bloqade/squin/rewrite/wrap_analysis.py +72 -0
- bloqade/squin/wire.py +5 -22
- bloqade/stim/__init__.py +40 -5
- bloqade/stim/_wrappers.py +18 -12
- bloqade/stim/dialects/__init__.py +1 -5
- bloqade/stim/dialects/{aux → auxiliary}/__init__.py +13 -1
- bloqade/stim/dialects/{aux → auxiliary}/emit.py +18 -3
- bloqade/stim/dialects/{aux → auxiliary}/stmts/__init__.py +1 -0
- bloqade/stim/dialects/{aux → auxiliary}/stmts/annotate.py +8 -0
- bloqade/stim/dialects/collapse/__init__.py +13 -2
- bloqade/stim/dialects/collapse/{emit.py → emit_str.py} +4 -2
- bloqade/stim/dialects/collapse/stmts/pp_measure.py +1 -1
- bloqade/stim/dialects/gate/__init__.py +16 -1
- bloqade/stim/dialects/gate/emit.py +10 -3
- bloqade/stim/dialects/gate/stmts/base.py +1 -1
- bloqade/stim/dialects/gate/stmts/pp.py +1 -1
- bloqade/stim/dialects/noise/emit.py +33 -2
- bloqade/stim/dialects/noise/stmts.py +29 -0
- bloqade/stim/emit/__init__.py +1 -1
- bloqade/stim/groups.py +4 -2
- bloqade/stim/parse/__init__.py +1 -0
- bloqade/stim/parse/lowering.py +686 -0
- {bloqade_circuit-0.2.3.dist-info → bloqade_circuit-0.4.0.dist-info}/METADATA +5 -3
- {bloqade_circuit-0.2.3.dist-info → bloqade_circuit-0.4.0.dist-info}/RECORD +95 -77
- bloqade/noise/__init__.py +0 -2
- bloqade/noise/native/_dialect.py +0 -3
- bloqade/noise/native/_wrappers.py +0 -34
- bloqade/noise/native/model.py +0 -346
- bloqade/qasm2/dialects/noise.py +0 -16
- bloqade/squin/rewrite/measure_desugar.py +0 -33
- /bloqade/stim/dialects/{aux → auxiliary}/_dialect.py +0 -0
- /bloqade/stim/dialects/{aux → auxiliary}/interp.py +0 -0
- /bloqade/stim/dialects/{aux → auxiliary}/lowering.py +0 -0
- /bloqade/stim/dialects/{aux → auxiliary}/stmts/const.py +0 -0
- /bloqade/stim/dialects/{aux → auxiliary}/types.py +0 -0
- /bloqade/stim/emit/{stim.py → stim_str.py} +0 -0
- {bloqade_circuit-0.2.3.dist-info → bloqade_circuit-0.4.0.dist-info}/WHEEL +0 -0
- {bloqade_circuit-0.2.3.dist-info → bloqade_circuit-0.4.0.dist-info}/licenses/LICENSE +0 -0
bloqade/noise/native/model.py
DELETED
|
@@ -1,346 +0,0 @@
|
|
|
1
|
-
import abc
|
|
2
|
-
import math
|
|
3
|
-
from typing import Dict, List, Tuple
|
|
4
|
-
from dataclasses import field, dataclass
|
|
5
|
-
from collections.abc import Sequence
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
@dataclass(frozen=True)
|
|
9
|
-
class GateNoiseParams:
|
|
10
|
-
"""Parameters for gate noise."""
|
|
11
|
-
|
|
12
|
-
local_px: float = field(default=1e-3, kw_only=True)
|
|
13
|
-
"""The error probability for a Pauli-X error during a local single qubit gate operation."""
|
|
14
|
-
local_py: float = field(default=1e-3, kw_only=True)
|
|
15
|
-
"""The error probability for a Pauli-Y error during a local single qubit gate operation."""
|
|
16
|
-
local_pz: float = field(default=1e-3, kw_only=True)
|
|
17
|
-
"""The error probability for a Pauli-Z error during a local single qubit gate operation."""
|
|
18
|
-
local_loss_prob: float = field(default=1e-4, kw_only=True)
|
|
19
|
-
"""The error probability for a loss during a local single qubit gate operation."""
|
|
20
|
-
|
|
21
|
-
global_px: float = field(default=1e-3, kw_only=True)
|
|
22
|
-
"""The error probability for a Pauli-X error during a global single qubit gate operation."""
|
|
23
|
-
global_py: float = field(default=1e-3, kw_only=True)
|
|
24
|
-
"""The error probability for a Pauli-Y error during a global single qubit gate operation."""
|
|
25
|
-
global_pz: float = field(default=1e-3, kw_only=True)
|
|
26
|
-
"""The error probability for a Pauli-Z error during a global single qubit gate operation."""
|
|
27
|
-
global_loss_prob: float = field(default=1e-3, kw_only=True)
|
|
28
|
-
"""The error probability for a loss during a global single qubit gate operation."""
|
|
29
|
-
|
|
30
|
-
cz_paired_gate_px: float = field(default=1e-3, kw_only=True)
|
|
31
|
-
"""The error probability for a Pauli-X error during CZ gate operation when two qubits are within blockade radius."""
|
|
32
|
-
cz_paired_gate_py: float = field(default=1e-3, kw_only=True)
|
|
33
|
-
"""The error probability for a Pauli-Y error during CZ gate operation when two qubits are within blockade radius."""
|
|
34
|
-
cz_paired_gate_pz: float = field(default=1e-3, kw_only=True)
|
|
35
|
-
"""The error probability for a Pauli-Z error during CZ gate operation when two qubits are within blockade radius."""
|
|
36
|
-
cz_gate_loss_prob: float = field(default=1e-3, kw_only=True)
|
|
37
|
-
"""The error probability for a loss during CZ gate operation when two qubits are within blockade radius."""
|
|
38
|
-
|
|
39
|
-
cz_unpaired_gate_px: float = field(default=1e-3, kw_only=True)
|
|
40
|
-
"""The error probability for Pauli-X error during CZ gate operation when another qubit is not within blockade radius."""
|
|
41
|
-
cz_unpaired_gate_py: float = field(default=1e-3, kw_only=True)
|
|
42
|
-
"""The error probability for Pauli-Y error during CZ gate operation when another qubit is not within blockade radius."""
|
|
43
|
-
cz_unpaired_gate_pz: float = field(default=1e-3, kw_only=True)
|
|
44
|
-
"""The error probability for Pauli-Z error during CZ gate operation when another qubit is not within blockade radius."""
|
|
45
|
-
cz_unpaired_loss_prob: float = field(default=1e-3, kw_only=True)
|
|
46
|
-
"""The error probability for a loss during CZ gate operation when another qubit is not within blockade radius."""
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
@dataclass(frozen=True)
|
|
50
|
-
class MoveNoiseParams:
|
|
51
|
-
idle_px_rate: float = field(default=1e-6, kw_only=True)
|
|
52
|
-
"""The error rate (prob/microsecond) for a Pauli-X error during an idle operation."""
|
|
53
|
-
idle_py_rate: float = field(default=1e-6, kw_only=True)
|
|
54
|
-
"""The error rate (prob/microsecond) for a Pauli-Y error during an idle operation."""
|
|
55
|
-
idle_pz_rate: float = field(default=1e-6, kw_only=True)
|
|
56
|
-
"""The error rate (prob/microsecond) for a Pauli-Z error during an idle operation."""
|
|
57
|
-
idle_loss_rate: float = field(default=1e-6, kw_only=True)
|
|
58
|
-
"""The error rate (prob/microsecond) for a loss during an idle operation."""
|
|
59
|
-
|
|
60
|
-
move_px_rate: float = field(default=1e-6, kw_only=True)
|
|
61
|
-
"""The error rate (prob/microsecond) for a Pauli-X error during a move operation."""
|
|
62
|
-
move_py_rate: float = field(default=1e-6, kw_only=True)
|
|
63
|
-
"""The error rate e (prob/microsecond) for a Pauli-Y error during a move operation."""
|
|
64
|
-
move_pz_rate: float = field(default=1e-6, kw_only=True)
|
|
65
|
-
"""The error rate e (prob/microsecond) for a Pauli-Z error during a move operation."""
|
|
66
|
-
move_loss_rate: float = field(default=1e-6, kw_only=True)
|
|
67
|
-
"""The error rate e (prob/microsecond) for a loss during a move operation."""
|
|
68
|
-
|
|
69
|
-
pick_px: float = field(default=1e-3, kw_only=True)
|
|
70
|
-
"""The error rate (prob per pick operation) for a Pauli-X error during a pick operation."""
|
|
71
|
-
pick_py: float = field(default=1e-3, kw_only=True)
|
|
72
|
-
"""The error rate (prob per pick operation) for a Pauli-Y error during a pick operation."""
|
|
73
|
-
pick_pz: float = field(default=1e-3, kw_only=True)
|
|
74
|
-
"""The error rate (prob per pick operation) for a Pauli-Z error during a pick operation."""
|
|
75
|
-
pick_loss_prob: float = field(default=1e-4, kw_only=True)
|
|
76
|
-
"""The error rate for a loss during a pick operation."""
|
|
77
|
-
|
|
78
|
-
move_speed: float = field(default=5e-1, kw_only=True)
|
|
79
|
-
"""Maximum speed of the qubits during a move operation."""
|
|
80
|
-
storage_spacing: float = field(default=4.0, kw_only=True)
|
|
81
|
-
"""Spacing between the qubits in the storage zone."""
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
@dataclass
|
|
85
|
-
class MoveNoiseModelABC(abc.ABC):
|
|
86
|
-
"""Abstract base class for noise based on atom movement.
|
|
87
|
-
|
|
88
|
-
This class defines the interface for a noise model. The gate noise is calculated form the parameters
|
|
89
|
-
provided in this dataclass which can be updated when inheriting from this class. The move error is
|
|
90
|
-
calculated by implementing the parallel_cz_errors method which takes a set of ctrl and qarg qubits
|
|
91
|
-
and returns a noise model for all the qubits. The noise model is a dictionary with the keys being the
|
|
92
|
-
error rates for the qubits and the values being the list of qubits that the error rate applies to.
|
|
93
|
-
|
|
94
|
-
Once implemented the class can be used with the NoisePass to analyze a circuit and apply the noise
|
|
95
|
-
model to the circuit.
|
|
96
|
-
|
|
97
|
-
NOTE: This model is not guaranteed to be supported long-term in bloqade. We will be
|
|
98
|
-
moving towards a more general approach to noise modeling in the future.
|
|
99
|
-
|
|
100
|
-
"""
|
|
101
|
-
|
|
102
|
-
params: MoveNoiseParams = field(default_factory=MoveNoiseParams)
|
|
103
|
-
"""Parameters for calculating move noise."""
|
|
104
|
-
|
|
105
|
-
@abc.abstractmethod
|
|
106
|
-
def parallel_cz_errors(
|
|
107
|
-
self, ctrls: List[int], qargs: List[int], rest: List[int]
|
|
108
|
-
) -> Dict[Tuple[float, float, float, float], List[int]]:
|
|
109
|
-
"""Takes a set of ctrls and qargs and returns a noise model for all qubits."""
|
|
110
|
-
pass
|
|
111
|
-
|
|
112
|
-
@staticmethod
|
|
113
|
-
def poisson_pauli_prob(rate: float, duration: float) -> float:
|
|
114
|
-
"""Calculate the number of noise events and their probabilities for a given rate and duration."""
|
|
115
|
-
assert duration >= 0, "Duration must be non-negative"
|
|
116
|
-
assert rate >= 0, "Rate must be non-negative"
|
|
117
|
-
return 0.5 * (1 - math.exp(-2 * rate * duration))
|
|
118
|
-
|
|
119
|
-
@classmethod
|
|
120
|
-
def join_binary_probs(cls, p1: float, *args: float) -> float:
|
|
121
|
-
"""Merge the probabilities of an event happening if the event can only happen once.
|
|
122
|
-
|
|
123
|
-
For example, finding the effective probability of losing an atom from multiple sources, since
|
|
124
|
-
a qubit can only happen once. This is done by using the formula:
|
|
125
|
-
|
|
126
|
-
p = p1 * (1 - p2) + p2 * (1 - p1)
|
|
127
|
-
|
|
128
|
-
applied recursively to all the probabilities in the list.
|
|
129
|
-
|
|
130
|
-
Args:
|
|
131
|
-
p1 (float): The probability of the event happening.
|
|
132
|
-
arg (float): The probabilities of the event happening from other sources.
|
|
133
|
-
|
|
134
|
-
Returns:
|
|
135
|
-
float: The effective probability of the event happening.
|
|
136
|
-
|
|
137
|
-
"""
|
|
138
|
-
if len(args) == 0:
|
|
139
|
-
return p1
|
|
140
|
-
else:
|
|
141
|
-
p2 = cls.join_binary_probs(*args)
|
|
142
|
-
return p1 * (1 - p2) + p2 * (1 - p1)
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
@dataclass
|
|
146
|
-
class TwoRowZoneModel(MoveNoiseModelABC):
|
|
147
|
-
"""This model assumes that the qubits are arranged in a single storage row with a row corresponding to a gate zone below it.
|
|
148
|
-
|
|
149
|
-
The CZ gate noise is calculated using the following heuristic: The idle error is calculated by the total duration require
|
|
150
|
-
to do the move and entable the qubits. Not every pair can be entangled at the same time, so we first deconflict the qargs
|
|
151
|
-
assuming by finding subsets in which both the ctrl and the qarg qubits are in ascending order. This breaks the pairs into
|
|
152
|
-
groups that can be moved and entangled separately. We then take each group and assign each pair to a gate zone slot. The
|
|
153
|
-
slots are allocated by starting from the middle of the atoms and moving outwards making sure to keep the ctrl qubits in
|
|
154
|
-
ascending order. The time to move a group is calculated by finding the maximum travel distance of the qarg and ctrl qubits
|
|
155
|
-
and dviding by the move speed. The total move time is the sum of all the group move times. The error rate for all the qubits
|
|
156
|
-
is then calculated by using the poisson_pauli_prob function. An additional error for the pick operation is calculated by
|
|
157
|
-
joining the binary probabilities of the pick operation and the move operation.
|
|
158
|
-
|
|
159
|
-
"""
|
|
160
|
-
|
|
161
|
-
gate_zone_y_offset: float = 20.0
|
|
162
|
-
gate_spacing: float = 20.0
|
|
163
|
-
|
|
164
|
-
def deconflict(
|
|
165
|
-
self, ctrls: List[int], qargs: List[int]
|
|
166
|
-
) -> List[Tuple[Tuple[int, ...], Tuple[int, ...]]]:
|
|
167
|
-
"""Return a list of groups of ctrl and qarg qubits that can be moved and entangled separately."""
|
|
168
|
-
# sort by ctrl qubit first to guarantee that they will be in ascending order
|
|
169
|
-
sorted_pairs = sorted(zip(ctrls, qargs))
|
|
170
|
-
|
|
171
|
-
groups = []
|
|
172
|
-
# group by qarg only putting it in a group if the qarg is greater than the last qarg in the group
|
|
173
|
-
# thus ensuring that the qargs are in ascending order
|
|
174
|
-
while len(sorted_pairs) > 0:
|
|
175
|
-
ctrl, qarg = sorted_pairs.pop(0)
|
|
176
|
-
|
|
177
|
-
found = False
|
|
178
|
-
for group in groups:
|
|
179
|
-
if group[-1][1] < qarg:
|
|
180
|
-
group.append((ctrl, qarg))
|
|
181
|
-
found = True
|
|
182
|
-
break
|
|
183
|
-
if not found:
|
|
184
|
-
groups.append([(ctrl, qarg)])
|
|
185
|
-
|
|
186
|
-
return [tuple(zip(*group)) for group in groups]
|
|
187
|
-
|
|
188
|
-
def assign_gate_slots(
|
|
189
|
-
self, ctrls: Sequence[int], qargs: Sequence[int]
|
|
190
|
-
) -> Dict[int, Tuple[int, int]]:
|
|
191
|
-
"""Allocate slots for the qubits to move to. start from middle of atoms and move outwards
|
|
192
|
-
making sure to keep the ctrl qubits in ascending order.
|
|
193
|
-
|
|
194
|
-
Note that we can do this because the move strategy is to move the ctrl qubits separately
|
|
195
|
-
from the qarg qubits, thus we don't have to worry about qarg qubits crossing the ctrl qubits
|
|
196
|
-
and vice versa. We pick the median of all the atoms because it distributes the qubits
|
|
197
|
-
as evenly as possible over the gate zone.
|
|
198
|
-
|
|
199
|
-
"""
|
|
200
|
-
assert len(ctrls) == len(qargs), "Number of ctrls and qargs must be equal"
|
|
201
|
-
addr_pairs = sorted(zip(ctrls, qargs), key=lambda x: x[0])
|
|
202
|
-
# sort by the distance between the ctrl and qarg qubits
|
|
203
|
-
|
|
204
|
-
ctrls, qargs = list(zip(*addr_pairs))
|
|
205
|
-
|
|
206
|
-
n_ctrls = len(ctrls)
|
|
207
|
-
|
|
208
|
-
ctrl_median = (
|
|
209
|
-
ctrls[n_ctrls // 2]
|
|
210
|
-
if n_ctrls % 2 == 1
|
|
211
|
-
else (ctrls[n_ctrls // 2 - 1] + ctrls[n_ctrls // 2]) / 2
|
|
212
|
-
)
|
|
213
|
-
|
|
214
|
-
all_addr = sorted(ctrls + qargs)
|
|
215
|
-
spatial_median = self.params.storage_spacing * (all_addr[0] + all_addr[-1]) / 2
|
|
216
|
-
|
|
217
|
-
addr_pairs.sort(key=lambda x: abs(x[0] - ctrl_median))
|
|
218
|
-
|
|
219
|
-
slots = {}
|
|
220
|
-
med_slot = round(spatial_median / self.gate_spacing)
|
|
221
|
-
|
|
222
|
-
left_slot = med_slot
|
|
223
|
-
right_slot = med_slot
|
|
224
|
-
slots[med_slot] = addr_pairs.pop(0)
|
|
225
|
-
while addr_pairs:
|
|
226
|
-
ctrl, qarg = addr_pairs.pop(0)
|
|
227
|
-
|
|
228
|
-
if ctrl < ctrl_median:
|
|
229
|
-
slots[left_slot := left_slot - 1] = (ctrl, qarg)
|
|
230
|
-
else:
|
|
231
|
-
slots[right_slot := right_slot + 1] = (ctrl, qarg)
|
|
232
|
-
|
|
233
|
-
return slots
|
|
234
|
-
|
|
235
|
-
def calculate_move_duration(self, slots: Dict[int, Tuple[int, int]]) -> float:
|
|
236
|
-
"""Calculate the time it takes to move the qubits from the ctrl to the qarg qubits."""
|
|
237
|
-
|
|
238
|
-
qarg_x_distance = float("-inf")
|
|
239
|
-
ctrl_x_distance = float("-inf")
|
|
240
|
-
|
|
241
|
-
for slot, (ctrl, qarg) in slots.items():
|
|
242
|
-
qarg_x_distance = max(
|
|
243
|
-
qarg_x_distance,
|
|
244
|
-
abs(qarg * self.params.storage_spacing - slot * self.gate_spacing),
|
|
245
|
-
)
|
|
246
|
-
ctrl_x_distance = max(
|
|
247
|
-
ctrl_x_distance,
|
|
248
|
-
abs(ctrl * self.params.storage_spacing - slot * self.gate_spacing),
|
|
249
|
-
)
|
|
250
|
-
|
|
251
|
-
qarg_max_distance = math.sqrt(qarg_x_distance**2 + self.gate_zone_y_offset**2)
|
|
252
|
-
ctrl_max_distance = math.sqrt(
|
|
253
|
-
ctrl_x_distance**2 + (self.gate_zone_y_offset - 3) ** 2
|
|
254
|
-
)
|
|
255
|
-
|
|
256
|
-
return (qarg_max_distance + ctrl_max_distance) / self.params.move_speed
|
|
257
|
-
|
|
258
|
-
def parallel_cz_errors(
|
|
259
|
-
self, ctrls: List[int], qargs: List[int], rest: List[int]
|
|
260
|
-
) -> Dict[Tuple[float, float, float, float], List[int]]:
|
|
261
|
-
"""Apply parallel gates by moving ctrl qubits to qarg qubits."""
|
|
262
|
-
groups = self.deconflict(ctrls, qargs)
|
|
263
|
-
slots = [self.assign_gate_slots(*group) for group in groups]
|
|
264
|
-
|
|
265
|
-
move_duration = sum(map(self.calculate_move_duration, slots))
|
|
266
|
-
|
|
267
|
-
px_time = self.poisson_pauli_prob(self.params.move_px_rate, move_duration)
|
|
268
|
-
py_time = self.poisson_pauli_prob(self.params.move_py_rate, move_duration)
|
|
269
|
-
px_time = self.poisson_pauli_prob(self.params.move_pz_rate, move_duration)
|
|
270
|
-
move_p_loss_time = self.poisson_pauli_prob(
|
|
271
|
-
self.params.move_loss_rate, move_duration
|
|
272
|
-
)
|
|
273
|
-
|
|
274
|
-
errors = {(px_time, py_time, px_time, move_p_loss_time): rest}
|
|
275
|
-
|
|
276
|
-
px_moved = self.join_binary_probs(self.params.pick_px, px_time)
|
|
277
|
-
py_moved = self.join_binary_probs(self.params.pick_py, py_time)
|
|
278
|
-
pz_moved = self.join_binary_probs(self.params.pick_pz, px_time)
|
|
279
|
-
p_loss_moved = self.join_binary_probs(
|
|
280
|
-
self.params.pick_loss_prob, move_p_loss_time
|
|
281
|
-
)
|
|
282
|
-
|
|
283
|
-
errors[(px_moved, py_moved, pz_moved, p_loss_moved)] = sorted(ctrls + qargs)
|
|
284
|
-
|
|
285
|
-
return errors
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
@dataclass
|
|
289
|
-
class SingleZoneLayoutABC(MoveNoiseModelABC):
|
|
290
|
-
gate_noise_params: GateNoiseParams = field(
|
|
291
|
-
default_factory=GateNoiseParams, kw_only=True
|
|
292
|
-
)
|
|
293
|
-
|
|
294
|
-
@abc.abstractmethod
|
|
295
|
-
def calculate_move_duration(self, ctrls: List[int], qargs: List[int]) -> float:
|
|
296
|
-
"""Calculate the time it takes to reconfigure the atom for executing the CZ gates."""
|
|
297
|
-
|
|
298
|
-
def parallel_cz_errors(
|
|
299
|
-
self, ctrls: List[int], qargs: List[int], rest: List[int]
|
|
300
|
-
) -> Dict[Tuple[float, float, float, float], List[int]]:
|
|
301
|
-
"""Apply parallel gates by moving ctrl qubits to qarg qubits."""
|
|
302
|
-
|
|
303
|
-
move_duration = self.calculate_move_duration(ctrls, qargs)
|
|
304
|
-
|
|
305
|
-
# idle errors during atom moves
|
|
306
|
-
idle_px_time = self.poisson_pauli_prob(self.params.idle_px_rate, move_duration)
|
|
307
|
-
idle_py_time = self.poisson_pauli_prob(self.params.idle_py_rate, move_duration)
|
|
308
|
-
idle_pz_time = self.poisson_pauli_prob(self.params.idle_pz_rate, move_duration)
|
|
309
|
-
idle_p_loss_time = self.poisson_pauli_prob(
|
|
310
|
-
self.params.idle_loss_rate, move_duration
|
|
311
|
-
)
|
|
312
|
-
|
|
313
|
-
# even qubits not involved in the gate can still experience unpaired errors
|
|
314
|
-
idle_px = self.join_binary_probs(
|
|
315
|
-
self.gate_noise_params.cz_unpaired_gate_px, idle_px_time
|
|
316
|
-
)
|
|
317
|
-
idle_py = self.join_binary_probs(
|
|
318
|
-
self.gate_noise_params.cz_unpaired_gate_py, idle_py_time
|
|
319
|
-
)
|
|
320
|
-
idle_pz = self.join_binary_probs(
|
|
321
|
-
self.gate_noise_params.cz_unpaired_gate_pz, idle_pz_time
|
|
322
|
-
)
|
|
323
|
-
idle_p_loss = self.join_binary_probs(
|
|
324
|
-
self.gate_noise_params.cz_unpaired_loss_prob, idle_p_loss_time
|
|
325
|
-
)
|
|
326
|
-
|
|
327
|
-
errors = {(idle_px, idle_py, idle_pz, idle_p_loss): rest}
|
|
328
|
-
|
|
329
|
-
# error during the move
|
|
330
|
-
move_px_time = self.poisson_pauli_prob(self.params.move_px_rate, move_duration)
|
|
331
|
-
move_py_time = self.poisson_pauli_prob(self.params.move_py_rate, move_duration)
|
|
332
|
-
move_pz_time = self.poisson_pauli_prob(self.params.move_pz_rate, move_duration)
|
|
333
|
-
move_p_loss_time = self.poisson_pauli_prob(
|
|
334
|
-
self.params.move_loss_rate, move_duration
|
|
335
|
-
)
|
|
336
|
-
# error coming from picking up the qubits
|
|
337
|
-
px_moved = self.join_binary_probs(self.params.pick_px, move_px_time)
|
|
338
|
-
py_moved = self.join_binary_probs(self.params.pick_py, move_py_time)
|
|
339
|
-
pz_moved = self.join_binary_probs(self.params.pick_pz, move_pz_time)
|
|
340
|
-
p_loss_moved = self.join_binary_probs(
|
|
341
|
-
self.params.pick_loss_prob, move_p_loss_time
|
|
342
|
-
)
|
|
343
|
-
|
|
344
|
-
errors[(px_moved, py_moved, pz_moved, p_loss_moved)] = sorted(ctrls + qargs)
|
|
345
|
-
|
|
346
|
-
return errors
|
bloqade/qasm2/dialects/noise.py
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
from kirin import ir, types, lowering
|
|
2
|
-
from kirin.decl import info, statement
|
|
3
|
-
|
|
4
|
-
from bloqade.qasm2.types import QubitType
|
|
5
|
-
|
|
6
|
-
dialect = ir.Dialect("qasm2.noise")
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
@statement(dialect=dialect)
|
|
10
|
-
class Pauli1(ir.Statement):
|
|
11
|
-
name = "pauli_1"
|
|
12
|
-
traits = frozenset({lowering.FromPythonCall()})
|
|
13
|
-
px: ir.SSAValue = info.argument(types.Float)
|
|
14
|
-
py: ir.SSAValue = info.argument(types.Float)
|
|
15
|
-
pz: ir.SSAValue = info.argument(types.Float)
|
|
16
|
-
qarg: ir.SSAValue = info.argument(QubitType)
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
from kirin import ir, types
|
|
2
|
-
from kirin.dialects import ilist
|
|
3
|
-
from kirin.rewrite.abc import RewriteRule, RewriteResult
|
|
4
|
-
|
|
5
|
-
from bloqade.squin.qubit import QubitType, MeasureAny, MeasureQubit, MeasureQubitList
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
class MeasureDesugarRule(RewriteRule):
|
|
9
|
-
"""
|
|
10
|
-
Desugar measure operations in the circuit.
|
|
11
|
-
"""
|
|
12
|
-
|
|
13
|
-
def rewrite_Statement(self, node: ir.Statement) -> RewriteResult:
|
|
14
|
-
|
|
15
|
-
if not isinstance(node, MeasureAny):
|
|
16
|
-
return RewriteResult()
|
|
17
|
-
|
|
18
|
-
if node.input.type.is_subseteq(QubitType):
|
|
19
|
-
node.replace_by(
|
|
20
|
-
MeasureQubit(
|
|
21
|
-
qubit=node.input,
|
|
22
|
-
)
|
|
23
|
-
)
|
|
24
|
-
return RewriteResult(has_done_something=True)
|
|
25
|
-
elif node.input.type.is_subseteq(ilist.IListType[QubitType, types.Any]):
|
|
26
|
-
node.replace_by(
|
|
27
|
-
MeasureQubitList(
|
|
28
|
-
qubits=node.input,
|
|
29
|
-
)
|
|
30
|
-
)
|
|
31
|
-
return RewriteResult(has_done_something=True)
|
|
32
|
-
|
|
33
|
-
return RewriteResult()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|