Skip to content

Fix 32-bit shifts in brute_force_decomp_helper dropping high detectors - #1123

Merged
Strilanc merged 1 commit into
quantumlib:mainfrom
nivednarayan:fix-decomp-64bit-shift
Oct 16, 2026
Merged

Strilanc merged 1 commit into
quantumlib:mainfrom
nivednarayan:fix-decomp-64bit-shift

Conversation

@nivednarayan

Copy link
Copy Markdown
Contributor

Fixes #1113

While looking at this issue I found that brute_force_decomp_helper keeps track of used terms in a uint64_t mask, but it was updating it with 1 << start and 1 << k. Those shift a 32-bit int, so once the shift count reaches 31 or more the result is undefined or gets sign-extended and the mask is wrong. In practice, with decompose_errors=True, an error touching 33 or more detectors would lose its higher targets (D32 in the example from the issue).

The fix is just changing those three shifts to uint64_t{1} << .... The existing check that rejects problems with 64 or more terms is untouched, so the biggest shift is 62 and stays in range. The fix and the regression test follow what was suggested in the issue.

I added test_decomposition_preserves_large_single_qubit_error to circuit_pybind_test.py. It builds the circuit from the issue for 32, 33 and 63 measurements and checks that the decomposed 0.25 error still flips every detector. Without the fix it fails at 33 (AssertionError: 33, mask is 0xFFFFFFFF so D32 is missing), and with the fix it passes.

Tests I ran:

  • python -m pytest src/stim/circuit src/stim/simulators: 222 passed
  • ./build/out/stim_test --gtest_filter='ErrorAnalyzer.*': 57 passed
pr Screenshot From 2026-10-15 17-18-21

@google-cla

google-cla Bot commented Oct 15, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@Strilanc Strilanc left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nice

@Strilanc
Strilanc merged commit 6f15adb into quantumlib:main Oct 16, 2026
57 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Graphlike decomposition silently drops D32 in a one-qubit, 33-detector circuit

2 participants