tridec 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.
Files changed (37) hide show
  1. tridec-0.1.0/LICENSE +202 -0
  2. tridec-0.1.0/PKG-INFO +204 -0
  3. tridec-0.1.0/README.md +167 -0
  4. tridec-0.1.0/pyproject.toml +62 -0
  5. tridec-0.1.0/setup.cfg +4 -0
  6. tridec-0.1.0/src/tridec/__init__.py +47 -0
  7. tridec-0.1.0/src/tridec/adapters/__init__.py +258 -0
  8. tridec-0.1.0/src/tridec/api.py +417 -0
  9. tridec-0.1.0/src/tridec/backends/__init__.py +11 -0
  10. tridec-0.1.0/src/tridec/backends/bp_numpy.py +221 -0
  11. tridec-0.1.0/src/tridec/backends/bp_torch.py +358 -0
  12. tridec-0.1.0/src/tridec/backends/bp_triton.py +480 -0
  13. tridec-0.1.0/src/tridec/backends/relay_triton.py +549 -0
  14. tridec-0.1.0/src/tridec/dem.py +49 -0
  15. tridec-0.1.0/src/tridec/sinter.py +115 -0
  16. tridec-0.1.0/src/tridec/tanner.py +48 -0
  17. tridec-0.1.0/src/tridec/validation/__init__.py +40 -0
  18. tridec-0.1.0/src/tridec/validation/analysis.py +239 -0
  19. tridec-0.1.0/src/tridec/validation/harness.py +231 -0
  20. tridec-0.1.0/src/tridec/validation/stats.py +63 -0
  21. tridec-0.1.0/src/tridec.egg-info/PKG-INFO +204 -0
  22. tridec-0.1.0/src/tridec.egg-info/SOURCES.txt +35 -0
  23. tridec-0.1.0/src/tridec.egg-info/dependency_links.txt +1 -0
  24. tridec-0.1.0/src/tridec.egg-info/requires.txt +22 -0
  25. tridec-0.1.0/src/tridec.egg-info/top_level.txt +1 -0
  26. tridec-0.1.0/tests/test_adapters.py +69 -0
  27. tridec-0.1.0/tests/test_api.py +192 -0
  28. tridec-0.1.0/tests/test_bp_numpy.py +152 -0
  29. tridec-0.1.0/tests/test_bp_torch.py +110 -0
  30. tridec-0.1.0/tests/test_bp_triton.py +102 -0
  31. tridec-0.1.0/tests/test_dem_hash_gate.py +104 -0
  32. tridec-0.1.0/tests/test_metal.py +187 -0
  33. tridec-0.1.0/tests/test_no_regression_cell.py +144 -0
  34. tridec-0.1.0/tests/test_relay_triton.py +119 -0
  35. tridec-0.1.0/tests/test_sinter.py +138 -0
  36. tridec-0.1.0/tests/test_surface_code.py +75 -0
  37. tridec-0.1.0/tests/test_validation.py +154 -0
