Skip to content

Commit 9f8b5e6

Browse files
committed
v0.6.4: fix LERBenchmark guard, bump version, expand user manual
1 parent 8fb3298 commit 9f8b5e6

9 files changed

Lines changed: 408 additions & 173 deletions

File tree

AGENTS.md

Lines changed: 119 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,139 @@
1-
# Repository Guidelines
1+
# AGENTS.md — QECTOR Decoder v3
22

3-
## Project Structure & Module Organization
3+
Project-specific instructions for working in this repository.
44

5-
This repository packages QECTOR Decoder v3 as a Rust/Python project. Python source lives in `python/qector_decoder_v3/`, with public modules such as `backend.py`, `dem.py`, `routing.py`, and `workbench.py`. Python tests are in `python/tests/` and follow the `test_*.py` pattern configured in `pyproject.toml`. Rust packaging and extension metadata are in `Cargo.toml`, `Cargo.lock`, `build.rs`, and `src/lib.rs`; the public `src/` tree is a stub for licensed source builds. Examples are under `examples/`, benchmark and validation utilities under `scripts/`, protobuf definitions under `proto/`, and design/reproducibility notes under `docs/`.
5+
## Project Overview
66

7-
## Build, Test, and Development Commands
7+
QECTOR Decoder v3 is a high-performance, source-available Rust/Python platform for quantum error correction (QEC) decoding.
88

9-
Create a local environment before development:
9+
- **Core**: Rust (PyO3 cdylib) implementing Union-Find, Blossom (exact MWPM), Sparse Blossom, BP-OSD, sliding-window, streaming, batch decoders, lookup tables, neural/GNN predecoders, hybrid decoders.
10+
- **Python package**: `qector_decoder_v3` (published on PyPI).
11+
- **Bindings**: maturin + PyO3. Zero-copy NumPy arrays, GIL-free hot paths where possible.
12+
- **Hardware**: CPU (Rayon), optional CUDA batch, optional OpenCL batch. Runtime detection + graceful fallback.
13+
- **Ecosystem**: PyMatching-compatible, Stim/Sinter integration, belief-matching, Qiskit plugin, REST/gRPC + full-featured MCP server (25 tools in the QectorWorkbench companion).
14+
- **Emphasis**: Syndrome faithfulness, CPU/GPU bit-identical results, extensive regression + artifact-backed benchmarks, reproducibility.
15+
16+
**Current version**: 0.6.4 (Cargo + Python packaging).
17+
18+
**Workspace layout** (this checkout):
19+
20+
- `src/` — Rust core (all decoder implementations, batch engines, kernels, utils).
21+
- `python/qector_decoder_v3/` — Python package sources (`__init__.py`, `backend.py`, `belief_matching.py`, `bposd.py`, `stim_compat.py`, `sinter_compat.py`, `workbench.py`, `dem.py`, etc.).
22+
- `python/tests/` — 100+ pytest tests covering correctness, faithfulness, performance, GPU parity, edge cases, benchmarks.
23+
- `proto/` — gRPC `.proto` (only for `grpc` / `full` features).
24+
- `lib/` — Windows import libs (OpenCL etc.).
25+
- `build.rs` — Handles optional protoc for gRPC + link paths.
26+
- `Cargo.toml` / `pyproject.toml` — maturin build.
27+
28+
Note: This appears to be a full-source "build" checkout (src/ contains real implementations + .cu kernels).
29+
30+
## Build & Install (Windows PowerShell)
31+
32+
Use a virtual environment.
1033

1134
```powershell
12-
py -3.11 -m venv .venv
13-
.\.venv\Scripts\python.exe -m pip install --upgrade pip maturin
14-
.\.venv\Scripts\python.exe -m pip install -e ".[dev,stim,bench]"
35+
python -m venv .venv
36+
.\.venv\Scripts\Activate.ps1
37+
python -m pip install --upgrade pip maturin
38+
python -m pip install -e ".[stim,bench]" # or [all], [cuda], [opencl] etc.
1539
```
1640

17-
Build the Python extension in-place with:
41+
- For iterative Rust+Python dev: `maturin develop --release` (or without --release for faster debug).
42+
- Features are controlled in Cargo (default includes opencl + cuda in this workspace).
43+
- gRPC/MCP: `--features full` or `maturin develop --features full`.
44+
- CUDA kernels are compiled at runtime via NVRTC (no special build step for kernels).
45+
- After changes to Rust, re-run `maturin develop` (or restart Python interpreter).
46+
47+
Verify:
1848

