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 gates that are identity up to a global phase (backport #13785) #13825

Merged
merged 2 commits into from
Feb 11, 2025

Conversation

mergify[bot]
Copy link
Contributor

@mergify mergify bot commented Feb 11, 2025

Summary

This fixes a bug in the RemoveIdentityEquivalent transpiler pass (the pass was introduced in #12384), where unitary gates close to identity up to a global phase were removed from the circuit but the global phase of the circuit was not updated. This includes, for instance, single-qubit unitary gates with matrices close to [[ $e^{i\theta}$, 0], [0, $e^{i\theta}$]] for fix floating-point values of $\theta$, standard gates $R_X(2\pi)$, $R_Y(2\pi)$, $R_Z(2\pi)$ (whose matrices are close to $-I$), and some others. Now the pass removes these gates and correctly updates the global phase of the circuit. In particular, the pass now handles non-parameterized GlobalPhaseGates as well.

Fixes #13778.

Details and comments:

The pass ignores parameterized gates. We could probably relatively easily extend it to handle parameterized global phase gates.

The thing to notice in the current documentation of the pass is that the current condition for removing a gate is indeed satisfied for gates of the form $e^{i\theta} I$. And in fact the opposite is also true (thanks to @ShellyGarion for helping me work out the math): if the removal condition is satisfied, then a gate is necessarily of the form $e^{i\theta} I$.

Lol, yet another change after the #13759 was merged is to now also explicitly handle Unitary gates.

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


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

… up to a global phase (#13785)

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

* similar fix for specialized rotation gates

* Correctly updating global phase when removing
gates that are equivalent to identity up to a global phase

* also handling UnitaryGates after the unitary gates PR was merged

* applying review suggestions

* removing code duplication

(cherry picked from commit 7995cab)

# Conflicts:
#	crates/accelerate/src/remove_identity_equiv.rs
Copy link
Contributor Author

mergify bot commented Feb 11, 2025

Cherry-pick of 7995cab has failed:

On branch mergify/bp/stable/1.3/pr-13785
Your branch is up to date with 'origin/stable/1.3'.

You are currently cherry-picking commit 7995cabbd.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	modified:   qiskit/transpiler/passes/optimization/remove_identity_equiv.py
	new file:   releasenotes/notes/fix-phase-in-remove-id-equivalent-6480da0c62f20df1.yaml
	modified:   test/python/transpiler/test_remove_identity_equivalent.py

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   crates/accelerate/src/remove_identity_equiv.rs

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

@mergify mergify bot requested a review from a team as a code owner February 11, 2025 09:45
@mergify mergify bot added the conflicts used by mergify when there are conflicts in a port label Feb 11, 2025
@qiskit-bot
Copy link
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:

  • @Qiskit/terra-core

@github-actions github-actions bot added the Changelog: Bugfix Include in the "Fixed" section of the changelog label Feb 11, 2025
@github-actions github-actions bot added this to the 1.3.3 milestone Feb 11, 2025
@ShellyGarion ShellyGarion added this pull request to the merge queue Feb 11, 2025
Merged via the queue into stable/1.3 with commit 55be2c3 Feb 11, 2025
19 checks passed
@coveralls
Copy link

Pull Request Test Coverage Report for Build 13262165759

Details

  • 21 of 21 (100.0%) changed or added relevant lines in 1 file are covered.
  • 16 unchanged lines in 4 files lost coverage.
  • Overall coverage increased (+0.002%) to 88.92%

Files with Coverage Reduction New Missed Lines %
crates/accelerate/src/remove_identity_equiv.rs 3 93.55%
crates/circuit/src/operations.rs 3 89.57%
crates/qasm2/src/lex.rs 4 91.73%
crates/qasm2/src/parse.rs 6 97.62%
Totals Coverage Status
Change from base Build 13187458716: 0.002%
Covered Lines: 79166
Relevant Lines: 89031

💛 - Coveralls

@mtreinish mtreinish deleted the mergify/bp/stable/1.3/pr-13785 branch February 19, 2025 20:57
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 conflicts used by mergify when there are conflicts in a port
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants