qliff 0.0.1__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.
Files changed (49) hide show
  1. qliff-0.0.1/Cargo.lock +264 -0
  2. qliff-0.0.1/Cargo.toml +26 -0
  3. qliff-0.0.1/LICENSE +21 -0
  4. qliff-0.0.1/MANIFEST.in +6 -0
  5. qliff-0.0.1/PKG-INFO +171 -0
  6. qliff-0.0.1/README.md +126 -0
  7. qliff-0.0.1/qliff/__init__.py +18 -0
  8. qliff-0.0.1/qliff/__main__.py +3 -0
  9. qliff-0.0.1/qliff/_types.py +6 -0
  10. qliff-0.0.1/qliff/circuit.py +224 -0
  11. qliff-0.0.1/qliff/metrics.py +26 -0
  12. qliff-0.0.1/qliff/noise/__init__.py +26 -0
  13. qliff-0.0.1/qliff/noise/channel.py +332 -0
  14. qliff-0.0.1/qliff/noise/sampler.py +369 -0
  15. qliff-0.0.1/qliff/pauli.py +215 -0
  16. qliff-0.0.1/qliff/qec/__init__.py +32 -0
  17. qliff-0.0.1/qliff/qec/codes.py +491 -0
  18. qliff-0.0.1/qliff/qec/coherent.py +198 -0
  19. qliff-0.0.1/qliff/qec/color.py +395 -0
  20. qliff-0.0.1/qliff/qec/colordec.py +64 -0
  21. qliff-0.0.1/qliff/qec/decoder.py +314 -0
  22. qliff-0.0.1/qliff/qec/dem.py +194 -0
  23. qliff-0.0.1/qliff/qec/lattice.py +230 -0
  24. qliff-0.0.1/qliff/qec/registry.py +242 -0
  25. qliff-0.0.1/qliff/qec/sampler.py +126 -0
  26. qliff-0.0.1/qliff/qec/threshold.py +130 -0
  27. qliff-0.0.1/qliff/qec/tn.py +347 -0
  28. qliff-0.0.1/qliff/server/__init__.py +7 -0
  29. qliff-0.0.1/qliff/server/api.py +190 -0
  30. qliff-0.0.1/qliff/server/app.py +44 -0
  31. qliff-0.0.1/qliff/server/cli.py +54 -0
  32. qliff-0.0.1/qliff/server/run.py +350 -0
  33. qliff-0.0.1/qliff/server/schema.py +212 -0
  34. qliff-0.0.1/qliff/server/static/assets/index-CGvj6Qmy.js +12 -0
  35. qliff-0.0.1/qliff/server/static/assets/index-V0CxkPTj.css +1 -0
  36. qliff-0.0.1/qliff/server/static/assets/uPlot.esm-C-vmSHoy.js +3 -0
  37. qliff-0.0.1/qliff/server/static/index.html +25 -0
  38. qliff-0.0.1/qliff/simulator.py +235 -0
  39. qliff-0.0.1/qliff.egg-info/PKG-INFO +171 -0
  40. qliff-0.0.1/qliff.egg-info/SOURCES.txt +47 -0
  41. qliff-0.0.1/qliff.egg-info/dependency_links.txt +1 -0
  42. qliff-0.0.1/qliff.egg-info/entry_points.txt +2 -0
  43. qliff-0.0.1/qliff.egg-info/not-zip-safe +1 -0
  44. qliff-0.0.1/qliff.egg-info/requires.txt +17 -0
  45. qliff-0.0.1/qliff.egg-info/top_level.txt +1 -0
  46. qliff-0.0.1/setup.cfg +4 -0
  47. qliff-0.0.1/setup.py +81 -0
  48. qliff-0.0.1/src/lib.rs +14 -0
  49. qliff-0.0.1/src/tableau.rs +1375 -0
