Skip to content

Preserve StatePreparation width in inverse (backport #16431) - #16681

Merged
Cryoris merged 1 commit into
stable/2.5from
mergify/bp/stable/2.5/pr-16431
Jul 29, 2026
Merged

Preserve StatePreparation width in inverse (backport #16431)#16681
Cryoris merged 1 commit into
stable/2.5from
mergify/bp/stable/2.5/pr-16431

Conversation

@mergify

@mergify mergify Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #16430.

StatePreparation.inverse() rebuilt integer-bitmap gates from the stored integer alone.
When the original gate was constructed with an explicit num_qubits, that width was lost and the inverse gate fell back to the minimal width implied by the integer value.

For example, StatePreparation(1, num_qubits=2).inverse() returned a 1-qubit gate instead of preserving the original 2-qubit basis-state preparation semantics.

This change forwards the original width for integer-bitmap inputs when rebuilding the inverse gate.

Details

  • preserve self.num_qubits in StatePreparation.inverse() for integer inputs
  • add a regression covering StatePreparation(1, num_qubits=2).inverse()
  • add a regression showing the integer-bitmap inverse and equivalent vector-form inverse both uncompute the same prepared 2-qubit state back to |00>
  • add a release note for the public bugfix

Testing

  • python -m unittest test.python.circuit.library.test_state_preparation.TestStatePreparation.test_inverse_preserves_integer_bitmap_width test.python.circuit.library.test_state_preparation.TestStatePreparation.test_inverse_integer_bitmap_matches_vector_form
  • python -m unittest test.python.circuit.library.test_state_preparation
  • python -m ruff check qiskit/circuit/library/data_preparation/state_preparation.py test/python/circuit/library/test_state_preparation.py

Release Notes

  • I have added a release note for end user visible changes.

AI usage

  • I used AI tooling to help draft and validate this change.
  • Tool: Codex (GPT-5)

This is an automatic backport of pull request #16431 done by [Mergify](https://mergify.com).

* Preserve StatePreparation width in inverse

* Strengthen StatePreparation inverse regression

* Address StatePreparation inverse review

* Respect StatePreparation inverse input contract

(cherry picked from commit d94420a)
@mergify
mergify Bot requested a review from a team as a code owner July 29, 2026 09:42
@mergify
mergify Bot requested a review from jakelishman July 29, 2026 09:42
@github-actions github-actions Bot added Changelog: Fixed Add a "Fixed" entry in the GitHub Release changelog. Community PR PRs from contributors that are not 'members' of the Qiskit repo mod: circuit Related to the core of the `QuantumCircuit` class or the circuit library labels Jul 29, 2026
@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 30440730829

Coverage decreased (-0.02%) to 87.637%

Details

  • Coverage decreased (-0.02%) from the base build.
  • Patch coverage: 2 of 2 lines across 1 file are fully covered (100%).
  • 26 coverage regressions across 4 files.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

26 previously-covered lines in 4 files lost coverage.

File Lines Losing Coverage Coverage
crates/qasm2/src/parse.rs 12 97.15%
crates/circuit/src/parameter/symbol_expr.rs 8 73.98%
crates/qasm2/src/lex.rs 5 92.29%
crates/qasm2/src/expr.rs 1 93.88%

Coverage Stats

Coverage Status
Relevant Lines: 128768
Covered Lines: 112849
Line Coverage: 87.64%
Coverage Strength: 998368.32 hits per line

💛 - Coveralls

@ShellyGarion
ShellyGarion added this pull request to the merge queue Jul 29, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 29, 2026
@ShellyGarion
ShellyGarion added this pull request to the merge queue Jul 29, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 29, 2026
@Cryoris
Cryoris added this pull request to the merge queue Jul 29, 2026
Merged via the queue into stable/2.5 with commit e5f2856 Jul 29, 2026
28 checks passed
@Cryoris
Cryoris deleted the mergify/bp/stable/2.5/pr-16431 branch July 29, 2026 15:20
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. Community PR PRs from contributors that are not 'members' of the Qiskit repo mod: circuit Related to the core of the `QuantumCircuit` class or the circuit library

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants