Skip to content

Commit 6058fc9

Browse files
committed
docs: restore full PYPI_README content after rebase conflict (v0.5.3)
1 parent 3ff978d commit 6058fc9

1 file changed

Lines changed: 167 additions & 0 deletions

File tree

‎PYPI_README.md‎

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,170 @@ py -0p
7070
| CPython free-threaded builds such as `cp313t` | Not published in v0.5.x |
7171

7272
Supported Python classifiers are standard CPython 3.9 to 3.13.
73+
74+
---
75+
76+
## Quick start
77+
78+
```python
79+
import numpy as np
80+
from qector_decoder_v3 import UnionFindDecoder, BlossomDecoder
81+
82+
check_to_qubits = [[0, 1], [1, 2], [2, 3], [3, 4]]
83+
n_qubits = 5
84+
syndrome = np.array([0, 1, 0, 0], dtype=np.uint8)
85+
86+
uf = UnionFindDecoder(check_to_qubits, n_qubits)
87+
print(uf.decode(syndrome))
88+
89+
mwpm = BlossomDecoder(check_to_qubits, n_qubits)
90+
print(mwpm.decode(syndrome))
91+
```
92+
93+
Batch decoding:
94+
95+
```python
96+
import numpy as np
97+
from qector_decoder_v3 import BatchDecoder
98+
99+
checks = [[0, 1], [1, 2], [2, 3], [3, 4]]
100+
syndromes = np.random.randint(0, 2, size=(4096, 4), dtype=np.uint8)
101+
102+
cpu = BatchDecoder(checks, n_qubits=5)
103+
corrections = cpu.parallel_batch_decode(syndromes)
104+
# single-shot also works (v0.5.3+):
105+
corrections_single = cpu.decode(syndromes[0])
106+
print(corrections.shape)
107+
```
108+
109+
---
110+
111+
## API surface
112+
113+
### Stim / DEM integration
114+
115+
```python
116+
import stim
117+
from qector_decoder_v3.stim_compat import (
118+
from_stim_detector_error_model,
119+
stim_circuit_to_check_matrix, # identical alias
120+
to_stim_decoder,
121+
stim_decoder_from_dem,
122+
)
123+
124+
dem = stim.Circuit.generated(
125+
"surface_code:rotated_memory_x", distance=5
126+
).detector_error_model(decompose_errors=True)
127+
128+
c2q, nq = from_stim_detector_error_model(dem)
129+
# or equivalently: stim_circuit_to_check_matrix(dem)
130+
131+
decoder = stim_decoder_from_dem(dem)
132+
```
133+
134+
### Sinter integration
135+
136+
```python
137+
import sinter
138+
from qector_decoder_v3.sinter_compat import (
139+
QectorSinterDecoder,
140+
QectorDecoderWrapper, # backward-compat alias for QectorSinterDecoder
141+
qector_sinter_decoders,
142+
)
143+
144+
samples = sinter.collect(
145+
num_workers=4,
146+
tasks=tasks,
147+
decoders=["qector_belief", "qector_blossom", "qector_unionfind"],
148+
custom_decoders=qector_sinter_decoders(),
149+
)
150+
151+
# standalone single-syndrome decode (v0.5.3+, no Sinter required):
152+
dec = QectorSinterDecoder("blossom")
153+
obs = dec.decode(syndrome, dem=dem)
154+
```
155+
156+
### BeliefMatching raw H constructor (v0.5.3+)
157+
158+
```python
159+
import numpy as np
160+
from qector_decoder_v3.belief_matching import BeliefMatching
161+
162+
# From a Stim DEM (recommended for circuit-level noise):
163+
bm = BeliefMatching.from_detector_error_model(dem)
164+
165+
# From a raw check matrix H (uniform prior p=0.1):
166+
H = np.array([[1, 1, 0], [0, 1, 1]], dtype=np.uint8)
167+
bm = BeliefMatching(H, p=0.05)
168+
obs = bm.decode(syndrome)
169+
```
170+
171+
### CUDA / GPU
172+
173+
```python
174+
from qector_decoder_v3 import CUDABatchDecoder
175+
176+
# Always check availability before constructing
177+
if CUDABatchDecoder.is_available():
178+
dec = CUDABatchDecoder(check_to_qubits, n_qubits)
179+
corrections = dec.batch_decode(syndromes)
180+
else:
181+
print("No CUDA GPU detected — use BatchDecoder for CPU batch decoding")
182+
```
183+
184+
---
185+
186+
## Independent validation (v0.5.3)
187+
188+
Validated by independent automated test suite (86/87 checks on v0.5.2 baseline; all 5 API failures closed in v0.5.3, post-fix 33/33 PASS + 1 SKIP on CPU-only host).
189+
Platform: Windows 10, AMD Ryzen 16-core, NVIDIA GTX 1660 Ti (CUDA 7.5), Python 3.11, PyMatching 2.4.0.
190+
Full artifact: `benchmark_results/validation_v051.json`.
191+
192+
**v0.5.3 API fixes (all 3 verified):**
193+
194+
| Fix | Before | After |
195+
|---|---|---|
196+
| `BatchDecoder.decode(syndrome)` | absent (only `parallel_batch_decode`) | present, 1-row batch wrapper |
197+
| `BeliefMatching(H, p=0.1)` | TypeError (expected `_Matrices`) | accepts raw numpy H, uniform prior |
198+
| `QectorSinterDecoder.decode(syndrome, dem)` | absent | present, DEM cached on first call |
199+
200+
| Claim | Result |
201+
|---|---|
202+
| 30 decoder x code combinations, 100% syndrome-valid corrections | Confirmed |
203+
| `pymatching_compat` bit-identical to PyMatching 2.4.0 | Confirmed |
204+
| Blossom LER within 0.00% of PyMatching on repetition code d=3-9 | Confirmed |
205+
| Blossom LER within 1.78% of PyMatching on rotated surface code d=3-7 | Confirmed |
206+
| CUDA batch 100% CPU-agreeing at all tested batch sizes (GTX 1660 Ti) | Confirmed |
207+
| CUDA batch 6.9-7.7x faster than CPU batch at 100k shots | Confirmed |
208+
| Workbench single-decode rep d=5 Blossom: 277,778 dec/s, p50 3.60 us, p99 11.61 us | Confirmed |
209+
| AutoDecoder backends: cpu, cuda GTX 1660 Ti, opencl=False | Confirmed |
210+
| Workbench JSON/CSV/PDF export pipeline end-to-end | Confirmed |
211+
| LookupTableDecoder table_size for rep d=5: 64 entries | Confirmed |
212+
| d=101 stress decode completes without error | Confirmed |
213+
| Invalid input rejected with clear ValueError / TypeError | Confirmed |
214+
215+
### Single-shot latency reference (us/decode, 2000 samples, independently validated)
216+
217+
| Decoder | rep d=5 | rep d=9 | surf d=3 | surf d=5 |
218+
|---|---|---|---|---|
219+
| UnionFindDecoder | 9.3 | 10.0 | 12.2 | 10.1 |
220+
| FastUnionFindDecoder | 9.5 | 10.2 | 11.4 | 12.1 |
221+
| BlossomDecoder | 10.6 | 10.6 | 14.8 | 16.8 |
222+
| SparseBlossomDecoder | 11.8 | 10.6 | 11.5 | 29.2 |
223+
| CPUBatchDecoder | 11.2 | 9.7 | 9.5 | 10.7 |
224+
| LookupTableDecoder | 8.7 | 10.7 | 9.5 | — |
225+
226+
LookupTableDecoder is the fastest single-shot decoder on rep d=5 (precomputed table, 64 entries, O(1) lookup).
227+
228+
### Known limitations
229+
230+
- **Union-Find is ~3x less accurate than MWPM** — expected speed/accuracy trade-off.
231+
- **Single-round code-capacity noise does not produce surface-code distance scaling.** Use circuit-level Stim DEM with `qector_sinter_decoders()` for threshold curves.
232+
- **SparseBlossom batch may return different (but valid) corrections than single-shot on degenerate syndromes.** Benign matching degeneracy.
233+
- **CUDABatchDecoder raises RuntimeError cleanly when no CUDA GPU is present.** Use `CUDABatchDecoder.is_available()` to check first.
234+
235+
---
236+
237+
## License
238+
239+
Source-available. Commercial use requires written licensing through https://www.qector.store.

0 commit comments

Comments
 (0)