Skip to content

Commit 36e91f0

Browse files
authored
docs: rewrite getting_started.md for presentation-ready format (#74)
* docs: polish documentation and expand API reference - Update getting_started.md: fix "Next Steps" to reflect BP+OSD is available - Expand api_reference.md with comprehensive API documentation: - Add DEM functions (extract_dem, build_parity_check_matrix, build_decoding_uai) - Add BatchBPDecoder and BatchOSDDecoder documentation - Add Syndrome Database functions - Add Circuit Generation functions - Organize into logical sections * docs: rewrite getting_started.md for presentation-ready format Restructure the getting started guide into 5 clear sections designed for a ~15 minute presentation: 1. The Decoding Problem - circuit-level noise, detection events 2. Pipeline Overview - Mermaid flowchart, DEM as rulebook 3. BP Algorithm & Why It Fails - factor graph, degeneracy problem 4. OSD Post-Processing - OSD-0 algorithm, soft-weighted cost 5. Live Demo - minimal code example, threshold results Key changes: - Reduced from 493 to 280 lines - Added 3 Mermaid flowcharts for visual understanding - Condensed code examples to essential snippets - Corrected threshold values (BP+OSD ~0.7%, not ~10%) - Moved detailed CLI options to usage_guide.md - Removed troubleshooting and advanced usage sections * docs: update poster and lecture notes * compile poster
1 parent 69fe6de commit 36e91f0

File tree

6 files changed

+1988
-2247
lines changed

6 files changed

+1988
-2247
lines changed

docs/api_reference.md

Lines changed: 99 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,76 @@
1-
## PyTorch BP API Reference
1+
## API Reference
22

3-
This reference documents the public API exported from `bpdecoderplus.pytorch_bp`.
3+
This reference documents the public API for BPDecoderPlus.
4+
5+
---
6+
7+
## Detector Error Model (DEM)
8+
9+
Functions for working with Stim detector error models.
10+
11+
### DEM Extraction
12+
13+
- `extract_dem(circuit, decompose_errors=True) -> stim.DetectorErrorModel`
14+
Extract DEM from a Stim circuit.
15+
16+
- `load_dem(path) -> stim.DetectorErrorModel`
17+
Load a DEM from file.
18+
19+
- `save_dem(dem, path)`
20+
Save a DEM to file.
21+
22+
### Parity Check Matrix
23+
24+
- `build_parity_check_matrix(dem, split_by_separator=True, merge_hyperedges=True) -> (H, priors, obs_flip)`
25+
Build parity check matrix from DEM.
26+
- `H`: Binary matrix of shape `(n_detectors, n_errors)`
27+
- `priors`: Error probabilities of shape `(n_errors,)`
28+
- `obs_flip`: Observable flip indicators of shape `(n_errors,)`
29+
30+
- `build_decoding_uai(H, priors, syndrome) -> str`
31+
Build UAI model string for MAP decoding from parity check matrix and syndrome.
32+
33+
---
34+
35+
## Batch Decoders
36+
37+
High-performance batch decoding for multiple syndromes.
38+
39+
### BatchBPDecoder
40+
41+
```python
42+
from bpdecoderplus.batch_bp import BatchBPDecoder
43+
44+
decoder = BatchBPDecoder(H, priors, device='cpu')
45+
marginals = decoder.decode(syndromes, max_iter=30, damping=0.2)
46+
```
47+
48+
- `BatchBPDecoder(H, priors, device='cpu')`
49+
Initialize batch BP decoder with parity check matrix and priors.
50+
51+
- `decode(syndromes, max_iter=100, damping=0.2) -> torch.Tensor`
52+
Decode batch of syndromes, returns marginal probabilities.
53+
54+
### BatchOSDDecoder
55+
56+
```python
57+
from bpdecoderplus.batch_osd import BatchOSDDecoder
58+
59+
osd_decoder = BatchOSDDecoder(H, device='cpu')
60+
solution = osd_decoder.solve(syndrome, marginals, osd_order=10)
61+
```
62+
63+
- `BatchOSDDecoder(H, device='cpu')`
64+
Initialize OSD decoder with parity check matrix.
65+
66+
- `solve(syndrome, marginals, osd_order=10) -> np.ndarray`
67+
Find error pattern using Ordered Statistics Decoding.
68+
69+
---
70+
71+
## PyTorch BP (Low-level API)
72+
73+
Low-level belief propagation implementation for factor graphs.
474

575
### UAI Parsing
676

@@ -43,3 +113,30 @@ This reference documents the public API exported from `bpdecoderplus.pytorch_bp`
43113

44114
- `apply_evidence(bp, evidence: Dict[int, int]) -> BeliefPropagation`
45115
Return a new BP object with evidence applied to factor tensors.
116+
117+
---
118+
119+
## Syndrome Database
120+
121+
Functions for generating and loading syndrome datasets.
122+
123+
- `sample_syndromes(circuit, num_shots, include_observables=True) -> (syndromes, observables)`
124+
Sample syndromes from a circuit.
125+
126+
- `save_syndrome_database(syndromes, observables, path, metadata=None)`
127+
Save syndrome database to `.npz` file.
128+
129+
- `load_syndrome_database(path) -> (syndromes, observables, metadata)`
130+
Load syndrome database from `.npz` file.
131+
132+
---
133+
134+
## Circuit Generation
135+
136+
Functions for generating surface code circuits.
137+
138+
- `generate_circuit(distance, rounds, p, task='z') -> stim.Circuit`
139+
Generate a rotated surface code memory circuit.
140+
141+
- `generate_filename(distance, rounds, p, task) -> str`
142+
Generate standardized filename for circuit parameters.

0 commit comments

Comments
 (0)