Skip to content

Measure the surface-code threshold with a matched prior and a dense grid - #568

Open
meandmytram wants to merge 6 commits into
mainfrom
notebooks-threshold-fix
Open

Measure the surface-code threshold with a matched prior and a dense grid#568
meandmytram wants to merge 6 commits into
mainfrom
notebooks-threshold-fix

Conversation

@meandmytram

@meandmytram meandmytram commented Sep 10, 2026

Copy link
Copy Markdown
Member

The last plot of quantum_surface.ipynb did not cross cleanly inside the literature band: the sweep decoded every rate with a fixed prior of 0.1 on a 0.01-spaced grid, and with $L \le 7$ the curves met at about $p = 0.10$ with the $L=3$/$L=5$ and $L=5$/$L=7$ crossings not resolved from each other.

Changes to the last cells:

  • the decoder's prior is the channel's rate at every point (bias_prob = p), as a threshold measurement calls for; a fixed prior makes the decoder optimal at one rate only and drags the crossing towards it;
  • the grid is dense around the crossing (0.08, 0.09, 0.095, 0.10, 0.105, 0.11, 0.12, 0.13), 3000 shots each, $L = 3, 5, 7$ at $\chi = 64$ under the RCM ordering; the full-scale run took eleven hours on five workers (ten minutes, two and a half hours, eight hours for the three sizes);
  • the aggregation cell prints the full table of rates with standard errors and estimates the crossing of each pair of neighbouring sizes by a weighted least-squares line through the difference of their logical error rates over the whole grid, with the uncertainty from the fit's covariance; the gap's standard error is that of the paired per-shot differences, since every size draws its shots from the same seed. The raw sign changes of the gap between grid points are listed too: with the statistical errors of this run the gap changes sign three times for $L=5$/$L=7$, so a single interpolated crossing would be an arbitrary choice;
  • the plot draws the fitted $L=5$/$L=7$ crossing with its uncertainty band next to the literature band.

What the full-scale data show: the fitted $L=5$/$L=7$ crossing is $9.4 \pm 0.3%$ and the $L=3$/$L=5$ one $9.9 \pm 0.3%$, both below the literature band (10.3% to 10.9%), with overlapping intervals, so the finite-size drift is not resolved and does not point towards the band. The closing text says so and names the likely cause: $\chi = 64$ is shown converged for $L = 3$ only, and truncation on the larger lattices costs accuracy where the crossing is decided. A $\chi$ sweep at $L = 7$ around $p = 0.09$ to $0.10$ is the follow-up measurement.

The paired-error change to the aggregation cell is in the code; its printed uncertainties refresh at the next regeneration (the per-shot data is not stored in the notebook, and the current values, computed as if the sizes were independent, are conservative).

🤖 Generated with Claude Code

https://claude.ai/code/session_01S6mbxc9eJDQMVx7tjvYwud

meandmytram and others added 2 commits September 10, 2026 11:43
The previous sweep decoded every rate with a fixed prior of 0.1 on a
0.01-spaced grid, and the crossing of the curves sat at about p = 0.10,
at the lower edge of the literature band. The decoder is now given the
channel's rate as its prior at every point (bias_prob = p), the grid is
dense around the crossing (0.08, 0.09, 0.095, 0.10, 0.105, 0.11, 0.12,
0.13), the aggregation cell prints the full table and the crossings of
neighbouring sizes by linear interpolation, and the plot draws the
L=5/L=7 crossing, the notebook's threshold estimate, next to the
literature band. Outputs are cleared here and regenerated at full scale.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01S6mbxc9eJDQMVx7tjvYwud
classical_ldpc now takes about 4 h (its BP comparison cell 1.25 h on five
workers) and quantum_surface about 13 h (the threshold sweep about 10 h);
the pipeline page says how the worker pools are sized and that concurrent
workers on this laptop run about three times slower per shot than a lone
process.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01S6mbxc9eJDQMVx7tjvYwud
@codecov

codecov Bot commented Sep 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.29%. Comparing base (53eaaf3) to head (400b56b).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #568      +/-   ##
==========================================
+ Coverage   97.26%   97.29%   +0.03%     
==========================================
  Files          26       26              
  Lines        5259     5259              
==========================================
+ Hits         5115     5117       +2     
+ Misses        144      142       -2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The threshold table and figure outputs must be regenerated and committed before publication.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Updates the surface-code threshold experiment to use matched priors and denser sampling, alongside revised notebook runtime guidance.

Changes:

  • Matches decoder bias to each physical error rate.
  • Adds threshold interpolation, tabular reporting, and plot annotation.
  • Updates full-run timing estimates.
File summaries
File Description
examples/decoding/quantum_surface.ipynb Revises threshold sweep and visualization.
examples/decoding/classical_ldpc.ipynb Updates runtime documentation.
docs/source/notebook_pipeline.rst Revises notebook runtime and worker guidance.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 1
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread examples/decoding/quantum_surface.ipynb Outdated
@meandmytram
meandmytram marked this pull request as ready for review September 10, 2026 17:39
L = 3, 5, 7 at chi = 64 (RCM order), 3000 shots per point, decoder prior
equal to the channel rate. Logical error rates (standard error ~0.006):
  p:     0.080  0.090  0.095  0.100  0.105  0.110  0.120  0.130
  L=3:   0.105  0.123  0.120  0.136  0.148  0.146  0.184  0.213
  L=5:   0.088  0.108  0.125  0.138  0.148  0.158  0.211  0.238
  L=7:   0.072  0.111  0.124  0.140  0.154  0.191  0.227  0.281
