Fix inverse() on circuits containing initialize() to raise CircuitError early#15607
Fix inverse() on circuits containing initialize() to raise CircuitError early#15607macatizm wants to merge 4 commits intoQiskit:mainfrom
Conversation
…or early Fixes Qiskit#15595 Previously, calling inverse() on a circuit containing initialize() would crash with a misleading internal error about invalid param types when trying to construct the inverse gate. This happened because Initialize has a definition (via _define()), so it passed the base Instruction inverse() check, but then failed later during gate construction. Now, Initialize.inverse() explicitly raises CircuitError early with a clear message, similar to how reset() behaves. This provides a better user experience with an informative error message instead of an internal error. The fix adds an inverse() method to the Initialize class that immediately raises CircuitError, explaining that initialize is a non-unitary instruction and cannot be inverted.
|
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:
|
|
Gittensor Miner seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
Cryoris
left a comment
There was a problem hiding this comment.
Thanks for the contribution! Could you add a test and a release note (under fixes) for this?
Co-authored-by: Julien Gacon <gaconju@gmail.com>
- Add test_inverse_raises_circuit_error() to verify CircuitError is raised - Add release note documenting the fix for issue Qiskit#15595
…' into fix-initialize-inverse-error-15595
|
Hi, @Cryoris |
Pull Request Test Coverage Report for Build 21386925525Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
|
thanks for your contribution to qiskit @macatizm |
|
The CLA was not signed properly since the commits were made by Gittensor Miner. |
|
I believe this may have been LLM generated without attribution. Please confirm the model used, and that the PR was tested and checked by a human before submission. I also see that this is being done for some sort of bug bounty. Qiskit did not sign up for this bug bounty and does not endorse it. We welcome quality contributions from humans, but not externally incentivised AI spam. |
Fixes #15595
Previously, calling
inverse()on a circuit containinginitialize()would crash with a misleading internal error about invalid param types when trying to construct the inverse gate. This happened becauseInitializehas a definition (via_define()), so it passed the baseInstruction.inverse()check, but then failed later during gate construction.Now,
Initialize.inverse()explicitly raisesCircuitErrorearly with a clear message, similar to howreset()behaves. This provides a better user experience with an informative error message instead of an internal error.The fix adds an
inverse()method to theInitializeclass that immediately raisesCircuitError, explaining thatinitializeis a non-unitary instruction and cannot be inverted.Changes
inverse()method toInitializeclass that raisesCircuitErrorearlyCircuitErrorexceptionPauliProductMeasurement)Testing
The fix prevents the following error:
And instead raises: