emlint 0.1.0__tar.gz
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.
- emlint-0.1.0/PKG-INFO +314 -0
- emlint-0.1.0/README.md +298 -0
- emlint-0.1.0/emlint/__init__.py +74 -0
- emlint-0.1.0/emlint/checks.py +360 -0
- emlint-0.1.0/emlint/cli.py +108 -0
- emlint-0.1.0/emlint/frontends.py +51 -0
- emlint-0.1.0/emlint/model.py +23 -0
- emlint-0.1.0/emlint/report.py +68 -0
- emlint-0.1.0/emlint.egg-info/PKG-INFO +314 -0
- emlint-0.1.0/emlint.egg-info/SOURCES.txt +24 -0
- emlint-0.1.0/emlint.egg-info/dependency_links.txt +1 -0
- emlint-0.1.0/emlint.egg-info/entry_points.txt +2 -0
- emlint-0.1.0/emlint.egg-info/requires.txt +10 -0
- emlint-0.1.0/emlint.egg-info/top_level.txt +1 -0
- emlint-0.1.0/pyproject.toml +36 -0
- emlint-0.1.0/setup.cfg +4 -0
- emlint-0.1.0/tests/test_check_correctability.py +216 -0
- emlint-0.1.0/tests/test_check_detectability.py +118 -0
- emlint-0.1.0/tests/test_check_duplicates.py +193 -0
- emlint-0.1.0/tests/test_check_observable_coverage.py +154 -0
- emlint-0.1.0/tests/test_check_probability_bounds.py +130 -0
- emlint-0.1.0/tests/test_check_sensitivity.py +167 -0
- emlint-0.1.0/tests/test_cli.py +171 -0
- emlint-0.1.0/tests/test_frontend.py +137 -0
- emlint-0.1.0/tests/test_report.py +178 -0
- emlint-0.1.0/tests/test_stim_integration.py +359 -0
emlint-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: emlint
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A static analysis tool for quantum error correction
|
|
5
|
+
License: Apache-2.0
|
|
6
|
+
Requires-Python: >=3.10
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
Requires-Dist: stim<3.0,>=1.14
|
|
9
|
+
Provides-Extra: dev
|
|
10
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
11
|
+
Requires-Dist: hypothesis>=6.50; extra == "dev"
|
|
12
|
+
Provides-Extra: benchmark
|
|
13
|
+
Requires-Dist: pytest>=7.0; extra == "benchmark"
|
|
14
|
+
Requires-Dist: hypothesis>=6.50; extra == "benchmark"
|
|
15
|
+
Requires-Dist: qldpc; extra == "benchmark"
|
|
16
|
+
|
|
17
|
+
# emlint
|
|
18
|
+
|
|
19
|
+
[](https://github.com/MathysRennela/dem-linter/actions/workflows/emlint.yml)
|
|
20
|
+
[](https://pypi.org/project/emlint/)
|
|
21
|
+
|
|
22
|
+
**stim simulates. sinter samples. emlint verifies.**
|
|
23
|
+
|
|
24
|
+
emlint is a static linter for Detector Error Models (DEMs). A DEM describes
|
|
25
|
+
a circuit's noise as a list of *error mechanisms* — independent faults, each
|
|
26
|
+
with a probability and a syndrome footprint: which detectors it fires and which
|
|
27
|
+
logical observables it flips. It catches structural bugs in milliseconds — before
|
|
28
|
+
you run a single shot.
|
|
29
|
+
|
|
30
|
+
## The problem
|
|
31
|
+
|
|
32
|
+
A `DETECTOR` instruction omitted in round 2 of a d=5 surface code leaves
|
|
33
|
+
detector D17 wired to nothing. The decoder silently miscorrects. The logical
|
|
34
|
+
error rate rises. The bug is invisible until ~10⁶ Sinter shots (≈45 minutes
|
|
35
|
+
on a standard laptop).
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
$ emlint check examples/buggy.dem
|
|
39
|
+
|
|
40
|
+
Detectors: 24 Observables: 1 Error mechanisms: 35
|
|
41
|
+
|
|
42
|
+
✓ detectability: All error mechanisms that flip observables also trigger detectors.
|
|
43
|
+
✗ sensitivity: 1 detector(s) are never triggered by any error mechanism.
|
|
44
|
+
Counter-example: Detector(s) not triggered by any error mechanism: D17
|
|
45
|
+
✓ observable_coverage: All declared observables are flipped by at least one error mechanism.
|
|
46
|
+
✓ probability_bounds: All error probabilities are within (0, 0.5].
|
|
47
|
+
✓ duplicates: No duplicate error mechanisms found.
|
|
48
|
+
✓ correctability: All syndromes map to a unique observable set.
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
2ms. One line. No simulation. D17 carries coordinates `(1, 0, 2)` — round 2,
|
|
52
|
+
position (1, 0) — so you know exactly where in the circuit to look.
|
|
53
|
+
|
|
54
|
+
```
|
|
55
|
+
$ emlint check examples/fixed.dem
|
|
56
|
+
|
|
57
|
+
✓ detectability ✓ sensitivity ✓ observable_coverage
|
|
58
|
+
✓ probability_bounds ✓ duplicates ✓ correctability
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Installation
|
|
62
|
+
|
|
63
|
+
```
|
|
64
|
+
pip install emlint
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Usage
|
|
68
|
+
|
|
69
|
+
### CLI
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
emlint check path/to/circuit.dem
|
|
73
|
+
emlint check path/to/circuit.dem --format json
|
|
74
|
+
emlint check path/to/circuit.dem --check detectability,sensitivity
|
|
75
|
+
emlint check path/to/circuit.dem --severity error
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Exit code `0` when all checks pass. Exit code `1` when any `error`-severity
|
|
79
|
+
check fails. Exit code `2` when there are warnings but no errors (usable in CI
|
|
80
|
+
to optionally escalate warnings without breaking the build).
|
|
81
|
+
|
|
82
|
+
`--severity error` suppresses `warning`-severity findings entirely — only
|
|
83
|
+
`error`-severity violations appear in output and affect the exit code. Useful
|
|
84
|
+
in CI pipelines where warnings are acknowledged but should not break the build.
|
|
85
|
+
|
|
86
|
+
### Python API
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
import stim
|
|
90
|
+
import emlint
|
|
91
|
+
|
|
92
|
+
circuit = stim.Circuit.generated(
|
|
93
|
+
"surface_code:rotated_memory_z",
|
|
94
|
+
rounds=3,
|
|
95
|
+
distance=5,
|
|
96
|
+
after_clifford_depolarization=0.001,
|
|
97
|
+
)
|
|
98
|
+
report = emlint.check(circuit.detector_error_model(decompose_errors=True))
|
|
99
|
+
print(emlint.format_text(report))
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
`emlint.check()` also accepts a `pathlib.Path` or a raw DEM string.
|
|
103
|
+
|
|
104
|
+
### CI integration
|
|
105
|
+
|
|
106
|
+
Add to `.github/workflows/qec.yml`:
|
|
107
|
+
|
|
108
|
+
```yaml
|
|
109
|
+
- name: Lint DEM
|
|
110
|
+
run: pip install emlint && emlint check circuit.dem
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Checks
|
|
114
|
+
|
|
115
|
+
| Check | What it catches | Severity |
|
|
116
|
+
|---|---|---|
|
|
117
|
+
| `detectability` | Errors that flip observables but trigger no detectors (undetectable) | error |
|
|
118
|
+
| `sensitivity` | Detectors never triggered by any error mechanism (dead detectors) | warning |
|
|
119
|
+
| `observable_coverage` | Logical observables never flipped by any error mechanism | error |
|
|
120
|
+
| `probability_bounds` | Error probabilities outside `(0, 0.5]` | error |
|
|
121
|
+
| `duplicates` | Error mechanisms with identical (detector, observable) signatures | warning |
|
|
122
|
+
| `correctability` | Syndromes mapping to multiple distinct observable sets | warning |
|
|
123
|
+
|
|
124
|
+
All checks operate on the standalone `.dem` file — no original circuit required.
|
|
125
|
+
Each failing check produces a counter-example pointing to the specific mechanism
|
|
126
|
+
or detector at fault.
|
|
127
|
+
|
|
128
|
+
## Connecting a failed check to the circuit bug
|
|
129
|
+
|
|
130
|
+
When a check fails, the counter-example tells you *where* in the DEM the problem
|
|
131
|
+
is. The table below tells you *what* circuit-level mistake most likely produced it
|
|
132
|
+
and where to look in your circuit source.
|
|
133
|
+
|
|
134
|
+
### `detectability` fails
|
|
135
|
+
|
|
136
|
+
> `error(0.001) L0 — flips observable but triggers 0 detectors`
|
|
137
|
+
|
|
138
|
+
The listed mechanism flips a logical observable but no detector fires — the
|
|
139
|
+
decoder has no syndrome signal to correct it.
|
|
140
|
+
|
|
141
|
+
**What went wrong in the circuit:**
|
|
142
|
+
- A `DETECTOR` instruction was omitted from a syndrome measurement round. The
|
|
143
|
+
round still runs and produces data, but no detector was wired to it.
|
|
144
|
+
- `OBSERVABLE_INCLUDE` targets a qubit that is outside the fault support of every
|
|
145
|
+
modelled error (wrong qubit index, wrong basis).
|
|
146
|
+
|
|
147
|
+
**Where to look:** search your circuit for the round that *should* cover the data
|
|
148
|
+
qubits referenced in the failing mechanism's observable. Check that every syndrome
|
|
149
|
+
extraction round ends with a `DETECTOR` pointing at the right ancilla measurement.
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
### `sensitivity` fails
|
|
154
|
+
|
|
155
|
+
> `D17@(1,0,2) not triggered by any error mechanism`
|
|
156
|
+
|
|
157
|
+
The listed detector is declared but no error mechanism ever fires it.
|
|
158
|
+
|
|
159
|
+
**What went wrong in the circuit:**
|
|
160
|
+
- The ancilla qubit for this detector is measuring in the wrong Pauli basis
|
|
161
|
+
(`X` vs `Z` mismatch), so the errors that *should* flip it pass through silently.
|
|
162
|
+
- The detector's coordinates point to the wrong spatial position — the qubit index
|
|
163
|
+
in `DETECTOR rec[…]` is off by one.
|
|
164
|
+
- A syndrome round was accidentally removed from the circuit, leaving its detector
|
|
165
|
+
declaration orphaned.
|
|
166
|
+
|
|
167
|
+
**Where to look:** the detector's coordinates (shown as `D17@(col,row,round)`)
|
|
168
|
+
identify the syndrome round and stabilizer position. Verify that the corresponding
|
|
169
|
+
ancilla qubit is connected to data qubits via the expected CNOT schedule, and that
|
|
170
|
+
the noise model includes errors on those CNOTs.
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
### `observable_coverage` fails
|
|
175
|
+
|
|
176
|
+
> `L1 not flipped by any error mechanism`
|
|
177
|
+
|
|
178
|
+
The listed logical observable is declared but no physical error can flip it.
|
|
179
|
+
|
|
180
|
+
**What went wrong in the circuit:**
|
|
181
|
+
- `OBSERVABLE_INCLUDE` on the wrong qubit or at the wrong point in the circuit
|
|
182
|
+
(e.g. applied to an ancilla instead of a data qubit, or after a reset that
|
|
183
|
+
erases the correlation).
|
|
184
|
+
- Observable index off-by-one in a multi-observable code.
|
|
185
|
+
|
|
186
|
+
**Where to look:** the counter-example gives you the observable index (e.g.
|
|
187
|
+
`L1`). Search your circuit source for every `OBSERVABLE_INCLUDE` with that
|
|
188
|
+
index. Verify that the qubit it references is part of the logical operator's
|
|
189
|
+
support and that errors on that qubit survive to the measurement record.
|
|
190
|
+
(`emlint check --format json` outputs counter-examples as structured data,
|
|
191
|
+
making it easy to script a targeted search when the circuit is auto-generated.)
|
|
192
|
+
|
|
193
|
+
---
|
|
194
|
+
|
|
195
|
+
### `probability_bounds` fails
|
|
196
|
+
|
|
197
|
+
> `error(0.0) D0 D1 — zero probability`
|
|
198
|
+
> `error(nan) D3 — NaN probability`
|
|
199
|
+
|
|
200
|
+
An error mechanism has a probability of exactly 0 (a no-op), is negative, or is
|
|
201
|
+
NaN — all of which indicate a fault in DEM generation, not a physical noise model.
|
|
202
|
+
|
|
203
|
+
**What went wrong in the circuit / DEM generation script:**
|
|
204
|
+
- Numerical underflow: a product of small probabilities rounded to 0 instead of
|
|
205
|
+
being pruned or clamped.
|
|
206
|
+
- Naive addition of two complementary probabilities exceeded 1, producing a
|
|
207
|
+
negative remainder.
|
|
208
|
+
- A copy-paste error in a manual DEM left a placeholder (`nan`, `-1`, `0`)
|
|
209
|
+
instead of a real probability.
|
|
210
|
+
|
|
211
|
+
**Where to look:** the mechanism's detector and observable targets identify which
|
|
212
|
+
fault path the DEM compiler was trying to express. Trace that fault path back to
|
|
213
|
+
the noise model parameters in your DEM generation script.
|
|
214
|
+
|
|
215
|
+
---
|
|
216
|
+
|
|
217
|
+
### `duplicates` fails
|
|
218
|
+
|
|
219
|
+
> `error(0.001, 0.001) share signature D3 D7; XOR-fused probability is 0.001998`
|
|
220
|
+
|
|
221
|
+
Two or more mechanisms share the same `(detectors, observables)` signature — the
|
|
222
|
+
same physical fault path is counted more than once.
|
|
223
|
+
|
|
224
|
+
**What went wrong in the circuit / DEM assembly:**
|
|
225
|
+
- Sub-circuit DEMs were concatenated (e.g. bulk + boundary + initialisation)
|
|
226
|
+
without merging mechanisms that touch the same fault path. The correct operation
|
|
227
|
+
is XOR-fusion: `p_eff = p1(1−p2) + p2(1−p1)`.
|
|
228
|
+
- An X error and a Y error on the same data qubit at a repetition code boundary
|
|
229
|
+
each trigger the same detector set and flip the same observable (legitimate
|
|
230
|
+
physics; use `--severity error` in CI to suppress this warning for known-correct
|
|
231
|
+
code families).
|
|
232
|
+
|
|
233
|
+
**Where to look:** if the duplicate arises from concatenation, find the boundary
|
|
234
|
+
between the sub-circuits where the mechanism originates. If you are manually
|
|
235
|
+
composing DEMs with Python, apply XOR-fusion instead of list concatenation.
|
|
236
|
+
|
|
237
|
+
---
|
|
238
|
+
|
|
239
|
+
### `correctability` fails
|
|
240
|
+
|
|
241
|
+
> `syndrome {D3 D7} maps to observable sets {L0}, {L1}`
|
|
242
|
+
|
|
243
|
+
The same detector syndrome is produced by mechanisms that flip *different*
|
|
244
|
+
observables — the decoder cannot determine the correct logical correction.
|
|
245
|
+
|
|
246
|
+
**What went wrong in the circuit:**
|
|
247
|
+
- Two physically distinct errors (e.g. an X error on qubit A and a Z error on
|
|
248
|
+
qubit B) produce the same syndrome but flip different logical observables. This
|
|
249
|
+
is a genuine code distance problem: the code cannot distinguish them.
|
|
250
|
+
- The DEM was generated with `decompose_errors=True`, which breaks hyperedge
|
|
251
|
+
mechanisms into sub-mechanisms that can create artificial syndrome collisions
|
|
252
|
+
(use `--severity error` to suppress this known artefact in CI).
|
|
253
|
+
- A degenerate code family (colour codes) has syndromes that legitimately map to
|
|
254
|
+
multiple valid logical corrections — this is an expected property, not a bug.
|
|
255
|
+
|
|
256
|
+
**Where to look:** the counter-example gives you the exact syndrome (e.g.
|
|
257
|
+
`{D3 D7}`) and the conflicting observable sets. Search your `.dem` file for
|
|
258
|
+
every `error(…)` line whose detector targets match that set — those are the two
|
|
259
|
+
colliding mechanisms. In the original circuit, find the gate locations
|
|
260
|
+
corresponding to each mechanism's targets (the detector coordinates annotate
|
|
261
|
+
the round and spatial position). If both locations are in the *same* Pauli
|
|
262
|
+
basis and the same round, this is likely a genuine distance-1 path. If they
|
|
263
|
+
are in different bases or rounds, look for a missing stabilizer measurement
|
|
264
|
+
or a mis-wired CNOT that merges two logically distinct fault paths.
|
|
265
|
+
|
|
266
|
+
**Scope note:** this check examines each mechanism *individually*. It does not
|
|
267
|
+
detect cases where two *co-occurring* faults combine to produce a syndrome that
|
|
268
|
+
maps to conflicting corrections — that is the code distance problem and is not
|
|
269
|
+
checked here. A future version will address multi-fault correctability via
|
|
270
|
+
compositional reasoning (pre/post-conditions on circuit segments).
|
|
271
|
+
|
|
272
|
+
## qLDPC & lifted-product codes
|
|
273
|
+
|
|
274
|
+
emlint accepts any DEM, including those generated from hypergraph product (HGP)
|
|
275
|
+
and lifted-product (Bivariate Bicycle) codes. Pass the DEM from any source:
|
|
276
|
+
|
|
277
|
+
```python
|
|
278
|
+
# From a qldpc-generated code
|
|
279
|
+
import qldpc, stim, emlint
|
|
280
|
+
|
|
281
|
+
classical = qldpc.codes.ClassicalCode.random(7, 5, seed=0)
|
|
282
|
+
code = qldpc.codes.HGPCode(classical)
|
|
283
|
+
noise = qldpc.circuits.DepolarizingNoiseModel(0.001)
|
|
284
|
+
circuit = qldpc.circuits.get_memory_experiment(code, num_rounds=5, noise_model=noise)
|
|
285
|
+
report = emlint.check(circuit.detector_error_model(decompose_errors=False))
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
The six structural checks apply universally — they do not assume surface code
|
|
289
|
+
topology and do not require knowledge of the underlying code family.
|
|
290
|
+
|
|
291
|
+
## Known false positives
|
|
292
|
+
|
|
293
|
+
**`correctability` with `decompose_errors=True`**
|
|
294
|
+
|
|
295
|
+
When a DEM is generated with `stim`'s `decompose_errors=True`, the hyperedge
|
|
296
|
+
decomposition can create sub-mechanism pairs that share the same detector set
|
|
297
|
+
but differ in observables — a syndrome collision that does not exist in the
|
|
298
|
+
original hyperedge model. The check fires at `warning` severity.
|
|
299
|
+
|
|
300
|
+
*Mitigation:* use `--severity error` in CI, or pass `decompose_errors=False`
|
|
301
|
+
to get a clean `correctability` result with no artefacts.
|
|
302
|
+
|
|
303
|
+
**`duplicates` at boundaries in degenerate code families**
|
|
304
|
+
|
|
305
|
+
Degenerate fault paths (e.g. X and Y errors at a repetition code boundary that
|
|
306
|
+
produce the same syndrome and flip the same observable) are correctly flagged as
|
|
307
|
+
duplicates. The warning is accurate — the XOR-fused probability is shown — but
|
|
308
|
+
may not require user action in degenerate code families.
|
|
309
|
+
|
|
310
|
+
*Mitigation:* use `--severity error` in CI to suppress.
|
|
311
|
+
|
|
312
|
+
## License
|
|
313
|
+
|
|
314
|
+
Apache 2.0
|
emlint-0.1.0/README.md
ADDED
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
# emlint
|
|
2
|
+
|
|
3
|
+
[](https://github.com/MathysRennela/dem-linter/actions/workflows/emlint.yml)
|
|
4
|
+
[](https://pypi.org/project/emlint/)
|
|
5
|
+
|
|
6
|
+
**stim simulates. sinter samples. emlint verifies.**
|
|
7
|
+
|
|
8
|
+
emlint is a static linter for Detector Error Models (DEMs). A DEM describes
|
|
9
|
+
a circuit's noise as a list of *error mechanisms* — independent faults, each
|
|
10
|
+
with a probability and a syndrome footprint: which detectors it fires and which
|
|
11
|
+
logical observables it flips. It catches structural bugs in milliseconds — before
|
|
12
|
+
you run a single shot.
|
|
13
|
+
|
|
14
|
+
## The problem
|
|
15
|
+
|
|
16
|
+
A `DETECTOR` instruction omitted in round 2 of a d=5 surface code leaves
|
|
17
|
+
detector D17 wired to nothing. The decoder silently miscorrects. The logical
|
|
18
|
+
error rate rises. The bug is invisible until ~10⁶ Sinter shots (≈45 minutes
|
|
19
|
+
on a standard laptop).
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
$ emlint check examples/buggy.dem
|
|
23
|
+
|
|
24
|
+
Detectors: 24 Observables: 1 Error mechanisms: 35
|
|
25
|
+
|
|
26
|
+
✓ detectability: All error mechanisms that flip observables also trigger detectors.
|
|
27
|
+
✗ sensitivity: 1 detector(s) are never triggered by any error mechanism.
|
|
28
|
+
Counter-example: Detector(s) not triggered by any error mechanism: D17
|
|
29
|
+
✓ observable_coverage: All declared observables are flipped by at least one error mechanism.
|
|
30
|
+
✓ probability_bounds: All error probabilities are within (0, 0.5].
|
|
31
|
+
✓ duplicates: No duplicate error mechanisms found.
|
|
32
|
+
✓ correctability: All syndromes map to a unique observable set.
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
2ms. One line. No simulation. D17 carries coordinates `(1, 0, 2)` — round 2,
|
|
36
|
+
position (1, 0) — so you know exactly where in the circuit to look.
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
$ emlint check examples/fixed.dem
|
|
40
|
+
|
|
41
|
+
✓ detectability ✓ sensitivity ✓ observable_coverage
|
|
42
|
+
✓ probability_bounds ✓ duplicates ✓ correctability
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Installation
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
pip install emlint
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Usage
|
|
52
|
+
|
|
53
|
+
### CLI
|
|
54
|
+
|
|
55
|
+
```
|
|
56
|
+
emlint check path/to/circuit.dem
|
|
57
|
+
emlint check path/to/circuit.dem --format json
|
|
58
|
+
emlint check path/to/circuit.dem --check detectability,sensitivity
|
|
59
|
+
emlint check path/to/circuit.dem --severity error
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Exit code `0` when all checks pass. Exit code `1` when any `error`-severity
|
|
63
|
+
check fails. Exit code `2` when there are warnings but no errors (usable in CI
|
|
64
|
+
to optionally escalate warnings without breaking the build).
|
|
65
|
+
|
|
66
|
+
`--severity error` suppresses `warning`-severity findings entirely — only
|
|
67
|
+
`error`-severity violations appear in output and affect the exit code. Useful
|
|
68
|
+
in CI pipelines where warnings are acknowledged but should not break the build.
|
|
69
|
+
|
|
70
|
+
### Python API
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
import stim
|
|
74
|
+
import emlint
|
|
75
|
+
|
|
76
|
+
circuit = stim.Circuit.generated(
|
|
77
|
+
"surface_code:rotated_memory_z",
|
|
78
|
+
rounds=3,
|
|
79
|
+
distance=5,
|
|
80
|
+
after_clifford_depolarization=0.001,
|
|
81
|
+
)
|
|
82
|
+
report = emlint.check(circuit.detector_error_model(decompose_errors=True))
|
|
83
|
+
print(emlint.format_text(report))
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
`emlint.check()` also accepts a `pathlib.Path` or a raw DEM string.
|
|
87
|
+
|
|
88
|
+
### CI integration
|
|
89
|
+
|
|
90
|
+
Add to `.github/workflows/qec.yml`:
|
|
91
|
+
|
|
92
|
+
```yaml
|
|
93
|
+
- name: Lint DEM
|
|
94
|
+
run: pip install emlint && emlint check circuit.dem
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Checks
|
|
98
|
+
|
|
99
|
+
| Check | What it catches | Severity |
|
|
100
|
+
|---|---|---|
|
|
101
|
+
| `detectability` | Errors that flip observables but trigger no detectors (undetectable) | error |
|
|
102
|
+
| `sensitivity` | Detectors never triggered by any error mechanism (dead detectors) | warning |
|
|
103
|
+
| `observable_coverage` | Logical observables never flipped by any error mechanism | error |
|
|
104
|
+
| `probability_bounds` | Error probabilities outside `(0, 0.5]` | error |
|
|
105
|
+
| `duplicates` | Error mechanisms with identical (detector, observable) signatures | warning |
|
|
106
|
+
| `correctability` | Syndromes mapping to multiple distinct observable sets | warning |
|
|
107
|
+
|
|
108
|
+
All checks operate on the standalone `.dem` file — no original circuit required.
|
|
109
|
+
Each failing check produces a counter-example pointing to the specific mechanism
|
|
110
|
+
or detector at fault.
|
|
111
|
+
|
|
112
|
+
## Connecting a failed check to the circuit bug
|
|
113
|
+
|
|
114
|
+
When a check fails, the counter-example tells you *where* in the DEM the problem
|
|
115
|
+
is. The table below tells you *what* circuit-level mistake most likely produced it
|
|
116
|
+
and where to look in your circuit source.
|
|
117
|
+
|
|
118
|
+
### `detectability` fails
|
|
119
|
+
|
|
120
|
+
> `error(0.001) L0 — flips observable but triggers 0 detectors`
|
|
121
|
+
|
|
122
|
+
The listed mechanism flips a logical observable but no detector fires — the
|
|
123
|
+
decoder has no syndrome signal to correct it.
|
|
124
|
+
|
|
125
|
+
**What went wrong in the circuit:**
|
|
126
|
+
- A `DETECTOR` instruction was omitted from a syndrome measurement round. The
|
|
127
|
+
round still runs and produces data, but no detector was wired to it.
|
|
128
|
+
- `OBSERVABLE_INCLUDE` targets a qubit that is outside the fault support of every
|
|
129
|
+
modelled error (wrong qubit index, wrong basis).
|
|
130
|
+
|
|
131
|
+
**Where to look:** search your circuit for the round that *should* cover the data
|
|
132
|
+
qubits referenced in the failing mechanism's observable. Check that every syndrome
|
|
133
|
+
extraction round ends with a `DETECTOR` pointing at the right ancilla measurement.
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
### `sensitivity` fails
|
|
138
|
+
|
|
139
|
+
> `D17@(1,0,2) not triggered by any error mechanism`
|
|
140
|
+
|
|
141
|
+
The listed detector is declared but no error mechanism ever fires it.
|
|
142
|
+
|
|
143
|
+
**What went wrong in the circuit:**
|
|
144
|
+
- The ancilla qubit for this detector is measuring in the wrong Pauli basis
|
|
145
|
+
(`X` vs `Z` mismatch), so the errors that *should* flip it pass through silently.
|
|
146
|
+
- The detector's coordinates point to the wrong spatial position — the qubit index
|
|
147
|
+
in `DETECTOR rec[…]` is off by one.
|
|
148
|
+
- A syndrome round was accidentally removed from the circuit, leaving its detector
|
|
149
|
+
declaration orphaned.
|
|
150
|
+
|
|
151
|
+
**Where to look:** the detector's coordinates (shown as `D17@(col,row,round)`)
|
|
152
|
+
identify the syndrome round and stabilizer position. Verify that the corresponding
|
|
153
|
+
ancilla qubit is connected to data qubits via the expected CNOT schedule, and that
|
|
154
|
+
the noise model includes errors on those CNOTs.
|
|
155
|
+
|
|
156
|
+
---
|
|
157
|
+
|
|
158
|
+
### `observable_coverage` fails
|
|
159
|
+
|
|
160
|
+
> `L1 not flipped by any error mechanism`
|
|
161
|
+
|
|
162
|
+
The listed logical observable is declared but no physical error can flip it.
|
|
163
|
+
|
|
164
|
+
**What went wrong in the circuit:**
|
|
165
|
+
- `OBSERVABLE_INCLUDE` on the wrong qubit or at the wrong point in the circuit
|
|
166
|
+
(e.g. applied to an ancilla instead of a data qubit, or after a reset that
|
|
167
|
+
erases the correlation).
|
|
168
|
+
- Observable index off-by-one in a multi-observable code.
|
|
169
|
+
|
|
170
|
+
**Where to look:** the counter-example gives you the observable index (e.g.
|
|
171
|
+
`L1`). Search your circuit source for every `OBSERVABLE_INCLUDE` with that
|
|
172
|
+
index. Verify that the qubit it references is part of the logical operator's
|
|
173
|
+
support and that errors on that qubit survive to the measurement record.
|
|
174
|
+
(`emlint check --format json` outputs counter-examples as structured data,
|
|
175
|
+
making it easy to script a targeted search when the circuit is auto-generated.)
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
### `probability_bounds` fails
|
|
180
|
+
|
|
181
|
+
> `error(0.0) D0 D1 — zero probability`
|
|
182
|
+
> `error(nan) D3 — NaN probability`
|
|
183
|
+
|
|
184
|
+
An error mechanism has a probability of exactly 0 (a no-op), is negative, or is
|
|
185
|
+
NaN — all of which indicate a fault in DEM generation, not a physical noise model.
|
|
186
|
+
|
|
187
|
+
**What went wrong in the circuit / DEM generation script:**
|
|
188
|
+
- Numerical underflow: a product of small probabilities rounded to 0 instead of
|
|
189
|
+
being pruned or clamped.
|
|
190
|
+
- Naive addition of two complementary probabilities exceeded 1, producing a
|
|
191
|
+
negative remainder.
|
|
192
|
+
- A copy-paste error in a manual DEM left a placeholder (`nan`, `-1`, `0`)
|
|
193
|
+
instead of a real probability.
|
|
194
|
+
|
|
195
|
+
**Where to look:** the mechanism's detector and observable targets identify which
|
|
196
|
+
fault path the DEM compiler was trying to express. Trace that fault path back to
|
|
197
|
+
the noise model parameters in your DEM generation script.
|
|
198
|
+
|
|
199
|
+
---
|
|
200
|
+
|
|
201
|
+
### `duplicates` fails
|
|
202
|
+
|
|
203
|
+
> `error(0.001, 0.001) share signature D3 D7; XOR-fused probability is 0.001998`
|
|
204
|
+
|
|
205
|
+
Two or more mechanisms share the same `(detectors, observables)` signature — the
|
|
206
|
+
same physical fault path is counted more than once.
|
|
207
|
+
|
|
208
|
+
**What went wrong in the circuit / DEM assembly:**
|
|
209
|
+
- Sub-circuit DEMs were concatenated (e.g. bulk + boundary + initialisation)
|
|
210
|
+
without merging mechanisms that touch the same fault path. The correct operation
|
|
211
|
+
is XOR-fusion: `p_eff = p1(1−p2) + p2(1−p1)`.
|
|
212
|
+
- An X error and a Y error on the same data qubit at a repetition code boundary
|
|
213
|
+
each trigger the same detector set and flip the same observable (legitimate
|
|
214
|
+
physics; use `--severity error` in CI to suppress this warning for known-correct
|
|
215
|
+
code families).
|
|
216
|
+
|
|
217
|
+
**Where to look:** if the duplicate arises from concatenation, find the boundary
|
|
218
|
+
between the sub-circuits where the mechanism originates. If you are manually
|
|
219
|
+
composing DEMs with Python, apply XOR-fusion instead of list concatenation.
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
### `correctability` fails
|
|
224
|
+
|
|
225
|
+
> `syndrome {D3 D7} maps to observable sets {L0}, {L1}`
|
|
226
|
+
|
|
227
|
+
The same detector syndrome is produced by mechanisms that flip *different*
|
|
228
|
+
observables — the decoder cannot determine the correct logical correction.
|
|
229
|
+
|
|
230
|
+
**What went wrong in the circuit:**
|
|
231
|
+
- Two physically distinct errors (e.g. an X error on qubit A and a Z error on
|
|
232
|
+
qubit B) produce the same syndrome but flip different logical observables. This
|
|
233
|
+
is a genuine code distance problem: the code cannot distinguish them.
|
|
234
|
+
- The DEM was generated with `decompose_errors=True`, which breaks hyperedge
|
|
235
|
+
mechanisms into sub-mechanisms that can create artificial syndrome collisions
|
|
236
|
+
(use `--severity error` to suppress this known artefact in CI).
|
|
237
|
+
- A degenerate code family (colour codes) has syndromes that legitimately map to
|
|
238
|
+
multiple valid logical corrections — this is an expected property, not a bug.
|
|
239
|
+
|
|
240
|
+
**Where to look:** the counter-example gives you the exact syndrome (e.g.
|
|
241
|
+
`{D3 D7}`) and the conflicting observable sets. Search your `.dem` file for
|
|
242
|
+
every `error(…)` line whose detector targets match that set — those are the two
|
|
243
|
+
colliding mechanisms. In the original circuit, find the gate locations
|
|
244
|
+
corresponding to each mechanism's targets (the detector coordinates annotate
|
|
245
|
+
the round and spatial position). If both locations are in the *same* Pauli
|
|
246
|
+
basis and the same round, this is likely a genuine distance-1 path. If they
|
|
247
|
+
are in different bases or rounds, look for a missing stabilizer measurement
|
|
248
|
+
or a mis-wired CNOT that merges two logically distinct fault paths.
|
|
249
|
+
|
|
250
|
+
**Scope note:** this check examines each mechanism *individually*. It does not
|
|
251
|
+
detect cases where two *co-occurring* faults combine to produce a syndrome that
|
|
252
|
+
maps to conflicting corrections — that is the code distance problem and is not
|
|
253
|
+
checked here. A future version will address multi-fault correctability via
|
|
254
|
+
compositional reasoning (pre/post-conditions on circuit segments).
|
|
255
|
+
|
|
256
|
+
## qLDPC & lifted-product codes
|
|
257
|
+
|
|
258
|
+
emlint accepts any DEM, including those generated from hypergraph product (HGP)
|
|
259
|
+
and lifted-product (Bivariate Bicycle) codes. Pass the DEM from any source:
|
|
260
|
+
|
|
261
|
+
```python
|
|
262
|
+
# From a qldpc-generated code
|
|
263
|
+
import qldpc, stim, emlint
|
|
264
|
+
|
|
265
|
+
classical = qldpc.codes.ClassicalCode.random(7, 5, seed=0)
|
|
266
|
+
code = qldpc.codes.HGPCode(classical)
|
|
267
|
+
noise = qldpc.circuits.DepolarizingNoiseModel(0.001)
|
|
268
|
+
circuit = qldpc.circuits.get_memory_experiment(code, num_rounds=5, noise_model=noise)
|
|
269
|
+
report = emlint.check(circuit.detector_error_model(decompose_errors=False))
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
The six structural checks apply universally — they do not assume surface code
|
|
273
|
+
topology and do not require knowledge of the underlying code family.
|
|
274
|
+
|
|
275
|
+
## Known false positives
|
|
276
|
+
|
|
277
|
+
**`correctability` with `decompose_errors=True`**
|
|
278
|
+
|
|
279
|
+
When a DEM is generated with `stim`'s `decompose_errors=True`, the hyperedge
|
|
280
|
+
decomposition can create sub-mechanism pairs that share the same detector set
|
|
281
|
+
but differ in observables — a syndrome collision that does not exist in the
|
|
282
|
+
original hyperedge model. The check fires at `warning` severity.
|
|
283
|
+
|
|
284
|
+
*Mitigation:* use `--severity error` in CI, or pass `decompose_errors=False`
|
|
285
|
+
to get a clean `correctability` result with no artefacts.
|
|
286
|
+
|
|
287
|
+
**`duplicates` at boundaries in degenerate code families**
|
|
288
|
+
|
|
289
|
+
Degenerate fault paths (e.g. X and Y errors at a repetition code boundary that
|
|
290
|
+
produce the same syndrome and flip the same observable) are correctly flagged as
|
|
291
|
+
duplicates. The warning is accurate — the XOR-fused probability is shown — but
|
|
292
|
+
may not require user action in degenerate code families.
|
|
293
|
+
|
|
294
|
+
*Mitigation:* use `--severity error` in CI to suppress.
|
|
295
|
+
|
|
296
|
+
## License
|
|
297
|
+
|
|
298
|
+
Apache 2.0
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
import stim
|
|
6
|
+
|
|
7
|
+
from emlint import frontends
|
|
8
|
+
from emlint.checks import ALL_CHECKS
|
|
9
|
+
from emlint.model import ErrorModel
|
|
10
|
+
from emlint.report import CheckFn, Report, format_json, format_text
|
|
11
|
+
|
|
12
|
+
__all__ = ["check", "ErrorModel", "Report", "CheckFn", "ALL_CHECKS", "format_text", "format_json"]
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def check(
|
|
16
|
+
source: stim.DetectorErrorModel | str | Path,
|
|
17
|
+
checks: dict[str, CheckFn] | None = None,
|
|
18
|
+
) -> Report:
|
|
19
|
+
"""Run checks against *source* and return a Report.
|
|
20
|
+
|
|
21
|
+
Parameters
|
|
22
|
+
----------
|
|
23
|
+
source:
|
|
24
|
+
A ``stim.DetectorErrorModel``, a ``pathlib.Path`` to a ``.dem`` file,
|
|
25
|
+
a string path to a ``.dem`` file, or a raw DEM string.
|
|
26
|
+
checks:
|
|
27
|
+
Dict of ``{name: check_fn}`` to run. Defaults to ``ALL_CHECKS``.
|
|
28
|
+
|
|
29
|
+
Examples
|
|
30
|
+
--------
|
|
31
|
+
::
|
|
32
|
+
|
|
33
|
+
report = emlint.check(stim.Circuit.generated(...).detector_error_model())
|
|
34
|
+
print(report.all_passed())
|
|
35
|
+
"""
|
|
36
|
+
if checks is None:
|
|
37
|
+
checks = ALL_CHECKS
|
|
38
|
+
|
|
39
|
+
if isinstance(source, stim.DetectorErrorModel):
|
|
40
|
+
dem = source
|
|
41
|
+
elif isinstance(source, Path):
|
|
42
|
+
text = source.read_text() # FileNotFoundError / PermissionError propagate
|
|
43
|
+
try:
|
|
44
|
+
dem = stim.DetectorErrorModel(text)
|
|
45
|
+
except Exception as exc:
|
|
46
|
+
raise ValueError(f"Failed to parse DEM: {exc}") from exc
|
|
47
|
+
elif isinstance(source, str):
|
|
48
|
+
path = Path(source)
|
|
49
|
+
if path.exists():
|
|
50
|
+
text = path.read_text() # PermissionError propagates
|
|
51
|
+
try:
|
|
52
|
+
dem = stim.DetectorErrorModel(text)
|
|
53
|
+
except Exception as exc:
|
|
54
|
+
raise ValueError(f"Failed to parse DEM: {exc}") from exc
|
|
55
|
+
else:
|
|
56
|
+
try:
|
|
57
|
+
dem = stim.DetectorErrorModel(source)
|
|
58
|
+
except Exception as exc:
|
|
59
|
+
raise ValueError(f"Failed to parse DEM: {exc}") from exc
|
|
60
|
+
else:
|
|
61
|
+
raise TypeError(
|
|
62
|
+
f"Unsupported source type {type(source).__name__}. "
|
|
63
|
+
"Pass a stim.DetectorErrorModel, a path to a .dem file, "
|
|
64
|
+
"or a raw DEM string."
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
model = frontends.from_stim_dem(dem)
|
|
68
|
+
results = [fn(model) for fn in checks.values()]
|
|
69
|
+
return Report(
|
|
70
|
+
results=results,
|
|
71
|
+
num_detectors=len(model.detectors),
|
|
72
|
+
num_observables=len(model.observables),
|
|
73
|
+
num_error_mechanisms=len(model.error_mechanisms),
|
|
74
|
+
)
|