Skip to content

Avoid triggering register/layout warning in remove_final_measurements#16026

Merged
alexanderivrii merged 1 commit intoQiskit:mainfrom
jakelishman:remove-final-measurements-layout
Apr 15, 2026
Merged

Avoid triggering register/layout warning in remove_final_measurements#16026
alexanderivrii merged 1 commit intoQiskit:mainfrom
jakelishman:remove-final-measurements-layout

Conversation

@jakelishman
Copy link
Copy Markdown
Member

QuantumCircuit.remove_final_measurements has always been a bit fragile because it attempts to do effectively in-place deletions of bits of metadata while leaving others intact. Since the "layout" warning is only about modifying the qregs, and those are untouched by remove_final_measurements, we know that the register modifications are at least safe here and can avoid the warning.

Fix #16025

AI/LLM disclosure

  • I didn't use LLM tooling, or only used it privately.
  • I used the following tool to help write this PR description:
  • I used the following tool to generate or modify code:

`QuantumCircuit.remove_final_measurements` has always been a bit fragile
because it attempts to do effectively in-place deletions of bits of
metadata while leaving others intact.  Since the "layout" warning is
only about modifying the `qregs`, and those are untouched by
`remove_final_measurements`, we know that the register modifications are
at least safe here and can avoid the warning.
@jakelishman jakelishman requested a review from a team as a code owner April 14, 2026 14:59
@jakelishman jakelishman added stable backport potential Make Mergify open a backport PR to the most recent stable branch on merge. Changelog: Fixed Add a "Fixed" entry in the GitHub Release changelog. mod: circuit Related to the core of the `QuantumCircuit` class or the circuit library labels Apr 14, 2026
@qiskit-bot
Copy link
Copy Markdown
Collaborator

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

  • @Qiskit/terra-core

Copy link
Copy Markdown
Member

@alexanderivrii alexanderivrii left a comment

Choose a reason for hiding this comment

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

LGTM!

@alexanderivrii alexanderivrii added this pull request to the merge queue Apr 15, 2026
Merged via the queue into Qiskit:main with commit 1b0276a Apr 15, 2026
29 checks passed
mergify Bot pushed a commit that referenced this pull request Apr 15, 2026
…s` (#16026)

`QuantumCircuit.remove_final_measurements` has always been a bit fragile
because it attempts to do effectively in-place deletions of bits of
metadata while leaving others intact.  Since the "layout" warning is
only about modifying the `qregs`, and those are untouched by
`remove_final_measurements`, we know that the register modifications are
at least safe here and can avoid the warning.

(cherry picked from commit 1b0276a)
@jakelishman jakelishman deleted the remove-final-measurements-layout branch April 15, 2026 08:02
github-merge-queue Bot pushed a commit that referenced this pull request Apr 15, 2026
…s` (#16026) (#16037)

`QuantumCircuit.remove_final_measurements` has always been a bit fragile
because it attempts to do effectively in-place deletions of bits of
metadata while leaving others intact.  Since the "layout" warning is
only about modifying the `qregs`, and those are untouched by
`remove_final_measurements`, we know that the register modifications are
at least safe here and can avoid the warning.

(cherry picked from commit 1b0276a)

Co-authored-by: Jake Lishman <jake.lishman@ibm.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. mod: circuit Related to the core of the `QuantumCircuit` class or the circuit library 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.

StatevectorSampler raises UserWarning: Trying to add QuantumRegister to a QuantumCircuit having a layout

3 participants