tridec-0.1.0/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
tridec-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,204 @@
1
+ Metadata-Version: 2.4
2
+ Name: tridec
3
+ Version: 0.1.0
4
+ Summary: Vendor-portable GPU decoders for quantum LDPC codes: Triton min-sum BP and Relay-BP on NVIDIA (CUDA) and AMD (ROCm), with CPU reference implementations, consuming any stim DetectorErrorModel or raw parity-check matrices.
5
+ Author: Blake Ledden
6
+ License: Apache-2.0
7
+ Project-URL: Repository, https://github.com/bledden/tridec
8
+ Project-URL: Documentation, https://github.com/bledden/tridec/blob/master/docs/benchmark.md
9
+ Project-URL: Issues, https://github.com/bledden/tridec/issues
10
+ Keywords: quantum error correction,qLDPC,decoder,belief propagation,triton,stim,GPU
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: License :: OSI Approved :: Apache Software License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Topic :: Scientific/Engineering :: Physics
16
+ Requires-Python: >=3.10
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE
19
+ Requires-Dist: numpy>=1.24
20
+ Requires-Dist: scipy>=1.10
21
+ Requires-Dist: stim>=1.13
22
+ Provides-Extra: torch
23
+ Requires-Dist: torch>=2.4; extra == "torch"
24
+ Provides-Extra: gpu
25
+ Requires-Dist: torch>=2.4; extra == "gpu"
26
+ Requires-Dist: triton>=3.0; extra == "gpu"
27
+ Provides-Extra: decoders
28
+ Requires-Dist: ldpc>=2.4.1; extra == "decoders"
29
+ Requires-Dist: relay-bp[stim]>=0.2.2; extra == "decoders"
30
+ Provides-Extra: sinter
31
+ Requires-Dist: sinter>=1.15; extra == "sinter"
32
+ Provides-Extra: dev
33
+ Requires-Dist: pytest>=8.0; extra == "dev"
34
+ Requires-Dist: sinter>=1.15; extra == "dev"
35
+ Requires-Dist: pymatching>=2.1; extra == "dev"
36
+ Dynamic: license-file
37
+
38
+ # tridec
39
+
40
+ [![ci](https://github.com/bledden/tridec/actions/workflows/ci.yml/badge.svg)](https://github.com/bledden/tridec/actions/workflows/ci.yml)
41
+
42
+ *Badge honesty: CI is CPU-only (ubuntu + macos arm64; the macos lane binds the
43
+ strict exact-count receipt gates). There are no GPU runners — the CUDA/ROCm
44
+ kernel paths are validated by the carried H200/MI300X receipts in
45
+ `bench/receipts/`, and the experimental Metal tier runs on a local machine.*
46
+
47
+ An open, vendor-portable GPU decoder library for quantum LDPC codes — Triton
48
+ min-sum BP and Relay-BP decoders that consume any stim `DetectorErrorModel` or
49
+ raw parity-check matrices, with CPU reference implementations, validated
50
+ against the standard CPU references (`ldpc`, `relay-bp`), running on NVIDIA
51
+ (CUDA) and AMD (ROCm) GPUs.
52
+
53
+ The same Triton kernels run unmodified on both vendors: the Relay-BP kernel
54
+ reproduces its logical-error-rate validation numbers identically on an NVIDIA
55
+ H200 (CUDA 12.4, triton 3.0) and an AMD MI300X (ROCm 7.0, triton 3.4) — see
56
+ [docs/benchmark.md](docs/benchmark.md) and the raw receipts in
57
+ `bench/receipts/`. Validated scope is NVIDIA + AMD; Apple silicon runs the
58
+ same kernels through [triton-metal](https://github.com/bledden/triton-metal)
59
+ as an **experimental** backend (see below).
60
+
61
+ ## Install
62
+
63
+ Most users want `pip install "tridec[torch,decoders]"` (CPU+GPU torch backend
64
+ plus the reference adapters). The bare install is the **numpy CPU reference
65
+ only** — correct but slow.
66
+
67
+ ```bash
68
+ pip install tridec # numpy CPU reference only
69
+ pip install "tridec[torch]" # + batched torch backend (CPU/GPU)
70
+ pip install "tridec[gpu]" # + Triton GPU kernels (CUDA or ROCm)
71
+ pip install "tridec[decoders]" # + ldpc / relay-bp reference adapters
72
+ pip install "tridec[sinter]" # + sinter.collect integration
73
+ ```
74
+
75
+ ## Quickstart
76
+
77
+ ```python
78
+ import stim
79
+ import tridec
80
+
81
+ circuit = stim.Circuit.from_file("memory.stim")
82
+ dem = circuit.detector_error_model(decompose_errors=False)
83
+
84
+ decoder = tridec.from_dem(dem, backend="auto") # triton > torch > numpy
85
+
86
+ dets, obs = circuit.compile_detector_sampler(seed=0).sample(
87
+ 100_000, separate_observables=True)
88
+ pred = decoder.decode_batch(dets) # (shots, n_obs) bool
89
+ print("logical error rate:", (pred != obs).any(axis=1).mean())
90
+ ```
91
+
92
+ Raw matrices work too: `tridec.from_matrices(H, priors, observables=Lo)`.
93
+ Relay-BP: `tridec.from_dem(dem, algorithm="relay")` (Triton kernels only).
94
+
95
+ With [sinter](https://pypi.org/project/sinter/) (the `[sinter]` extra):
96
+
97
+ ```python
98
+ import sinter
99
+ from tridec.sinter import sinter_decoders
100
+
101
+ stats = sinter.collect(
102
+ num_workers=4, tasks=tasks,
103
+ decoders=["tridec_bp", "pymatching"],
104
+ custom_decoders=sinter_decoders(),
105
+ max_shots=1_000_000)
106
+ ```
107
+
108
+ ## Backend × algorithm matrix (honest availability)
109
+
110
+ | Algorithm | `numpy` | `torch` | `triton` | `metal` (experimental) |
111
+ |---|---|---|---|---|
112
+ | min-sum BP | yes (CPU reference) | yes (CPU + CUDA/ROCm) | yes (CUDA + ROCm) | yes (fp32) |
113
+ | Relay-BP | no | no | yes (CUDA + ROCm) | yes (fp32, slow — see below) |
114
+
115
+ There is no in-package CPU Relay-BP; its CPU reference is IBM's `relay-bp`
116
+ Rust decoder, wrapped in `tridec.adapters` and used as the validation
117
+ oracle for the Triton path.
118
+
119
+ ## What's validated where
120
+
121
+ | Environment | Status |
122
+ |---|---|
123
+ | CPU (any) | numpy BP reference; torch BP bit-identical to numpy at fp64 (one iteration), LER-identical full decode |
124
+ | NVIDIA H200, CUDA 12.4, torch 2.4.1, triton 3.0.0 | Triton BP: ≥99.5% hard-decision agreement vs fp64 references, LER-identical (156 = 156 = 156 fails / 2000 shots vs numpy/torch). Triton Relay-BP: LER-matches the `relay-bp` Rust oracle (31 vs 38 fails / 2000, overlapping Wilson CIs) — carried source-repo receipts |
125
+ | AMD MI300X, ROCm 7.0.0, torch 2.9, triton 3.4.0 | Same kernels, unmodified: identical primitive-identity numbers (pre-leg posterior max-diff 1.8e-15) and the same oracle-vs-Triton LER identity (carried receipts) — **and validated through the installed package for v0.1.0** (`bench/receipts/mi300x_packaged.json`): full suite 88 passed / 10 skipped on gfx942 (GPU tiers bind, darwin-only strict tiers skip), packaged-API BP 166 = numpy 166 fails / 2000, Relay-BP fp32 34 vs Rust oracle 31 (overlapping CIs), throughput within ±2.2% of the carried receipt |
126
+ | Apple silicon (M4 Max), triton-metal | **Experimental, spike-validated only** (`bench/receipts/metal_spike.md`): both kernels pass the same correctness gates at fp32; see the section below |
127
+
128
+ ## Experimental: Apple silicon (Metal)
129
+
130
+ The same Triton kernels run on Apple-silicon GPUs through
131
+ [triton-metal](https://github.com/bledden/triton-metal), with **zero changes
132
+ to the kernel source**. This is experimental: validated at spike level on one
133
+ machine (M4 Max), fp32 only (Metal has no fp64), and not part of the
134
+ official receipt set.
135
+
136
+ ```bash
137
+ # triton-metal + a triton >= 3.6 build + torch must be importable, then:
138
+ pip install tridec
139
+ python -c "import tridec; print(tridec.available_backends())" # ['metal', ...]
140
+ ```
141
+
142
+ `backend="auto"` detects the triton-metal environment (darwin, `triton` +
143
+ `triton_metal` importable, no CUDA/ROCm device) and selects `"metal"`;
144
+ `backend="triton"` resolves to `"metal"` there too, and `backend="metal"`
145
+ asserts the environment is present. The execution pattern is triton-metal's
146
+ documented one — **CPU torch tensors** (zero-copy via unified memory; not
147
+ `mps`) — so no device arguments are needed.
148
+
149
+ What the spike measured (2000 canonical shots, seed 0, M4 Max — re-validated
150
+ through this API path in `tests/test_metal.py`):
151
+
152
+ - **min-sum BP (fp32)**: all correctness gates pass — one-iteration hard
153
+ agreement 1.000 vs the fp64 numpy reference on both the surface-code and
154
+ BB-code fixtures; LER 76 = 76 / 2000 (surface) and 167 vs 168 / 2000 (BB).
155
+ Batched decode of 2000 shots in 28 ms (surface) / 167 ms (BB) — **37–56×
156
+ the per-shot numpy baseline on the same machine**.
157
+ - **Relay-BP (fp32)**: correct but slow — LER matches the `relay-bp` Rust
158
+ oracle (31 vs 39 fails / 2000, per-shot agreement 99.3%), but
159
+ `decode_batch(2000)` takes **31 s** vs 1.26 s for the Rust CPU oracle:
160
+ relay's per-iteration host loop (~7k small kernel launches) is
161
+ launch-overhead dominated on Metal. Use it for validation, not production.
162
+ - Relay-BP on metal enforces fp32: `dtype="float64"` raises with a clear
163
+ error; the default resolves to `float32`.
164
+
165
+ No claims beyond the spike: no official LER receipts, no cross-machine
166
+ validation, no performance tuning. CUDA/ROCm remain the supported GPU paths.
167
+
168
+ Compatibility floors in `pyproject.toml`; known-good pins: stim 1.15.0,
169
+ ldpc 2.4.1, relay-bp 0.2.2, torch 2.4.1 / 2.9, triton 3.0 / 3.4.
170
+
171
+ ## Validation discipline
172
+
173
+ `tridec.validation` ships the matched-protocol harness the numbers were
174
+ produced with: `dem_hash` (sha256 of the DEM's canonical bytes), `run_matched`
175
+ (one shared DEM, one shot set, fail-fast DEM-identity and tie-break gates),
176
+ Wilson/TOST statistics and a paired per-shot gap-to-MLE bootstrap. The test
177
+ suite pins the extraction byte-for-byte: 8 canonical BB-code fixture circuits
178
+ must hash to the exact DEM sha256s recorded in the carried `zoo_grid.json`
179
+ receipt, and a full 16,667-shot cell must reproduce the recorded
180
+ logical-failure counts of the `ldpc` reference adapters exactly.
181
+
182
+ For v0.1.0 the WHOLE grid was re-decoded in the receipt environment
183
+ (`bench/full_grid_noregression.py`): 31 of 32 (cell, decoder) failure counts
184
+ reproduce **exactly** — all 24 BP / BP-OSD-0 / BP-OSD-10 counts, and 7 of 8
185
+ BPLSD counts. The single deviation (BPLSD, p=0.002/X: 879 vs 880, one shot
186
+ in 200,000) is attributed by a same-environment repeat experiment to
187
+ run-to-run nondeterminism inside ldpc's `BpLsdDecoder` itself (identical
188
+ shots, fresh instances: 879/880/879) — documented in
189
+ `bench/receipts/full_grid_noregression.json`.
190
+
191
+ ## Status
192
+
193
+ `0.1.0` — first release. The kernels and their validation receipts are
194
+ stable; the public API surface is young and may still move before 1.0.
195
+ Minor `0.x` releases may rename or remove public API; `1.0` will lock the
196
+ surface. GPU paths require triton + a CUDA/ROCm GPU (or the experimental
197
+ triton-metal environment); the GPU/metal test tiers skip cleanly where
198
+ unavailable.
199
+ Validated through the installed package on MI300X/ROCm (v0.1.0) and via
200
+ carried receipts on H200/CUDA; Metal is experimental.
201
+
202
+ ## License
203
+
204
+ Apache-2.0.
tridec-0.1.0/README.md ADDED
@@ -0,0 +1,167 @@
1
+ # tridec
2
+
3
+ [![ci](https://github.com/bledden/tridec/actions/workflows/ci.yml/badge.svg)](https://github.com/bledden/tridec/actions/workflows/ci.yml)
4
+
5
+ *Badge honesty: CI is CPU-only (ubuntu + macos arm64; the macos lane binds the
6
+ strict exact-count receipt gates). There are no GPU runners — the CUDA/ROCm
7
+ kernel paths are validated by the carried H200/MI300X receipts in
8
+ `bench/receipts/`, and the experimental Metal tier runs on a local machine.*
9
+
10
+ An open, vendor-portable GPU decoder library for quantum LDPC codes — Triton
11
+ min-sum BP and Relay-BP decoders that consume any stim `DetectorErrorModel` or
12
+ raw parity-check matrices, with CPU reference implementations, validated
13
+ against the standard CPU references (`ldpc`, `relay-bp`), running on NVIDIA
14
+ (CUDA) and AMD (ROCm) GPUs.
15
+
16
+ The same Triton kernels run unmodified on both vendors: the Relay-BP kernel
17
+ reproduces its logical-error-rate validation numbers identically on an NVIDIA
18
+ H200 (CUDA 12.4, triton 3.0) and an AMD MI300X (ROCm 7.0, triton 3.4) — see
19
+ [docs/benchmark.md](docs/benchmark.md) and the raw receipts in
20
+ `bench/receipts/`. Validated scope is NVIDIA + AMD; Apple silicon runs the
21
+ same kernels through [triton-metal](https://github.com/bledden/triton-metal)
22
+ as an **experimental** backend (see below).
23
+
24
+ ## Install
25
+
26
+ Most users want `pip install "tridec[torch,decoders]"` (CPU+GPU torch backend
27
+ plus the reference adapters). The bare install is the **numpy CPU reference
28
+ only** — correct but slow.
29
+
30
+ ```bash
31
+ pip install tridec # numpy CPU reference only
32
+ pip install "tridec[torch]" # + batched torch backend (CPU/GPU)
33
+ pip install "tridec[gpu]" # + Triton GPU kernels (CUDA or ROCm)
34
+ pip install "tridec[decoders]" # + ldpc / relay-bp reference adapters
35
+ pip install "tridec[sinter]" # + sinter.collect integration
36
+ ```
37
+
38
+ ## Quickstart
39
+
40
+ ```python
41
+ import stim
42
+ import tridec
43
+
44
+ circuit = stim.Circuit.from_file("memory.stim")
45
+ dem = circuit.detector_error_model(decompose_errors=False)
46
+
47
+ decoder = tridec.from_dem(dem, backend="auto") # triton > torch > numpy
48
+
49
+ dets, obs = circuit.compile_detector_sampler(seed=0).sample(
50
+ 100_000, separate_observables=True)
51
+ pred = decoder.decode_batch(dets) # (shots, n_obs) bool
52
+ print("logical error rate:", (pred != obs).any(axis=1).mean())
53
+ ```
54
+
55
+ Raw matrices work too: `tridec.from_matrices(H, priors, observables=Lo)`.
56
+ Relay-BP: `tridec.from_dem(dem, algorithm="relay")` (Triton kernels only).
57
+
58
+ With [sinter](https://pypi.org/project/sinter/) (the `[sinter]` extra):
59
+
60
+ ```python
61
+ import sinter
62
+ from tridec.sinter import sinter_decoders
63
+
64
+ stats = sinter.collect(
65
+ num_workers=4, tasks=tasks,
66
+ decoders=["tridec_bp", "pymatching"],
67
+ custom_decoders=sinter_decoders(),
68
+ max_shots=1_000_000)
69
+ ```
70
+
71
+ ## Backend × algorithm matrix (honest availability)
72
+
73
+ | Algorithm | `numpy` | `torch` | `triton` | `metal` (experimental) |
74
+ |---|---|---|---|---|
75
+ | min-sum BP | yes (CPU reference) | yes (CPU + CUDA/ROCm) | yes (CUDA + ROCm) | yes (fp32) |
76
+ | Relay-BP | no | no | yes (CUDA + ROCm) | yes (fp32, slow — see below) |
77
+
78
+ There is no in-package CPU Relay-BP; its CPU reference is IBM's `relay-bp`
79
+ Rust decoder, wrapped in `tridec.adapters` and used as the validation
80
+ oracle for the Triton path.
81
+
82
+ ## What's validated where
83
+
84
+ | Environment | Status |
85
+ |---|---|
86
+ | CPU (any) | numpy BP reference; torch BP bit-identical to numpy at fp64 (one iteration), LER-identical full decode |
87
+ | NVIDIA H200, CUDA 12.4, torch 2.4.1, triton 3.0.0 | Triton BP: ≥99.5% hard-decision agreement vs fp64 references, LER-identical (156 = 156 = 156 fails / 2000 shots vs numpy/torch). Triton Relay-BP: LER-matches the `relay-bp` Rust oracle (31 vs 38 fails / 2000, overlapping Wilson CIs) — carried source-repo receipts |
88
+ | AMD MI300X, ROCm 7.0.0, torch 2.9, triton 3.4.0 | Same kernels, unmodified: identical primitive-identity numbers (pre-leg posterior max-diff 1.8e-15) and the same oracle-vs-Triton LER identity (carried receipts) — **and validated through the installed package for v0.1.0** (`bench/receipts/mi300x_packaged.json`): full suite 88 passed / 10 skipped on gfx942 (GPU tiers bind, darwin-only strict tiers skip), packaged-API BP 166 = numpy 166 fails / 2000, Relay-BP fp32 34 vs Rust oracle 31 (overlapping CIs), throughput within ±2.2% of the carried receipt |
89
+ | Apple silicon (M4 Max), triton-metal | **Experimental, spike-validated only** (`bench/receipts/metal_spike.md`): both kernels pass the same correctness gates at fp32; see the section below |
90
+
91
+ ## Experimental: Apple silicon (Metal)
92
+
93
+ The same Triton kernels run on Apple-silicon GPUs through
94
+ [triton-metal](https://github.com/bledden/triton-metal), with **zero changes
95
+ to the kernel source**. This is experimental: validated at spike level on one
96
+ machine (M4 Max), fp32 only (Metal has no fp64), and not part of the
97
+ official receipt set.
98
+
99
+ ```bash
100
+ # triton-metal + a triton >= 3.6 build + torch must be importable, then:
101
+ pip install tridec
102
+ python -c "import tridec; print(tridec.available_backends())" # ['metal', ...]
103
+ ```
104
+
105
+ `backend="auto"` detects the triton-metal environment (darwin, `triton` +
106
+ `triton_metal` importable, no CUDA/ROCm device) and selects `"metal"`;
107
+ `backend="triton"` resolves to `"metal"` there too, and `backend="metal"`
108
+ asserts the environment is present. The execution pattern is triton-metal's
109
+ documented one — **CPU torch tensors** (zero-copy via unified memory; not
110
+ `mps`) — so no device arguments are needed.
111
+
112
+ What the spike measured (2000 canonical shots, seed 0, M4 Max — re-validated
113
+ through this API path in `tests/test_metal.py`):
114
+
115
+ - **min-sum BP (fp32)**: all correctness gates pass — one-iteration hard
116
+ agreement 1.000 vs the fp64 numpy reference on both the surface-code and
117
+ BB-code fixtures; LER 76 = 76 / 2000 (surface) and 167 vs 168 / 2000 (BB).
118
+ Batched decode of 2000 shots in 28 ms (surface) / 167 ms (BB) — **37–56×
119
+ the per-shot numpy baseline on the same machine**.
120
+ - **Relay-BP (fp32)**: correct but slow — LER matches the `relay-bp` Rust
121
+ oracle (31 vs 39 fails / 2000, per-shot agreement 99.3%), but
122
+ `decode_batch(2000)` takes **31 s** vs 1.26 s for the Rust CPU oracle:
123
+ relay's per-iteration host loop (~7k small kernel launches) is
124
+ launch-overhead dominated on Metal. Use it for validation, not production.
125
+ - Relay-BP on metal enforces fp32: `dtype="float64"` raises with a clear
126
+ error; the default resolves to `float32`.
127
+
128
+ No claims beyond the spike: no official LER receipts, no cross-machine
129
+ validation, no performance tuning. CUDA/ROCm remain the supported GPU paths.
130
+
131
+ Compatibility floors in `pyproject.toml`; known-good pins: stim 1.15.0,
132
+ ldpc 2.4.1, relay-bp 0.2.2, torch 2.4.1 / 2.9, triton 3.0 / 3.4.
133
+
134
+ ## Validation discipline
135
+
136
+ `tridec.validation` ships the matched-protocol harness the numbers were
137
+ produced with: `dem_hash` (sha256 of the DEM's canonical bytes), `run_matched`
138
+ (one shared DEM, one shot set, fail-fast DEM-identity and tie-break gates),
139
+ Wilson/TOST statistics and a paired per-shot gap-to-MLE bootstrap. The test
140
+ suite pins the extraction byte-for-byte: 8 canonical BB-code fixture circuits
141
+ must hash to the exact DEM sha256s recorded in the carried `zoo_grid.json`
142
+ receipt, and a full 16,667-shot cell must reproduce the recorded
143
+ logical-failure counts of the `ldpc` reference adapters exactly.
144
+
145
+ For v0.1.0 the WHOLE grid was re-decoded in the receipt environment
146
+ (`bench/full_grid_noregression.py`): 31 of 32 (cell, decoder) failure counts
147
+ reproduce **exactly** — all 24 BP / BP-OSD-0 / BP-OSD-10 counts, and 7 of 8
148
+ BPLSD counts. The single deviation (BPLSD, p=0.002/X: 879 vs 880, one shot
149
+ in 200,000) is attributed by a same-environment repeat experiment to
150
+ run-to-run nondeterminism inside ldpc's `BpLsdDecoder` itself (identical
151
+ shots, fresh instances: 879/880/879) — documented in
152
+ `bench/receipts/full_grid_noregression.json`.
153
+
154
+ ## Status
155
+
156
+ `0.1.0` — first release. The kernels and their validation receipts are
157
+ stable; the public API surface is young and may still move before 1.0.
158
+ Minor `0.x` releases may rename or remove public API; `1.0` will lock the
159
+ surface. GPU paths require triton + a CUDA/ROCm GPU (or the experimental
160
+ triton-metal environment); the GPU/metal test tiers skip cleanly where
161
+ unavailable.
162
+ Validated through the installed package on MI300X/ROCm (v0.1.0) and via
163
+ carried receipts on H200/CUDA; Metal is experimental.
164
+
165
+ ## License
166
+
167
+ Apache-2.0.
@@ -0,0 +1,62 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "tridec"
7
+ version = "0.1.0"
8
+ description = "Vendor-portable GPU decoders for quantum LDPC codes: Triton min-sum BP and Relay-BP on NVIDIA (CUDA) and AMD (ROCm), with CPU reference implementations, consuming any stim DetectorErrorModel or raw parity-check matrices."
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = { text = "Apache-2.0" }
12
+ authors = [{ name = "Blake Ledden" }]
13
+ keywords = ["quantum error correction", "qLDPC", "decoder", "belief propagation", "triton", "stim", "GPU"]
14
+ classifiers = [
15
+ "Development Status :: 3 - Alpha",
16
+ "Intended Audience :: Science/Research",
17
+ "License :: OSI Approved :: Apache Software License",
18
+ "Programming Language :: Python :: 3",
19
+ "Topic :: Scientific/Engineering :: Physics",
20
+ ]
21
+
22
+ # Version floors are the oldest versions this package is validated against.
23
+ # Known-good (validated) combinations — see README "Compatibility" for the full matrix:
24
+ # stim 1.15.0, ldpc 2.4.1, relay-bp 0.2.2,
25
+ # torch 2.4.1 + triton 3.0.0 (CUDA 12.4, H200),
26
+ # torch 2.9 + triton 3.4 (ROCm 7.0, MI300X).
27
+ dependencies = [
28
+ "numpy>=1.24",
29
+ "scipy>=1.10",
30
+ "stim>=1.13",
31
+ ]
32
+
33
+ [project.urls]
34
+ Repository = "https://github.com/bledden/tridec"
35
+ Documentation = "https://github.com/bledden/tridec/blob/master/docs/benchmark.md"
36
+ Issues = "https://github.com/bledden/tridec/issues"
37
+
38
+ [project.optional-dependencies]
39
+ # torch backend: batched BP that runs on CPU and CUDA/ROCm devices.
40
+ torch = ["torch>=2.4"]
41
+ # gpu: the Triton fast path (NVIDIA CUDA or AMD ROCm builds of torch+triton).
42
+ gpu = ["torch>=2.4", "triton>=3.0"]
43
+ # decoders: optional CPU reference decoder adapters (validation targets).
44
+ decoders = ["ldpc>=2.4.1", "relay-bp[stim]>=0.2.2"]
45
+ # sinter: the sinter.collect custom-decoder integration (tridec.sinter).
46
+ sinter = ["sinter>=1.15"]
47
+ dev = ["pytest>=8.0", "sinter>=1.15", "pymatching>=2.1"]
48
+
49
+ [tool.setuptools.packages.find]
50
+ where = ["src"]
51
+
52
+ [tool.pytest.ini_options]
53
+ testpaths = ["tests"]
54
+ addopts = "-ra"
55
+ # Environment markers: the suite runs on three kinds of machines —
56
+ # CPU-only : gpu + metal tests skip (importorskip / module-level skips)
57
+ # CUDA/ROCm GPU : gpu tests run, metal tests skip
58
+ # Apple silicon + triton-metal : metal tests run, gpu tests skip
59
+ markers = [
60
+ "gpu: requires triton + a CUDA/ROCm GPU",
61
+ "metal: requires the experimental triton-metal environment (Apple silicon)",
62
+ ]
tridec-0.1.0/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+