Repository navigation
Clearing the fix/osd-decoder-improvements #61
Description
Notice that the function of the current repo is meant to correctly plot of the circuit level threshold for bp-osd decoder on rotated surface code, which is mainly realized in "scripts/analyze_threshold.py" by running "uv run python scripts/analyze_threshold.py" and give right output:
"chance@chanceserver:~/BPDecoderPlus$ uv run python scripts/analyze_threshold.py
Collecting threshold data (GPU batch mode)...
[BPDecoderPlus]
obs_flip range: [0.0000, 1.0000]
obs_flip near 0.5 (0.3-0.7): 0/78
obs_flip == 0: 70, == 1: 4
d=3, p=0.001: LER=0.0008 (5000 samples)
d=3, p=0.003: LER=0.0062 (5000 samples)
d=3, p=0.005: LER=0.0192 (5000 samples)
d=3, p=0.007: LER=0.0338 (5000 samples)
d=3, p=0.009: LER=0.0440 (5000 samples)
d=3, p=0.012: LER=0.0830 (5000 samples)
d=3, p=0.015: LER=0.1174 (5000 samples)
obs_flip range: [0.0000, 1.0000]
obs_flip near 0.5 (0.3-0.7): 0/502
obs_flip == 0: 484, == 1: 13
d=5, p=0.001: LER=0.0004 (5000 samples)
d=5, p=0.003: LER=0.0034 (5000 samples)
d=5, p=0.005: LER=0.0108 (5000 samples)
d=5, p=0.007: LER=0.0374 (5000 samples)
d=5, p=0.009: LER=0.0652 (5000 samples)
d=5, p=0.012: LER=0.1256 (5000 samples)
d=5, p=0.015: LER=0.1978 (5000 samples)
obs_flip range: [0.0000, 1.0000]
obs_flip near 0.5 (0.3-0.7): 0/1558
obs_flip == 0: 1526, == 1: 25
d=7, p=0.001: LER=0.0002 (5000 samples)
d=7, p=0.003: LER=0.0010 (5000 samples)
d=7, p=0.005: LER=0.0126 (5000 samples)
d=7, p=0.007: LER=0.0312 (5000 samples)
d=7, p=0.009: LER=0.0790 (5000 samples)
d=7, p=0.012: LER=0.1758 (5000 samples)
d=7, p=0.015: LER=0.2780 (5000 samples)
obs_flip range: [0.0000, 1.0000]
obs_flip near 0.5 (0.3-0.7): 0/3534
obs_flip == 0: 3484, == 1: 41
d=9, p=0.001: LER=0.0000 (5000 samples)
d=9, p=0.003: LER=0.0004 (5000 samples)
d=9, p=0.005: LER=0.0072 (5000 samples)
d=9, p=0.007: LER=0.0362 (5000 samples)
Dataset d=9, p=0.009 not found, skipping
d=9, p=0.012: LER=0.2156 (5000 samples)
d=9, p=0.015: LER=0.3700 (5000 samples)
Collected 27 BPDecoderPlus data points
Threshold plot saved to: outputs/threshold_plot.png
BPDecoderPlus Threshold Analysis Summary:
Distance Error Rates Tested Min LER Max LER
d=3 7 points (0.001-0.015) 0.0008 0.1174
d=5 7 points (0.001-0.015) 0.0004 0.1978
d=7 7 points (0.001-0.015) 0.0002 0.2780
d=9 6 points (0.001-0.015) 0.0000 0.3700
[ldpc]
[ldpc] d=3, p=0.001: LER=0.0012 (5000 samples)
[ldpc] d=3, p=0.003: LER=0.0064 (5000 samples)
[ldpc] d=3, p=0.005: LER=0.0214 (5000 samples)
[ldpc] d=3, p=0.007: LER=0.0386 (5000 samples)
[ldpc] d=3, p=0.009: LER=0.0586 (5000 samples)
[ldpc] d=3, p=0.012: LER=0.0948 (5000 samples)
[ldpc] d=3, p=0.015: LER=0.1320 (5000 samples)
[ldpc] d=5, p=0.001: LER=0.0002 (5000 samples)
[ldpc] d=5, p=0.003: LER=0.0046 (5000 samples)
[ldpc] d=5, p=0.005: LER=0.0148 (5000 samples)
[ldpc] d=5, p=0.007: LER=0.0438 (5000 samples)
[ldpc] d=5, p=0.009: LER=0.0818 (5000 samples)
[ldpc] d=5, p=0.012: LER=0.1540 (5000 samples)
[ldpc] d=5, p=0.015: LER=0.2252 (5000 samples)
[ldpc] d=7, p=0.001: LER=0.0002 (5000 samples)
[ldpc] d=7, p=0.003: LER=0.0010 (5000 samples)
[ldpc] d=7, p=0.005: LER=0.0186 (5000 samples)
[ldpc] d=7, p=0.007: LER=0.0456 (5000 samples)
[ldpc] d=7, p=0.009: LER=0.0976 (5000 samples)
[ldpc] d=7, p=0.012: LER=0.2106 (5000 samples)
[ldpc] d=7, p=0.015: LER=0.3092 (5000 samples)
[ldpc] d=9, p=0.001: LER=0.0000 (5000 samples)
[ldpc] d=9, p=0.003: LER=0.0002 (5000 samples)
[ldpc] d=9, p=0.005: LER=0.0116 (5000 samples)
[ldpc] d=9, p=0.007: LER=0.0538 (5000 samples)
[ldpc] Dataset d=9, p=0.009 not found, skipping
[ldpc] d=9, p=0.012: LER=0.2786 (5000 samples)
[ldpc] d=9, p=0.015: LER=0.3962 (5000 samples)
Collected 27 ldpc data points
Threshold plot saved to: outputs/threshold_plot_ldpc.png
Threshold comparison plot saved to: outputs/threshold_comparison.png
Threshold overlay plot saved to: outputs/threshold_overlay.png
ldpc Threshold Analysis Summary:
Distance Error Rates Tested Min LER Max LER
d=3 7 points (0.001-0.015) 0.0012 0.1320
d=5 7 points (0.001-0.015) 0.0002 0.2252
d=7 7 points (0.001-0.015) 0.0002 0.3092
d=9 6 points (0.001-0.015) 0.0000 0.3962
Threshold Comparison Summary:
Distance Error Rate BPDecoderPlus ldpc Diff
d=3 p=0.0010 0.0008 0.0012 -0.0004
d=3 p=0.0030 0.0062 0.0064 -0.0002
d=3 p=0.0050 0.0192 0.0214 -0.0022
d=3 p=0.0070 0.0338 0.0386 -0.0048
d=3 p=0.0090 0.0440 0.0586 -0.0146
d=3 p=0.0120 0.0830 0.0948 -0.0118
d=3 p=0.0150 0.1174 0.1320 -0.0146
d=5 p=0.0010 0.0004 0.0002 +0.0002
d=5 p=0.0030 0.0034 0.0046 -0.0012
d=5 p=0.0050 0.0108 0.0148 -0.0040
d=5 p=0.0070 0.0374 0.0438 -0.0064
d=5 p=0.0090 0.0652 0.0818 -0.0166
d=5 p=0.0120 0.1256 0.1540 -0.0284
d=5 p=0.0150 0.1978 0.2252 -0.0274
d=7 p=0.0010 0.0002 0.0002 +0.0000
d=7 p=0.0030 0.0010 0.0010 +0.0000
d=7 p=0.0050 0.0126 0.0186 -0.0060
d=7 p=0.0070 0.0312 0.0456 -0.0144
d=7 p=0.0090 0.0790 0.0976 -0.0186
d=7 p=0.0120 0.1758 0.2106 -0.0348
d=7 p=0.0150 0.2780 0.3092 -0.0312
d=9 p=0.0010 0.0000 0.0000 +0.0000
d=9 p=0.0030 0.0004 0.0002 +0.0002
d=9 p=0.0050 0.0072 0.0116 -0.0044
d=9 p=0.0070 0.0362 0.0538 -0.0176
d=9 p=0.0120 0.2156 0.2786 -0.0630
d=9 p=0.0150 0.3700 0.3962 -0.0262
chance@chanceserver:~/BPDecoderPlus$ "
Based on this:
- The function that realized in "src/bpdecoderplus/osd.py" is fully covered by "src/bpdecoderplus/batch_osd.py" and not used in "scripts/analyze_threshold.py". Please remove osd.py and corespondly change the /test files.
- "Dataset d=9, p=0.009 not found, skipping" is signaled. Please fix it by using "scripts/generate_threshold_datasets.py".
- The hyperedge merging is totally not used, since stim package simutanously dealing this and output the .dem document with each error unique and has different syndromes. This can also be test through the output "obs_flip range: [0.0000, 1.0000] obs_flip near 0.5 (0.3-0.7): 0/78 obs_flip == 0: 70, == 1: 4". Please remove the hyperedge merging function and correspondingly change the /test files.
- Write a comprehensive document Getting_threshold.md in the folder "/docs" that include: 1. A step by step leads to reproduce the threshold above. 2. Use web, find reference to validate this threshold. you can refer to the nature version of Braviy's paper:"https://www.nature.com/articles/s41586-024-07107-7", "[...]The pseudo-threshold p0 is defined as a solution of the break-even equation pL(p) = kp. Here kp is an estimate of the probability that at least one of k unencoded qubits suffers from an error. BB codes offer a pseudo-threshold close to 0.7%, see Table 1, which is nearly the same as the error threshold of the surface code49 and exceeds the threshold of all high-rate LDPC codes known to the authors.[...]".
- Add test for all the rest functions.
- Pass the test and proposed a PR. Comment on all related issues.
Activity
GiggleLiu commentedon Jan 24, 2026
All tasks from this issue are addressed in PR #62:
osd.py-batch_osd.pycovers all functionalitysc_d9_r9_p0090_z.{dem,npz}(720 detectors, 14966 error mechanisms, 20000 shots)decompose_errors=Truehandles unique patterns; removed_split_error_by_separator,_build_parity_check_matrix_hyperedge,_build_parity_check_matrix_legacydocs/Getting_threshold.md- Includes prerequisites, dataset generation, BP+OSD analysis steps, expected results (~0.7% threshold), and referencesBatchBPDecoder(9) andBatchOSDDecoder(10)Also fixed a
prob_tagformatting bug and simplifiedanalyze_threshold.pyby removing soft XOR logic.ChanceSiyuan commentedon Jan 25, 2026
Description:
The function
_split_error_by_separatorinsrc/bpdecoderplus/dem.py, which was introduced infix/osd-decoder-improvements, has been omitted in the currentfix/issue-61-cleanupbranch. This function handles the splitting of XZ error correlations, which is a required step for generating valid thresholds for the BPOSD decoder.To Do:
_split_error_by_separatorby diffing againstfix/osd-decoder-improvements.docs/Getting_threshold.mdin the currentfix/issue-61-cleanupbranch with an explanation of this mechanism. Reference the PyMatching repository, specifically their approach to parsing.demfiles and the theoretical requirement of splitting error targets by the^separator into independent components.fix: restore ^ separator handling in DEM parsing (critical for BP dec…
GiggleLiu commentedon Jan 25, 2026
@ChanceSiyuan Thanks for catching this! Fixed in commit a11d9ba.
Changes
Restored
_split_error_by_separatorwith detailed docstring explaining:Added
split_by_separatorparameter tobuild_parity_check_matrix:True(correct behavior for BP decoding)Falsefor legacy behavior if neededAdded 7 regression tests that will catch this bug if it happens again:
TestSplitErrorBySeparator: unit tests for the split functionTestBuildParityCheckMatrixSeparator: integration tests verifying H matrix structuretest_real_dem_has_separators: confirms real surface code DEMs contain^separatorsCode Documentation
Added prominent comments in the code:
All 118 tests pass.
Merge pull request #62 from TensorBFS/fix/issue-61-cleanup