Skip to content

Preserve StatePreparation width in inverse - #16650

Open
TSS99 wants to merge 1 commit into
Qiskit:mainfrom
TSS99:fix-stateprep-inverse-width
Open

Preserve StatePreparation width in inverse#16650
TSS99 wants to merge 1 commit into
Qiskit:mainfrom
TSS99:fix-stateprep-inverse-width

Conversation

@TSS99

@TSS99 TSS99 commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Fix #16430.

StatePreparation.inverse() rebuilt the inverse gate from the stored integer
value alone, so an explicit num_qubits given at construction was lost. For
integer inputs the constructor then re-inferred the minimal width from the
value, e.g. StatePreparation(1, num_qubits=2).inverse() collapsed to a
1-qubit gate.

The fix forwards the original width when rebuilding the inverse, but only for
integer-backed instances — num_qubits is invalid for label and vector inputs,
so those paths are unchanged.

Tests

Added a regression that appends StatePreparation(1, num_qubits=2) and its
inverse on the same 2-qubit circuit and checks the result is the identity.

python -m unittest test.python.circuit.library.test_state_preparation -v

AI/LLM disclosure

  • I didn't use LLM tooling, or only used it privately.
  • I used the following tool to understand this PR: Claude and ChatGPT

@TSS99
TSS99 requested a review from a team as a code owner July 23, 2026 16:50
@TSS99
TSS99 requested a review from raynelfss July 23, 2026 16:50
@Cryoris

Cryoris commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Let's give #16431 a chance first, that was opened before and has the exact same fix.

@Cryoris Cryoris added the on hold Can not fix yet label Jul 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

on hold Can not fix yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

StatePreparation.inverse drops explicit num_qubits for integer-bitmap inputs

2 participants