Commit 7a2d108
fix: handle disconnected components in tropical TN contraction (#70)
* feat: add tropical tensor network threshold analysis script
Add scripts/analyze_tropical_threshold.py for analyzing the threshold of
tropical tensor network MAP decoder on rotated surface codes.
Key features:
- Builds UAI factor graph from DEM parity check matrix
- Uses tropical tensor network contraction for exact MAP inference
- Computes observable prediction using mod-2 arithmetic with obs_flip thresholding
- Generates threshold plots comparing LER across error rates
Known limitation: MAP decoding finds the single most likely error pattern,
but QEC requires the most likely observable value. This causes ~2x higher
LER compared to BP+OSD which uses marginal probabilities. See issue for
discussion of potential improvements.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* fix: handle disconnected components in tropical TN contraction
The tropical TN decoder was producing incorrect results because
omeco.optimize_code only processes one connected component of the
factor graph. When prior factors (single-variable) were disconnected
from constraint factors, they were being dropped from the contraction
tree.
Changes:
- Add _find_connected_components() using union-find algorithm
- Modify get_omeco_tree() to handle multiple disconnected components
- Update analyze_tropical_threshold.py to use pymatching graph structure
- Add comprehensive tests for connected components handling
- Add tests verifying Tropical TN matches MWPM on surface codes
Fixes #68
* refactor: use bpdecoderplus.dem instead of pymatching for tropical TN
Update analyze_tropical_threshold.py and tests to use build_parity_check_matrix
from bpdecoderplus.dem instead of pymatching's graph structure:
- Use merge_hyperedges=True for efficient computation (smaller matrix)
- Threshold obs_flip at 0.5 for soft values from hyperedge merging
- Remove pymatching dependency from core decoder (optional for comparison)
- Update tests to use bpdecoderplus.dem functions
The connected components fix ensures all factors are included in the
contraction tree regardless of the matrix construction method.
* Debug the tropical tensor network
* docs: improve documentation with LaTeX math and benchmark results
- Add MathJax support via pymdownx.arithmatex extension
- Create mathjax.js config for proper math rendering
- Convert mathematical_description.md to use proper LaTeX notation
- Add benchmark results section to getting_started.md
- Include threshold plots and decoder comparison images
Closes #69
* fix: address PR review comments for tropical TN
- Fix empty detector handling in test_tropical_fix.py to check syndrome
- Convert combine_trees from recursive to iterative to avoid recursion limits
- Add validation to get_output_vars for better error messages
- Remove unused imports (pytest, torch) in test files
- Remove unused observables variable in test_tropical_mwpm_match.py
All 123 tests pass.
* test: add tests for build_decoding_uai to improve coverage
Add TestBuildDecodingUAI class with 6 tests:
- test_basic_uai_structure: verify UAI header format
- test_prior_factors: check prior probability values
- test_constraint_factors_syndrome_zero: even parity constraints
- test_constraint_factors_syndrome_one: odd parity constraints
- test_empty_detector: handle detectors with no connected errors
- test_real_surface_code: integration test with real DEM
This improves code coverage for the new build_decoding_uai function.
* test: increase code coverage from 95% to 97%
Add additional tests for better coverage:
- test_dem.py: Add tests for zero-probability errors and no-split mode
- test_cli.py: Add tests for --generate-dem and --generate-syndromes flags
- test_syndrome.py: Add tests for metadata edge cases (0-dim array, dict)
- test_uai_parser.py: Add tests for Factor/UAIModel repr and empty evidence
Total: 141 tests passing with 97% coverage.
---------
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>1 parent 7d3d79f commit 7a2d108
File tree
28 files changed
+3810
-498
lines changed- docs
- images
- javascripts
- note
- outputs
- scripts
- src/bpdecoderplus
- tests
- tropical_in_new
- src
- tests
28 files changed
+3810
-498
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
428 | 428 | | |
429 | 429 | | |
430 | 430 | | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
431 | 473 | | |
432 | 474 | | |
433 | 475 | | |
| |||
Loading
Loading
Loading
Loading
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
11 | | - | |
12 | | - | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
19 | 21 | | |
20 | | - | |
| 22 | + | |
21 | 23 | | |
22 | | - | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
23 | 27 | | |
24 | 28 | | |
25 | 29 | | |
26 | 30 | | |
27 | 31 | | |
28 | | - | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
29 | 37 | | |
30 | 38 | | |
31 | 39 | | |
32 | | - | |
33 | | - | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
34 | 46 | | |
35 | 47 | | |
36 | 48 | | |
37 | 49 | | |
38 | 50 | | |
39 | | - | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
40 | 56 | | |
41 | | - | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
50 | 56 | | |
51 | 57 | | |
52 | 58 | | |
| |||
0 commit comments