Skip to content

fix: remove_idle_qubits KeyError on shared operand nodes#332

Open
SAY-5 wants to merge 2 commits into
qBraid:mainfrom
SAY-5:fix-remap-shared-operand-nodes
Open

fix: remove_idle_qubits KeyError on shared operand nodes#332
SAY-5 wants to merge 2 commits into
qBraid:mainfrom
SAY-5:fix-remap-shared-operand-nodes

Conversation

@SAY-5

@SAY-5 SAY-5 commented Jul 22, 2026

Copy link
Copy Markdown

Summary of changes

Closes #331.

unroll() can emit gate statements that share the same IndexedIdentifier operand node (the crz decomposition does this), and _remap_qubits rewrites bit.indices[0][0].value in place per statement, so a node shared by k statements gets remapped k times. With a lower-indexed idle qubit the repeated lookups walk off the index map and raise KeyError, e.g. crz(0.5) q[1], q[2]; on a 3-qubit register.

This tracks visited node ids so each operand node is remapped exactly once, and adds a regression test with the minimal repro from the issue. The remap now also produces correct indices for shared nodes rather than silently double-remapping them when the shift happens to stay inside the map.

Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
@SAY-5
SAY-5 requested a review from TheGupta2012 as a code owner July 22, 2026 18:53
@coderabbitai

coderabbitai Bot commented Jul 22, 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

Run ID: 801d4e1b-95e8-4d72-b873-26c9f3e4e420

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:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
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() KeyError: unroll() emits aliased operand nodes that _remap_qubits mutates repeatedly

1 participant