Crossings by linear interpolation: L=3/L=5 at p = 0.0938, L=5/L=7 at
p = 0.0887, both below the literature band (10.3-10.9%). With the fixed
prior of 0.1 the previous sweep crossed at about 0.10; the matched prior
did not move the crossing up but down, and L = 7 is now above L = 5 from
p = 0.105 on. Every shot decoded. Outputs committed as measured.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01S6mbxc9eJDQMVx7tjvYwud

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The threshold selection ignores multiple observed crossings, and the concluding interpretation contradicts the committed results.

Get a fresh assessment by requesting another Copilot review.

Review details

Suppressed comments (1)

examples/decoding/quantum_surface.ipynb:3168

  • This interpretation reverses the committed results: the table prints L=3/L=5 at 0.0938 and L=5/L=7 at 0.0887, so the former is above, not below, the latter. The same data also re-cross between 0.09 and 0.10, so the blanket claims about ordering on either side of 0.0887 are not supported; update the conclusion after resolving the crossing ambiguity.
    "Below the crossing the curves fan out in the right order: at a fixed physical error rate the larger code fails less often, and the gap widens as $p$ decreases. Above it the order reverses, the larger code failing more often. The crossing of the two largest sizes, printed by the aggregation cell and drawn as the dotted line, is this notebook's estimate of the code-capacity bit-flip threshold of the surface code; the shaded band is the literature range, from the minimum-weight-matching value of 10.3% to the optimal-decoding value of 10.9%. With $L \\le 7$ the finite-size drift of the crossing is still visible (the $L = 3$/$L = 5$ crossing sits below the $L = 5$/$L = 7$ one), so the estimate from the largest pair is the one to read. The logarithmic axis is what makes the low-$p$ fan-out visible; on a linear axis it collapses into the origin. A shot whose decode raises is counted as a failure rather than dropped, and the aggregation cell prints how many there were, so a curve can only be pessimistic about such shots, never flattered by them."
  • Files reviewed: 3/3 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment thread examples/decoding/quantum_surface.ipynb Outdated
@meandmytram meandmytram self-assigned this Sep 12, 2026
@meandmytram meandmytram added bug Something isn't working documentation Improvements or additions to documentation python Pull requests that update Python code labels Sep 12, 2026
@meandmytram

meandmytram commented Sep 12, 2026

Copy link
Copy Markdown
Member Author

@Copilot investigate the parameters for which we get a solid threshold crossing

…gn change

The gap between neighbouring sizes changes sign more than once on this grid
(L=5/L=7: three sign changes), so the first interpolated crossing was an
arbitrary, noise-driven choice. The crossing now comes from a weighted
least-squares line through the gap, with its uncertainty from the fit's
covariance (L=5/L=7: 0.0937 +/- 0.0032), and every raw sign change is
listed; a pair without a unique sign change says so. The plot marks the
fitted crossing with its uncertainty band. Outputs of the two cells were
regenerated from the committed table.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01S6mbxc9eJDQMVx7tjvYwud

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The uncertainty calculation ignores correlated samples, and the concluding interpretation contradicts the fitted results.

Get a fresh assessment by requesting another Copilot review.

Review details
  • Files reviewed: 2/3 changed files
  • Comments generated: 3
  • Review effort level: Balanced

Comment thread examples/decoding/quantum_surface.ipynb
Comment thread examples/decoding/quantum_surface.ipynb
Comment thread examples/decoding/quantum_surface.ipynb Outdated
meandmytram and others added 2 commits September 11, 2026 23:20
The convergence text claimed the curves move right with the bond
dimension; the plot shows chi=64 and 128 on top of each other, chi=16 and
32 within a standard error of them, and only chi=8 departing. The
threshold text claimed the curves cross inside the literature band and
that the L=3/L=5 crossing sits below the L=5/L=7 one; the fitted L=5/L=7
crossing is 9.4 +/- 0.3%, below the band, and the L=3/L=5 one is higher at
9.9 +/- 0.3%. The text now describes the order of the curves rate by rate,
the fit and the three sign changes it replaces, the shortfall against the
band and the bond-dimension sweep that would settle it, and the measured
run time (eleven hours: ten minutes, two and a half hours, eight hours).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01S6mbxc9eJDQMVx7tjvYwud
Every lattice size draws its shots from the same seed, so shot i of one
size shares its random prefix with shot i of the next and the two logical
error rates are correlated; the crossing fit's weights now use the standard
error of the paired per-shot differences instead of the quadrature sum of
two independent errors. The printed uncertainties refresh at the next
regeneration (the per-shot data is not stored in the notebook); the
current ones, computed as if independent, are conservative.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01S6mbxc9eJDQMVx7tjvYwud

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The committed threshold outputs and narrative still use the superseded independent-error weighting rather than the new paired analysis.

Get a fresh assessment by requesting another Copilot review.

Review details
  • Files reviewed: 2/3 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment on lines +3091 to +3092
" sem(np.asarray(failures_statistics[key_of(large, p)], dtype=float)\n",
" - np.asarray(failures_statistics[key_of(small, p)], dtype=float))\n",

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct: the committed output was regenerated from the printed per-size errors, so it still carries the independent weighting, and the paired weights can move the fitted crossing as well as its uncertainty. The per-shot arrays are not stored in the notebook, so the sweep cell has to be re-executed (about eleven hours on five workers). That rerun is scheduled to start automatically as soon as the experiment queue currently occupying the machine finishes; the plot, the printed table and the closing text will be refreshed from it and pushed here before this is merged. Leaving the thread open until then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working documentation Improvements or additions to documentation python Pull requests that update Python code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants