Skip to content

fix: remove_idle_qubits(in_place=False) updating qubit count on the wrong module#336

Open
ryanhill1 wants to merge 1 commit into
mainfrom
fix-remove-idle-qubits-in-place-counter
Open

fix: remove_idle_qubits(in_place=False) updating qubit count on the wrong module#336
ryanhill1 wants to merge 1 commit into
mainfrom
fix-remove-idle-qubits-in-place-counter

Conversation

@ryanhill1

Copy link
Copy Markdown
Member

Summary of changes

Closes #334.

remove_idle_qubits routes every mutation through qasm_module — which is self or a deepcopy depending on in_place — except the qubit-count update at the end of the register loop, which used self. With in_place=False the original module's num_qubits was decremented and the returned copy kept the stale pre-removal count:

m2 = m.remove_idle_qubits(in_place=False)
m2.num_qubits  # 3 (stale — should be 2)
m.num_qubits   # 2 (original mutated — should still be 3)

The copy's AST was already correct (declaration size, operand indices, dumps() output); only the counters were swapped. This also switches the size lookup two lines above from self to qasm_module for consistency — harmless today since the registers are identical at that point, but it keeps the method reading from one object.

Regression test asserts both sides: the returned copy reports the reduced count and dumps the collapsed register, and the original module is left untouched.

🤖 Generated with Claude Code

…e original module

remove_idle_qubits routed every mutation through qasm_module (self or a
deepcopy depending on in_place) except the qubit-count update, which
used self. With in_place=False the original module's count was
decremented and the returned copy kept the stale pre-removal count.

Fixes #334
@ryanhill1
ryanhill1 requested a review from TheGupta2012 as a code owner July 24, 2026 16:38
@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: fc5c577b-9558-41d3-8092-a92edebe16df

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • ✅ Review completed - (🔄 Check again to review again)
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-remove-idle-qubits-in-place-counter

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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.

remove_idle_qubits(in_place=False) decrements num_qubits on the original module instead of the copy

2 participants