Correctly updating global phase when removing gates that are identity up to a global phase (backport #13785) #13825
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This fixes a bug in the$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
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 [[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).