Repository navigation
Factor out the per-basis prep/meas error emission in the circuit builders - #105
Merged
Merged
Conversation
ivanbasov
force-pushed
the
refactor/prep-meas-flip-error-helpers
branch
from
November 19, 2026 23:54
4e3d14d to
0042374
Compare
…ders The surface-code and color-code Circuit classes repeated the same "emit X_ERROR for a Z-basis failure, Z_ERROR for an X-basis failure" block 14 times each, once per noise mode and basis, and the mapping from (operation, basis) to a noise-model key was written out at every site. The DEM precompute repeated the same mapping as ternaries. - NoiseModel.spam_probability(kind, basis) is now the single place that maps a prep/meas operation in a basis to its key. - Circuit._spam_probability and Circuit._flip_error (both builders) replace the duplicated blocks in add_reset, add_single_error, add_measure_reset, add_measure and the final-round data-readout flip. - build_single_p_marginal and build_single_p_marginal_color_code index the prep/meas probabilities by basis code instead of branching. No behaviour change: circuit text and DEM probability vectors are byte-identical before and after for 15680 builder/precompute configurations (both codes, scalar and NoiseModel noise, both bases). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Signed-off-by: Ivan Basov <ibasov@nvidia.com>
ivanbasov
force-pushed
the
refactor/prep-meas-flip-error-helpers
branch
from
November 19, 2026 23:55
0042374 to
9a13fef
Compare
ivanbasov
marked this pull request as ready for review
November 19, 2026 23:55
bmhowe23
approved these changes
Nov 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follows #104, which is merged. The branch is rebased onto
mainand contains one commit (+145/−315).What
Refactoring only, no behaviour change. The surface-code and color-code
Circuitclasses repeated the block "emitX_ERRORfor a Z-basis failure,Z_ERRORfor an X-basis failure" 14 times each, and every site spelled out whichdata.noise_modelkey belongs to which basis. The DEM precompute repeated the same mapping as ternaries.Changes
qec/noise_model.py:NoiseModel.spam_probability(kind, basis)is now the single place that maps a prep/meas operation in a basis to its key.qec/surface_code/memory_circuit.py,qec/color_code/memory_circuit.py:Circuit._spam_probabilityandCircuit._flip_errorreplace the duplicated blocks inadd_reset,add_single_error,add_measure_reset,add_measureand the final-round data-readout flip.qec/precompute_dem.py:build_single_p_marginalandbuild_single_p_marginal_color_codeindex the prep/meas probabilities by basis code instead of branching.For a basis or error type other than X/Z, which no caller passes, the result differs: previously an unparsable circuit line or a silent skip, now a
ValueErrorfromspam_probabilityor an empty string.Verification
NoiseModelnoise (including distinct and zero prep/meas values), d=3 and 5, 1/2/4 rounds, both bases,noisy_init/noisy_meas/add_detectors/add_boundary_detectors, four surface-code rotations, color-codegidney_style_noise/flip_triangle.NoiseModel.spam_probabilityintest_noise_model.py, including rejected arguments.unittest discover528 tests, 57 skipped, 1 failure (test_required_model_files_present, pretrained weights not present locally);pyteston the color, precompute, noise-model and torch-setup tests 325 passed, 13 skipped;yapfclean.The builders run once per configuration, so there is no runtime effect.
🤖 Generated with Claude Code