Skip to content

Fix QuantumCircuit.compose for front=True and individual qargs#15872

Merged
jakelishman merged 1 commit intoQiskit:mainfrom
jeevan0920:jeevan/fix_15834
Mar 26, 2026
Merged

Fix QuantumCircuit.compose for front=True and individual qargs#15872
jakelishman merged 1 commit intoQiskit:mainfrom
jeevan0920:jeevan/fix_15834

Conversation

@jeevan0920
Copy link
Copy Markdown
Contributor

@jeevan0920 jeevan0920 commented Mar 25, 2026

When compose() is called with both front=True and a qubits mapping, the original instructions were incorrectly re-appended with the incoming circuit's qubit remap table, causing the error when the circuits had different widths. The fix removes the spurious qubits/clbits arguments from that append, and adds a regression test.

Fix #15834

@jeevan0920 jeevan0920 self-assigned this Mar 25, 2026
@jeevan0920 jeevan0920 requested a review from a team as a code owner March 25, 2026 09:20
@qiskit-bot
Copy link
Copy Markdown
Collaborator

One or more of the following people are relevant to this code:

  • @Qiskit/terra-core

@jeevan0920 jeevan0920 requested a review from jakelishman March 25, 2026 09:21
Copy link
Copy Markdown
Member

@jakelishman jakelishman left a comment

Choose a reason for hiding this comment

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

Ohh yeah, now you do it and I look at it a second time it's quite clearly a mistake - no need to remap the instructions that are just getting put back where they belong.

It might be nice to have a bugfix release note for this, since the bug did make it into a (pre)release version of Qiskit.

In your PR commit, if you edit it so it says "Fix #15834" instead of just "#15834", the automatic closing should take effect.

if append_existing:
dest._current_scope().extend(
append_existing, qubits=mapped_qubits, clbits=mapped_clbits
append_existing,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If you delete the trailing comma on this line, the Python code formatter (black) should then squash it all back onto one line.

(I can't do it easily by GitHub suggestion because of a limitation in their feature.)

@Cryoris Cryoris added the Changelog: Fixed Add a "Fixed" entry in the GitHub Release changelog. label Mar 26, 2026
@Cryoris Cryoris changed the title Remove unwanted remapping Fix QuantumCircuit.compose for front=True and individual qargs Mar 26, 2026
@Cryoris Cryoris added the stable backport potential Make Mergify open a backport PR to the most recent stable branch on merge. label Mar 26, 2026
Copy link
Copy Markdown
Member

@jakelishman jakelishman left a comment

Choose a reason for hiding this comment

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

Thanks!

@jakelishman jakelishman added this pull request to the merge queue Mar 26, 2026
@jakelishman jakelishman added this to the 2.4.0rc2 milestone Mar 26, 2026
Merged via the queue into Qiskit:main with commit 62f74c7 Mar 26, 2026
27 checks passed
mergify bot pushed a commit that referenced this pull request Mar 26, 2026
(cherry picked from commit 62f74c7)
github-merge-queue bot pushed a commit that referenced this pull request Mar 26, 2026
(cherry picked from commit 62f74c7)

Co-authored-by: Jeevan <31155545+jeevan0920@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Changelog: Fixed Add a "Fixed" entry in the GitHub Release changelog. stable backport potential Make Mergify open a backport PR to the most recent stable branch on merge.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

compose fails when front=True is provided and when the circuit to be composed has a different number of qubits

4 participants