Skip to content

fix: shallow-copy circuit instructions into initial branched path#371

Merged
speller26 merged 2 commits into
mainfrom
rmshaffer/mcm-index-fix
May 1, 2026
Merged

fix: shallow-copy circuit instructions into initial branched path#371
speller26 merged 2 commits into
mainfrom
rmshaffer/mcm-index-fix

Conversation

@rmshaffer
Copy link
Copy Markdown
Contributor

Issue #, if available:
Fixes #370

Description of changes:

The initial branched SimulationPath was seeded with shared references to Circuit.instructions, so the contiguous-qubit remapping in BaseLocalSimulator._map_circuit_qubits silently retargeted the path's gates and corrupted the final state whenever the circuit's qubit set was non-contiguous. Shallow-copying each instruction into the initial path keeps the two lists independent.

Testing done:

Added two regression tests in TestMCMNonContiguousClassicalIndices covering the minimal repro and the non-monotonic c[N] case; both fail on main and pass with the fix. All tests pass.

Merge Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your pull request.

General

Tests

  • I have added tests that prove my fix is effective or that my feature works (if appropriate)
  • I have checked that my tests are not configured for a specific region or account (if appropriate)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@rmshaffer rmshaffer requested a review from a team as a code owner May 1, 2026 14:59
@codecov
Copy link
Copy Markdown

codecov Bot commented May 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (1d8fcea) to head (515fd36).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #371   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           49        49           
  Lines         4884      4885    +1     
  Branches       562       562           
=========================================
+ Hits          4884      4885    +1     

☔ View full report in Codecov by Sentry.
📢 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.

@rmshaffer rmshaffer requested a review from speller26 May 1, 2026 15:05
@speller26 speller26 merged commit 6a785a4 into main May 1, 2026
39 of 48 checks passed
@speller26 speller26 deleted the rmshaffer/mcm-index-fix branch May 1, 2026 16:20
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.

Non-contiguous classical-bit MCMs produce wrong final bitstring

3 participants