1949
```powershell
20-
.\.venv\Scripts\python.exe -m maturin develop --release --no-default-features
50+
python -c "from qector_decoder_v3 import UnionFindDecoder, BlossomDecoder, CUDABatchDecoder; print('CUDA available:', CUDABatchDecoder.is_available() if hasattr(CUDABatchDecoder,'is_available') else 'check'); import qector_decoder_v3; print(qector_decoder_v3.__version__)"
2151
```
2252

23-
Run the full Python test suite with `.\.venv\Scripts\python.exe -m pytest python/tests -q --tb=short`. Run targeted tests by passing a file, for example `python/tests/test_backend.py`. Use `cargo test --release --lib` for Rust library tests when licensed Rust sources are available.
53+
## Testing
54+
55+
Run the full Python test suite (primary validation lives here):
56+
57+
```powershell
58+
pytest python/tests/ -q
59+
```
60+
61+
Useful filters:
62+
63+
- `pytest python/tests/ -k "unionfind or blossom or faithfulness"`
64+
- `pytest python/tests/test_gpu* -q` (GPU paths)
65+
- `pytest python/tests/test_bposd* python/tests/test_belief*`
66+
- `pytest python/tests/test_clean_venv_install.py` (install hygiene)
67+
- `pytest python/tests/test_public_api_imports.py test_type_hints.py`
68+
69+
Many tests are **correctness audits** (syndrome faithful, bit-identical across backends, regression against known good results). Do not weaken or skip them lightly.
70+
71+
Rust unit tests (if present):
72+
73+
```powershell
74+
cargo test
75+
```
76+
77+
Before claiming performance or correctness improvements, re-run relevant benchmark scripts (see README) and the due-diligence style tests.
78+
79+
## Coding Conventions & Style
80+
81+
### Rust
82+
83+
- Keep hot paths allocation-free or with reusable scratch (see `uf_core`, batch workspaces).
84+
- Use `rayon` for data-parallel batch paths.
85+
- Feature-gate GPU modules (`#[cfg(feature = "cuda")]`, `#[cfg(feature = "opencl")]`).
86+
- Strong error messages for invalid inputs (see decoder constructors).
87+
- Preserve exact numerical behavior across CPU/GPU; bit-identical results are a hard requirement in many tests.
88+
- Update `build.rs` only when adding new rerun-if-changed or build-time dependencies.
89+
90+
### Python
91+
92+
- NumPy-centric. Use `numpy.typing`, keep dtypes explicit (uint8 for syndromes usually).
93+
- Public API re-exports from the compiled extension + pure-Python shims/fallbacks.
94+
- Backend selection logic lives in `backend.py` (AutoDecoder, calibration).
95+
- Compat layers (`stim_compat`, `sinter_compat`, `pymatching_compat`) must stay faithful to the wrapped behavior.
96+
- Type hints + mypy/ruff clean (dev deps include them).
97+
- Avoid holding GIL during long Rust calls where the extension releases it.
98+
99+
### General
100+
101+
- Prefer adding tests over comments for invariants.
102+
- Benchmark numbers and claims must be reproducible via checked-in scripts + artifacts.
103+
- GPU code must degrade gracefully; never assume a device is present.
104+
- Changes touching DEM handling, observables, or sliding window must touch the corresponding faithfulness tests.
105+
106+
## Common Tasks
107+
108+
- Add a new decoder variant: implement in Rust (new `Py*` class + registration in `lib.rs`), expose in `__init__.py`, add Python wrapper if needed, add tests under `python/tests/`.
109+
- Fix a bug reported by a specific test: run that test in isolation first, then broader faithfulness suite.
110+
- Change Python-only logic (e.g. `belief_matching.py`): no rebuild needed.
111+
- Touch CUDA: ensure `cuda_is_available` and fallback paths still work; run GPU parity tests.
112+
- Update public API: also update `test_public_api_imports.py`, docs if present, and type stubs if any.
113+
- Release prep: version bumps in `Cargo.toml` + `pyproject.toml`, update `__fallback_version__` in `__init__.py`.
114+
115+
## Things to Watch Out For
24116

25-
## Coding Style & Naming Conventions
117+
- The compiled extension (`qector_decoder_v3*.pyd` or .so) must be rebuilt after any Rust change. Stale .pyd is a common source of confusion.
118+
- Feature flags affect what symbols are present (CUDA/OpenCL/gRPC may be missing).
119+
- Windows: OpenCL uses the pre-bundled .lib in `lib/`.
120+
- Hyperedges: some fast decoders reject them (see validation code).
121+
- Memory: batch decoders and large distance codes can be memory-heavy; tests include growth/leak checks.
122+
- Never claim "faster than X" or "better LER" without running the competitive scripts on this machine and recording artifacts.
26123

