Skip to content

Fix: Initialize.inverse() now raises CircuitError immediately#15782

Merged
ShellyGarion merged 5 commits intoQiskit:mainfrom
CosminDinuThiery:fix_initialise.inverse()_error
Mar 22, 2026
Merged

Fix: Initialize.inverse() now raises CircuitError immediately#15782
ShellyGarion merged 5 commits intoQiskit:mainfrom
CosminDinuThiery:fix_initialise.inverse()_error

Conversation

@CosminDinuThiery
Copy link
Copy Markdown
Contributor

@CosminDinuThiery CosminDinuThiery commented Mar 8, 2026

Summary

Fixes #15595 by raising CircuitError immediately when inverse() is called on a circuit containing Initialize.
Previously, calling inverse() on such circuits would let the computation unfold until crashing with a cryptic and uninformative error.

  • I have added the tests to cover my changes.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.

Details and comments

A new inverse() method is added to the Initialize class to override the default inverse() method inherited from the Instruction class.
This fix comes with a test verifying that the correct error is raised, and a release note.

@CosminDinuThiery CosminDinuThiery requested a review from a team as a code owner March 8, 2026 16:25
@qiskit-bot qiskit-bot added the Community PR PRs from contributors that are not 'members' of the Qiskit repo label Mar 8, 2026
@qiskit-bot
Copy link
Copy Markdown
Collaborator

Thank you for opening a new pull request.

Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient.

While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone.

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

  • @Cryoris
  • @Qiskit/terra-core
  • @ajavadia

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 8, 2026

CLA assistant check
All committers have signed the CLA.

@CosminDinuThiery CosminDinuThiery force-pushed the fix_initialise.inverse()_error branch from 0645cac to 5194046 Compare March 8, 2026 17:01
@ShellyGarion ShellyGarion self-assigned this Mar 9, 2026
@ShellyGarion ShellyGarion added the Changelog: Fixed Add a "Fixed" entry in the GitHub Release changelog. label Mar 9, 2026
@ShellyGarion ShellyGarion added this to the 2.5.0 milestone Mar 9, 2026
Copy link
Copy Markdown
Member

@ShellyGarion ShellyGarion left a comment

Choose a reason for hiding this comment

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

Hi @dinuthierycosminpro-debug - thanks for your contribution to qiskit and for fixing this bug.
Could you please handle the Docs and Lint formatting errors?
Other than some more formatting, this PR looks OK to me.


def inverse(self, annotated: bool = False):
"""Overrides initialize.inverse() and raise a circuit error"""
raise CircuitError ("Initialize is not unitary thus can not be inverted."
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.

Suggested change
raise CircuitError ("Initialize is not unitary thus can not be inverted."
raise CircuitError ("Initialize is not unitary thus can not be inverted. "


See `#15595 <https://github.com/Qiskit/qiskit/issues/15595>`__.


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.

I think that 2 lines of space are not needed.

@CosminDinuThiery CosminDinuThiery force-pushed the fix_initialise.inverse()_error branch from 0d29b76 to 055a56f Compare March 9, 2026 12:54
Comment thread qiskit/circuit/library/data_preparation/initializer.py Outdated
Comment thread releasenotes/notes/fix-initialize.inverse()-late-error-1846fbbae82ec011.yaml Outdated
@CosminDinuThiery CosminDinuThiery force-pushed the fix_initialise.inverse()_error branch from 055a56f to 9424527 Compare March 9, 2026 13:04
Comment thread test/python/circuit/test_initializer.py Outdated
Co-authored-by: Julien Gacon <gaconju@gmail.com>
@CosminDinuThiery CosminDinuThiery force-pushed the fix_initialise.inverse()_error branch from 12905b3 to 0fe1d00 Compare March 9, 2026 14:43
@Cryoris
Copy link
Copy Markdown
Collaborator

Cryoris commented Mar 9, 2026

This looks good to me, thanks for the addition @dinuthierycosminpro-debug. We're currently in release freeze for Qiskit v2.4, but once we split the stable branch for that release out we can merge your PR into main. Until then this PR is on hold.

@Cryoris Cryoris added the on hold Can not fix yet label Mar 9, 2026
@ShellyGarion
Copy link
Copy Markdown
Member

LGTM too, thanks @dinuthierycosminpro-debug for your contribution to qiskit!

@CosminDinuThiery
Copy link
Copy Markdown
Contributor Author

Thank you for your reviews!

@ShellyGarion ShellyGarion moved this from Ready to Done in Qiskit 2.5 Mar 12, 2026
@ShellyGarion ShellyGarion removed the on hold Can not fix yet label Mar 22, 2026
Copy link
Copy Markdown
Member

@ShellyGarion ShellyGarion left a comment

Choose a reason for hiding this comment

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

Thanks! and your PR is the first to merge in Qiskit 2.5

@ShellyGarion ShellyGarion enabled auto-merge March 22, 2026 09:42
@ShellyGarion ShellyGarion added the stable backport potential Make Mergify open a backport PR to the most recent stable branch on merge. label Mar 22, 2026
@ShellyGarion ShellyGarion added this pull request to the merge queue Mar 22, 2026
Merged via the queue into Qiskit:main with commit 1aeb988 Mar 22, 2026
26 checks passed
mergify Bot pushed a commit that referenced this pull request Mar 22, 2026
* Fix: Initialize.inverse() now raises CircuitError immediately

* move importations to the beggining

* Fix: apply black formatting

* Apply suggestions from code review by Cryoris

Co-authored-by: Julien Gacon <gaconju@gmail.com>

---------

Co-authored-by: Julien Gacon <gaconju@gmail.com>
Co-authored-by: Shelly Garion <46566946+ShellyGarion@users.noreply.github.com>
(cherry picked from commit 1aeb988)
github-merge-queue Bot pushed a commit that referenced this pull request Mar 22, 2026
#15848)

* Fix: Initialize.inverse() now raises CircuitError immediately

* move importations to the beggining

* Fix: apply black formatting

* Apply suggestions from code review by Cryoris



---------



(cherry picked from commit 1aeb988)

Co-authored-by: Cosmin Dinu-Thiery <dinu.thiery.cosmin.pro@gmail.com>
Co-authored-by: Julien Gacon <gaconju@gmail.com>
Co-authored-by: Shelly Garion <46566946+ShellyGarion@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. Community PR PRs from contributors that are not 'members' of the Qiskit repo stable backport potential Make Mergify open a backport PR to the most recent stable branch on merge.

Projects

Status: Done
Status: Done

Development

Successfully merging this pull request may close these issues.

inverse() on circuits containing initialize() crashes with a misleading internal error instead of raising CircuitError, like in the case of reset()

5 participants