qliff-0.0.1/Cargo.lock ADDED
@@ -0,0 +1,264 @@
1
+ # This file is automatically @generated by Cargo.
2
+ # It is not intended for manual editing.
3
+ version = 4
4
+
5
+ [[package]]
6
+ name = "autocfg"
7
+ version = "1.5.1"
8
+ source = "registry+https://github.com/rust-lang/crates.io-index"
9
+ checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53"
10
+
11
+ [[package]]
12
+ name = "cc"
13
+ version = "1.2.67"
14
+ source = "registry+https://github.com/rust-lang/crates.io-index"
15
+ checksum = "e17dd265a7d0f31ef544e1b20e03add05d3b45b491b633b10d67145d2acc1a38"
16
+ dependencies = [
17
+ "find-msvc-tools",
18
+ "shlex",
19
+ ]
20
+
21
+ [[package]]
22
+ name = "cfg-if"
23
+ version = "1.0.4"
24
+ source = "registry+https://github.com/rust-lang/crates.io-index"
25
+ checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
26
+
27
+ [[package]]
28
+ name = "crossbeam-deque"
29
+ version = "0.8.6"
30
+ source = "registry+https://github.com/rust-lang/crates.io-index"
31
+ checksum = "9dd111b7b7f7d55b72c0a6ae361660ee5853c9af73f70c3c2ef6858b950e2e51"
32
+ dependencies = [
33
+ "crossbeam-epoch",
34
+ "crossbeam-utils",
35
+ ]
36
+
37
+ [[package]]
38
+ name = "crossbeam-epoch"
39
+ version = "0.9.18"
40
+ source = "registry+https://github.com/rust-lang/crates.io-index"
41
+ checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e"
42
+ dependencies = [
43
+ "crossbeam-utils",
44
+ ]
45
+
46
+ [[package]]
47
+ name = "crossbeam-utils"
48
+ version = "0.8.21"
49
+ source = "registry+https://github.com/rust-lang/crates.io-index"
50
+ checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28"
51
+
52
+ [[package]]
53
+ name = "either"
54
+ version = "1.16.0"
55
+ source = "registry+https://github.com/rust-lang/crates.io-index"
56
+ checksum = "91622ff5e7162018101f2fea40d6ebf4a78bbe5a49736a2020649edf9693679e"
57
+
58
+ [[package]]
59
+ name = "find-msvc-tools"
60
+ version = "0.1.9"
61
+ source = "registry+https://github.com/rust-lang/crates.io-index"
62
+ checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582"
63
+
64
+ [[package]]
65
+ name = "heck"
66
+ version = "0.5.0"
67
+ source = "registry+https://github.com/rust-lang/crates.io-index"
68
+ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
69
+
70
+ [[package]]
71
+ name = "indoc"
72
+ version = "2.0.7"
73
+ source = "registry+https://github.com/rust-lang/crates.io-index"
74
+ checksum = "79cf5c93f93228cf8efb3ba362535fb11199ac548a09ce117c9b1adc3030d706"
75
+ dependencies = [
76
+ "rustversion",
77
+ ]
78
+
79
+ [[package]]
80
+ name = "libc"
81
+ version = "0.2.186"
82
+ source = "registry+https://github.com/rust-lang/crates.io-index"
83
+ checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66"
84
+
85
+ [[package]]
86
+ name = "memoffset"
87
+ version = "0.9.1"
88
+ source = "registry+https://github.com/rust-lang/crates.io-index"
89
+ checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a"
90
+ dependencies = [
91
+ "autocfg",
92
+ ]
93
+
94
+ [[package]]
95
+ name = "once_cell"
96
+ version = "1.21.4"
97
+ source = "registry+https://github.com/rust-lang/crates.io-index"
98
+ checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
99
+
100
+ [[package]]
101
+ name = "portable-atomic"
102
+ version = "1.13.1"
103
+ source = "registry+https://github.com/rust-lang/crates.io-index"
104
+ checksum = "c33a9471896f1c69cecef8d20cbe2f7accd12527ce60845ff44c153bb2a21b49"
105
+
106
+ [[package]]
107
+ name = "proc-macro2"
108
+ version = "1.0.106"
109
+ source = "registry+https://github.com/rust-lang/crates.io-index"
110
+ checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934"
111
+ dependencies = [
112
+ "unicode-ident",
113
+ ]
114
+
115
+ [[package]]
116
+ name = "pyo3"
117
+ version = "0.23.5"
118
+ source = "registry+https://github.com/rust-lang/crates.io-index"
119
+ checksum = "7778bffd85cf38175ac1f545509665d0b9b92a198ca7941f131f85f7a4f9a872"
120
+ dependencies = [
121
+ "cfg-if",
122
+ "indoc",
123
+ "libc",
124
+ "memoffset",
125
+ "once_cell",
126
+ "portable-atomic",
127
+ "pyo3-build-config",
128
+ "pyo3-ffi",
129
+ "pyo3-macros",
130
+ "unindent",
131
+ ]
132
+
133
+ [[package]]
134
+ name = "pyo3-build-config"
135
+ version = "0.23.5"
136
+ source = "registry+https://github.com/rust-lang/crates.io-index"
137
+ checksum = "94f6cbe86ef3bf18998d9df6e0f3fc1050a8c5efa409bf712e661a4366e010fb"
138
+ dependencies = [
139
+ "once_cell",
140
+ "python3-dll-a",
141
+ "target-lexicon",
142
+ ]
143
+
144
+ [[package]]
145
+ name = "pyo3-ffi"
146
+ version = "0.23.5"
147
+ source = "registry+https://github.com/rust-lang/crates.io-index"
148
+ checksum = "e9f1b4c431c0bb1c8fb0a338709859eed0d030ff6daa34368d3b152a63dfdd8d"
149
+ dependencies = [
150
+ "libc",
151
+ "pyo3-build-config",
152
+ ]
153
+
154
+ [[package]]
155
+ name = "pyo3-macros"
156
+ version = "0.23.5"
157
+ source = "registry+https://github.com/rust-lang/crates.io-index"
158
+ checksum = "fbc2201328f63c4710f68abdf653c89d8dbc2858b88c5d88b0ff38a75288a9da"
159
+ dependencies = [
160
+ "proc-macro2",
161
+ "pyo3-macros-backend",
162
+ "quote",
163
+ "syn",
164
+ ]
165
+
166
+ [[package]]
167
+ name = "pyo3-macros-backend"
168
+ version = "0.23.5"
169
+ source = "registry+https://github.com/rust-lang/crates.io-index"
170
+ checksum = "fca6726ad0f3da9c9de093d6f116a93c1a38e417ed73bf138472cf4064f72028"
171
+ dependencies = [
172
+ "heck",
173
+ "proc-macro2",
174
+ "pyo3-build-config",
175
+ "quote",
176
+ "syn",
177
+ ]
178
+
179
+ [[package]]
180
+ name = "python3-dll-a"
181
+ version = "0.2.15"
182
+ source = "registry+https://github.com/rust-lang/crates.io-index"
183
+ checksum = "d80ba7540edb18890d444c5aa8e1f1f99b1bdf26fb26ae383135325f4a36042b"
184
+ dependencies = [
185
+ "cc",
186
+ ]
187
+
188
+ [[package]]
189
+ name = "qliff"
190
+ version = "0.0.1"
191
+ dependencies = [
192
+ "pyo3",
193
+ "rayon",
194
+ ]
195
+
196
+ [[package]]
197
+ name = "quote"
198
+ version = "1.0.45"
199
+ source = "registry+https://github.com/rust-lang/crates.io-index"
200
+ checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924"
201
+ dependencies = [
202
+ "proc-macro2",
203
+ ]
204
+
205
+ [[package]]
206
+ name = "rayon"
207
+ version = "1.12.0"
208
+ source = "registry+https://github.com/rust-lang/crates.io-index"
209
+ checksum = "fb39b166781f92d482534ef4b4b1b2568f42613b53e5b6c160e24cfbfa30926d"
210
+ dependencies = [
211
+ "either",
212
+ "rayon-core",
213
+ ]
214
+
215
+ [[package]]
216
+ name = "rayon-core"
217
+ version = "1.13.0"
218
+ source = "registry+https://github.com/rust-lang/crates.io-index"
219
+ checksum = "22e18b0f0062d30d4230b2e85ff77fdfe4326feb054b9783a3460d8435c8ab91"
220
+ dependencies = [
221
+ "crossbeam-deque",
222
+ "crossbeam-utils",
223
+ ]
224
+
225
+ [[package]]
226
+ name = "rustversion"
227
+ version = "1.0.22"
228
+ source = "registry+https://github.com/rust-lang/crates.io-index"
229
+ checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
230
+
231
+ [[package]]
232
+ name = "shlex"
233
+ version = "2.0.1"
234
+ source = "registry+https://github.com/rust-lang/crates.io-index"
235
+ checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba"
236
+
237
+ [[package]]
238
+ name = "syn"
239
+ version = "2.0.117"
240
+ source = "registry+https://github.com/rust-lang/crates.io-index"
241
+ checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99"
242
+ dependencies = [
243
+ "proc-macro2",
244
+ "quote",
245
+ "unicode-ident",
246
+ ]
247
+
248
+ [[package]]
249
+ name = "target-lexicon"
250
+ version = "0.12.16"
251
+ source = "registry+https://github.com/rust-lang/crates.io-index"
252
+ checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1"
253
+
254
+ [[package]]
255
+ name = "unicode-ident"
256
+ version = "1.0.24"
257
+ source = "registry+https://github.com/rust-lang/crates.io-index"
258
+ checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
259
+
260
+ [[package]]
261
+ name = "unindent"
262
+ version = "0.2.4"
263
+ source = "registry+https://github.com/rust-lang/crates.io-index"
264
+ checksum = "7264e107f553ccae879d21fbea1d6724ac785e8c3bfc762137959b5802826ef3"
qliff-0.0.1/Cargo.toml ADDED
@@ -0,0 +1,26 @@
1
+ [package]
2
+ name = "qliff"
3
+ version = "0.0.1"
4
+ edition = "2021"
5
+ description = "Clifford + noisy stabilizer simulator (native core)"
6
+ license = "MIT"
7
+ repository = "https://github.com/plutoniumm/qliff"
8
+
9
+ [lib]
10
+ name = "_core"
11
+ crate-type = ["cdylib"]
12
+
13
+ [dependencies]
14
+ pyo3 = { version = "0.23", features = [
15
+ "extension-module",
16
+ "abi3-py311",
17
+ # synthesize the python3.dll import lib when cross-compiling to Windows,
18
+ # so no Windows Python needs to be present on the build machine.
19
+ "generate-import-lib",
20
+ ] }
21
+ rayon = "1"
22
+
23
+ [profile.release]
24
+ lto = true
25
+ codegen-units = 1
26
+ opt-level = 3
qliff-0.0.1/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 plutoniumm
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,6 @@
1
+ include README.md
2
+ include LICENSE
3
+ include Cargo.toml
4
+ include Cargo.lock
5
+ recursive-include src *.rs
6
+ recursive-include qliff/server/static *
qliff-0.0.1/PKG-INFO ADDED
@@ -0,0 +1,171 @@
1
+ Metadata-Version: 2.4
2
+ Name: qliff
3
+ Version: 0.0.1
4
+ Summary: Clifford + noisy stabilizer simulator: noise-free and noisy (importance-sampled) stabilizer simulation with a native core.
5
+ Home-page: https://github.com/plutoniumm/qliff
6
+ Author: plutoniumm
7
+ Author-email: haskell-game@manav.ch
8
+ License: MIT
9
+ Keywords: quantum,clifford,stabilizer,simulator,noise,qec,tableau
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Rust
14
+ Classifier: Topic :: Scientific/Engineering :: Physics
15
+ Requires-Python: >=3.11
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Requires-Dist: numpy
19
+ Provides-Extra: dev
20
+ Requires-Dist: setuptools-rust; extra == "dev"
21
+ Requires-Dist: twine; extra == "dev"
22
+ Requires-Dist: black; extra == "dev"
23
+ Requires-Dist: wheel; extra == "dev"
24
+ Provides-Extra: bench
25
+ Requires-Dist: stim; extra == "bench"
26
+ Requires-Dist: pymatching; extra == "bench"
27
+ Provides-Extra: studio
28
+ Requires-Dist: fastapi; extra == "studio"
29
+ Requires-Dist: uvicorn[standard]; extra == "studio"
30
+ Requires-Dist: pymatching; extra == "studio"
31
+ Requires-Dist: ldpc; extra == "studio"
32
+ Dynamic: author
33
+ Dynamic: author-email
34
+ Dynamic: classifier
35
+ Dynamic: description
36
+ Dynamic: description-content-type
37
+ Dynamic: home-page
38
+ Dynamic: keywords
39
+ Dynamic: license
40
+ Dynamic: license-file
41
+ Dynamic: provides-extra
42
+ Dynamic: requires-dist
43
+ Dynamic: requires-python
44
+ Dynamic: summary
45
+
46
+ # qliff
47
+
48
+ A Clifford stabilizer simulator with support for noisy and mid-circuit measurement-based simulation.
49
+
50
+ - **Clifford stab simulation** via the Aaronson–Gottesman tableau
51
+ - **Noisy sim** via stabilizer-channel
52
+ decomposition `E = Σ_μ q_μ S_μ` and **stratified importance sampling**
53
+ ([arXiv:2512.07304](https://arxiv.org/abs/2512.07304)), "nearly as cheap as Pauli noise."
54
+ - **Decoder-ready QEC primitives**: detectors, observables, detection-event sampling, a
55
+ detector error model by Pauli-frame propagation, and exporters (parity-check matrix +
56
+ priors, matching weights, syndrome/label tensors). These drop
57
+ directly into MWPM (pymatching), BP, or ML decoders.
58
+
59
+ ## Install
60
+
61
+ ```sh
62
+ pip install qliff
63
+ ```
64
+
65
+ Docs at [plutoniumm.github.io/qliff](https://plutoniumm.github.io/qliff/).
66
+
67
+ ## Clifford simulation
68
+
69
+ ```python
70
+ from qliff import Simulator
71
+
72
+ s = Simulator(2).H(0).CX(0, 1)
73
+ s.canon() # ['+XX', '+ZZ']
74
+ s.peek("ZZ") # +1
75
+ s.measure("XX") # (+1, False)
76
+
77
+ m0, m1 = Simulator(2).H(0).CX(0, 1).M(0, 1) # m0 == m1
78
+ ```
79
+
80
+ Mid-circuit measurement and classical feedback are just Python — the simulator is stateful,
81
+ so conditionals (teleportation, syndrome correction) need no special API:
82
+
83
+ ```python
84
+ s = Simulator(3, seed=0)
85
+ s.H(0)
86
+ s.H(1).CX(1, 2)
87
+ s.CX(0, 1).H(0)
88
+
89
+ if s.M(1) == 1:
90
+ s.X(2)
91
+ if s.M(0) == 1:
92
+ s.Z(2)
93
+
94
+ s.peek("__X") # +1
95
+ ```
96
+
97
+ ## Noise
98
+ Build `Circuit` with gate/noise methods, then sample or estimate.
99
+
100
+ `Circuit.estimate` picks the right sampler by default — plain Monte-Carlo when every channel is Pauli, otherwise
101
+ stratified importance sampling
102
+
103
+ ```python
104
+ from qliff import Circuit
105
+
106
+ c = Circuit(1)
107
+ c.H(0).DEPOLARIZE1(0, 0.1).M(0)
108
+ c.sample(1000)
109
+
110
+ c = Circuit(1)
111
+ c.H(0).RZ(0, 0.3)
112
+ c.estimate("X", 20000) # ≈ cos(0.3)
113
+
114
+ c = Circuit(1)
115
+ c.X(0).AMPLITUDE_DAMP(0, 0.3)
116
+ c.estimate("Z", 60000) # ≈ 2p - 1
117
+ ```
118
+
119
+ Force the variance strategy with `c.estimate(obs, shots, stratify=False)` (flat) or `stratify=True`
120
+ (stratified), or drive the sampler directly: `from qliff.noise import Sampler`, then
121
+ `Sampler(c).expect(obs, shots, stratify=True)`. Add a custom channel by subclassing
122
+ `qliff.noise.Channel` and dropping it in with `c.noise(ch, q)`.
123
+
124
+ ## Quantum error correction
125
+
126
+ `qliff.qec` ships code-circuit generators, so you can go straight to a logical-error-rate
127
+ curve. Any circuit's detectors and observables are declared with `c.detector(...)` /
128
+ `c.observable(...)`, then turned into decoder inputs:
129
+
130
+ ```python
131
+ from qliff.qec import rotated_surface_code, logical_fidelity
132
+ from pymatching import Matching
133
+
134
+ c = rotated_surface_code(distance=5, rounds=5, p=0.01)
135
+ dem = c.dem()
136
+
137
+ H, priors, obs_matrix = dem.check_matrix()
138
+ m = Matching.from_check_matrix(
139
+ H,
140
+ weights=dem.weights(),
141
+ faults_matrix=obs_matrix
142
+ )
143
+
144
+ dets, flips = c.detector_sampler().sample(20000)
145
+ fidelity = logical_fidelity(m.decode_batch(dets), flips)
146
+ ```
147
+
148
+ ## Extending
149
+
150
+ Everything you'd customize lives in Python. Add a noise channel by subclassing
151
+ `qliff.noise.Channel` and returning its stabilizer-channel `branches`; plug in a custom
152
+ sampler or observable; export the DEM to whatever decoder you like. The Rust core stays a thin,
153
+ fast tableau engine.
154
+
155
+ ## Develop
156
+
157
+ ```sh
158
+ ./do develop # build rust core
159
+ ./do test
160
+ ./do lint
161
+ ./do bench
162
+ ./do build # all wheels (macOS/Linux/Windows, x86_64 + arm) + sdist, no upload
163
+ ./do deploy # same build, then publish to PyPI
164
+
165
+ cd docs && npm run build && npm run deploy # docs site -> GitHub Pages
166
+ ```
167
+
168
+ ## License
169
+ MIT
170
+
171
+ If you are a company using this, please get a grad student to help you with issues. If you are a grad student, please feel free to email me :)
qliff-0.0.1/README.md ADDED
@@ -0,0 +1,126 @@
1
+ # qliff
2
+
3
+ A Clifford stabilizer simulator with support for noisy and mid-circuit measurement-based simulation.
4
+
5
+ - **Clifford stab simulation** via the Aaronson–Gottesman tableau
6
+ - **Noisy sim** via stabilizer-channel
7
+ decomposition `E = Σ_μ q_μ S_μ` and **stratified importance sampling**
8
+ ([arXiv:2512.07304](https://arxiv.org/abs/2512.07304)), "nearly as cheap as Pauli noise."
9
+ - **Decoder-ready QEC primitives**: detectors, observables, detection-event sampling, a
10
+ detector error model by Pauli-frame propagation, and exporters (parity-check matrix +
11
+ priors, matching weights, syndrome/label tensors). These drop
12
+ directly into MWPM (pymatching), BP, or ML decoders.
13
+
14
+ ## Install
15
+
16
+ ```sh
17
+ pip install qliff
18
+ ```
19
+
20
+ Docs at [plutoniumm.github.io/qliff](https://plutoniumm.github.io/qliff/).
21
+
22
+ ## Clifford simulation
23
+
24
+ ```python
25
+ from qliff import Simulator
26
+
27
+ s = Simulator(2).H(0).CX(0, 1)
28
+ s.canon() # ['+XX', '+ZZ']
29
+ s.peek("ZZ") # +1
30
+ s.measure("XX") # (+1, False)
31
+
32
+ m0, m1 = Simulator(2).H(0).CX(0, 1).M(0, 1) # m0 == m1
33
+ ```
34
+
35
+ Mid-circuit measurement and classical feedback are just Python — the simulator is stateful,
36
+ so conditionals (teleportation, syndrome correction) need no special API:
37
+
38
+ ```python
39
+ s = Simulator(3, seed=0)
40
+ s.H(0)
41
+ s.H(1).CX(1, 2)
42
+ s.CX(0, 1).H(0)
43
+
44
+ if s.M(1) == 1:
45
+ s.X(2)
46
+ if s.M(0) == 1:
47
+ s.Z(2)
48
+
49
+ s.peek("__X") # +1
50
+ ```
51
+
52
+ ## Noise
53
+ Build `Circuit` with gate/noise methods, then sample or estimate.
54
+
55
+ `Circuit.estimate` picks the right sampler by default — plain Monte-Carlo when every channel is Pauli, otherwise
56
+ stratified importance sampling
57
+
58
+ ```python
59
+ from qliff import Circuit
60
+
61
+ c = Circuit(1)
62
+ c.H(0).DEPOLARIZE1(0, 0.1).M(0)
63
+ c.sample(1000)
64
+
65
+ c = Circuit(1)
66
+ c.H(0).RZ(0, 0.3)
67
+ c.estimate("X", 20000) # ≈ cos(0.3)
68
+
69
+ c = Circuit(1)
70
+ c.X(0).AMPLITUDE_DAMP(0, 0.3)
71
+ c.estimate("Z", 60000) # ≈ 2p - 1
72
+ ```
73
+
74
+ Force the variance strategy with `c.estimate(obs, shots, stratify=False)` (flat) or `stratify=True`
75
+ (stratified), or drive the sampler directly: `from qliff.noise import Sampler`, then
76
+ `Sampler(c).expect(obs, shots, stratify=True)`. Add a custom channel by subclassing
77
+ `qliff.noise.Channel` and dropping it in with `c.noise(ch, q)`.
78
+
79
+ ## Quantum error correction
80
+
81
+ `qliff.qec` ships code-circuit generators, so you can go straight to a logical-error-rate
82
+ curve. Any circuit's detectors and observables are declared with `c.detector(...)` /
83
+ `c.observable(...)`, then turned into decoder inputs:
84
+
85
+ ```python
86
+ from qliff.qec import rotated_surface_code, logical_fidelity
87
+ from pymatching import Matching
88
+
89
+ c = rotated_surface_code(distance=5, rounds=5, p=0.01)
90
+ dem = c.dem()
91
+
92
+ H, priors, obs_matrix = dem.check_matrix()
93
+ m = Matching.from_check_matrix(
94
+ H,
95
+ weights=dem.weights(),
96
+ faults_matrix=obs_matrix
97
+ )
98
+
99
+ dets, flips = c.detector_sampler().sample(20000)
100
+ fidelity = logical_fidelity(m.decode_batch(dets), flips)
101
+ ```
102
+
103
+ ## Extending
104
+
105
+ Everything you'd customize lives in Python. Add a noise channel by subclassing
106
+ `qliff.noise.Channel` and returning its stabilizer-channel `branches`; plug in a custom
107
+ sampler or observable; export the DEM to whatever decoder you like. The Rust core stays a thin,
108
+ fast tableau engine.
109
+
110
+ ## Develop
111
+
112
+ ```sh
113
+ ./do develop # build rust core
114
+ ./do test
115
+ ./do lint
116
+ ./do bench
117
+ ./do build # all wheels (macOS/Linux/Windows, x86_64 + arm) + sdist, no upload
118
+ ./do deploy # same build, then publish to PyPI
119
+
120
+ cd docs && npm run build && npm run deploy # docs site -> GitHub Pages
121
+ ```
122
+
123
+ ## License
124
+ MIT
125
+
126
+ If you are a company using this, please get a grad student to help you with issues. If you are a grad student, please feel free to email me :)
@@ -0,0 +1,18 @@
1
+ from . import noise, qec
2
+ from ._core import ColTableau, __version__
3
+ from .circuit import Circuit
4
+ from .metrics import expectation, fidelity
5
+ from .pauli import PauliString
6
+ from .simulator import Simulator
7
+
8
+ __all__ = [
9
+ "__version__",
10
+ "ColTableau",
11
+ "Simulator",
12
+ "PauliString",
13
+ "Circuit",
14
+ "expectation",
15
+ "fidelity",
16
+ "noise",
17
+ "qec",
18
+ ]
@@ -0,0 +1,3 @@
1
+ from .server.cli import main
2
+
3
+ main()
@@ -0,0 +1,6 @@
1
+ Bits = list[int] # per-qubit 0/1 vector
2
+ Signed = tuple[int, Bits, Bits] # (sign in {0, 1}, x bits, z bits)
3
+ Targets = tuple[int, ...] # qubit indices an op acts on
4
+ Op = tuple[str, Targets] # (gate name, target qubits)
5
+ Branch = tuple[float, list[Op]] # (weight, ops) -- one stabilizer-channel branch
6
+ Instruction = tuple[str, Targets, object] # (name, targets, arg) in a Circuit