Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

correctly updating global phase when removing -I gates from the circuit #13785

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

alexanderivrii
Copy link
Contributor

@alexanderivrii alexanderivrii commented Feb 4, 2025

Summary

This fixes a minor bug in the RemoveIdentityEquivalent transpiler pass (the pass was introduced in #12384), where unitary gates close to -I were correctly removed from the circuit but the global phase of the circuit was not updated. This includes, for instance, unitary gates with matrix close to [[-1, 0], [0, -1]] as well as RX(2 * pi) and similar gates.

Fixes #13778.

Thanks to @Cryoris and @ShellyGarion for joint debugging of the problem.

@alexanderivrii alexanderivrii added stable backport potential The bug might be minimal and/or import enough to be port to stable Changelog: Bugfix Include in the "Fixed" section of the changelog labels Feb 4, 2025
@alexanderivrii alexanderivrii added this to the 2.0.0 milestone Feb 4, 2025
@alexanderivrii alexanderivrii requested a review from a team as a code owner February 4, 2025 15:41
@qiskit-bot
Copy link
Collaborator

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

  • @Qiskit/terra-core

@mtreinish mtreinish modified the milestones: 2.0.0, 1.3.3 Feb 4, 2025
@alexanderivrii
Copy link
Contributor Author

alexanderivrii commented Feb 4, 2025

Update: there is another part of the pass dealing with RX, RY, RZ and RXXGate, RYYGate, RZZGate, RZXGate gates that I should look at to see if a similar problem is possible that is similarly fixed in b7713a1.

@coveralls
Copy link

coveralls commented Feb 4, 2025

Pull Request Test Coverage Report for Build 13140017109

Warning: 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

  • 15 of 15 (100.0%) changed or added relevant lines in 1 file are covered.
  • 17 unchanged lines in 3 files lost coverage.
  • Overall coverage decreased (-0.009%) to 88.837%

Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/expr.rs 1 94.23%
crates/qasm2/src/lex.rs 4 91.73%
crates/qasm2/src/parse.rs 12 97.15%
Totals Coverage Status
Change from base Build 13135899673: -0.009%
Covered Lines: 79742
Relevant Lines: 89762

💛 - Coveralls

Copy link
Contributor

@Cryoris Cryoris left a comment

Choose a reason for hiding this comment

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

Thanks for tackling this!

I would expect this needs to cover the full spectrum of operations that are the identity up to a global phase, i.e. exp(i phi) * I 🙂 This could be done e.g. by just looking at the first entry of the matrix and extracting the phase (similar to how it is done in Operator.equiv).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: Bugfix Include in the "Fixed" section of the changelog stable backport potential The bug might be minimal and/or import enough to be port to stable
Projects
Status: To do
Development

Successfully merging this pull request may close these issues.

incorrect statevector simulation using qiskit & qiskit-aer
5 participants