27-
Python targets 3.9+ and uses Ruff with a 120-character line length. Keep modules and functions in `snake_case`, classes in `PascalCase`, and tests named `test_<behavior>.py` with `test_<expected_result>` functions. Preserve lazy optional imports for GPU and ecosystem dependencies. Rust uses edition 2021; prefer `cargo fmt` style and feature-gated code for optional CUDA, OpenCL, and gRPC paths.
124+
## When Running Commands
28125

29-
## Testing Guidelines
126+
- Prefer `python -m pytest ...` over bare `pytest` for consistency.
127+
- Use the activated venv.
128+
- For long-running tests/benchmarks use the monitor tool or background where appropriate.
129+
- When editing across Rust/Python boundary, verify roundtrips (encode/decode result objects, JSON, etc.).
30130

31-
Use `pytest` and `hypothesis` where property coverage is useful. Add tests beside related coverage in `python/tests/`, especially for decoder correctness, API compatibility, fallback behavior, and reproducibility commands. GPU tests must tolerate unavailable hardware unless explicitly marked or guarded by availability checks.
131+
## Project Rules Priority
32132

33-
## Commit & Pull Request Guidelines
133+
These instructions apply in addition to any higher-level or user `AGENTS.md` / rules. Deeper directory rules (if added) take precedence for files within them.
34134

35-
Git history is unavailable in this environment, so use concise imperative commit subjects, for example `Fix batch decode dtype handling`. Pull requests should include a scoped description, commands run, environment details for benchmark claims, linked issues when applicable, and screenshots or artifacts for Workbench or report-output changes. Follow `CONTRIBUTING.md` for licensing, benchmark evidence, and security disclosure rules.
135+
Follow the spirit of the existing extensive test suite: prioritize correctness, reproducibility, and faithful behavior over micro-optimizations.
36136

37-
## Security & Configuration Tips
137+
---
38138

39-
Do not publish exploit details in issues; follow `SECURITY.md`. Treat performance claims as hardware- and build-specific. Include raw outputs, hashes, and environment blocks for benchmark submissions as described in `docs/REPRODUCIBILITY_CHECKLIST.md`.
139+
Generated by /init on first session in this workspace. Update this file as conventions evolve.

Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ serde = { version = "1.0", features = ["derive"] }
3333
serde_json = "1.0"
3434
fastrand = "2.4"
3535
chrono = "0.4"
36+
safetensors = "0.5"
37+
memmap2 = "0.9"
38+
thiserror = "2"
39+
rand = "0.8"
3640

3741
# OpenCL (GPU batch decoder)
3842
ocl = { version = "0.19", optional = true }
@@ -51,7 +55,7 @@ rand_distr = "0.4"
5155

5256
[build-dependencies]
5357
tonic-prost-build = "0.14"
54-
prost-build = { version = "0.14" }
58+
prost-build = "0.14"
5559
# Vendored `protoc` so the `grpc`/`full` builds compile the gRPC proto with no
5660
# system install. Only invoked by build.rs when the `grpc` feature is enabled.
5761
protoc-bin-vendored = "3"

PYPI_README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ Contact:
204204
author = {Guillaume Lessard},
205205
title = {{QECTOR Decoder v3}: Rust/Python Quantum Error Correction Decoding Platform},
206206
year = {2026},
207-
version = {0.6.3},
207+
version = {0.6.4},
208208
url = {https://www.qector.store},
209209
note = {Source-available. Commercial license required for commercial use.}
210210
}
79.3 KB
Binary file not shown.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ All public claims should cite an artifact, commit, command, machine, and version
222222

223223
Artifact: `benchmark_results/stim_ler_d13_d15.json`
224224

225-
Environment: Windows 10/11 class x64 machine, Python 3.11+, QECTOR v0.6.3 + v3.3 Workbench, PyMatching 2.4+, Stim 1.16+, 20,000 shots per distance.
225+
Environment: Windows 10/11 class x64 machine, Python 3.11+, QECTOR v0.6.4 + v3.3 Workbench, PyMatching 2.4+, Stim 1.16+, 20,000 shots per distance.
226226

227227
| Distance | QECTOR Blossom LER | PyMatching LER | QECTOR us/shot | PyMatching us/shot |
228228
| ---: | ---: | ---: | ---: | ---: |
@@ -428,7 +428,7 @@ See [LICENSE](LICENSE) for the repository terms and contact the commercial team
428428
author = {Guillaume Lessard},
429429
title = {{QECTOR Decoder v3}: Rust/Python Quantum Error Correction Decoding Platform},
430430
year = {2026},
431-
version = {0.6.3},
431+
version = {0.6.4},
432432
url = {https://www.qector.store},
433433
note = {Source-available. Commercial license required for commercial use.}
434434
}

0 commit comments

Comments
 (0)