-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Compensate for global phase in MatrixGate decomposition #7118
base: main
Are you sure you want to change the base?
Conversation
Looks like this creates a global phase in one of the ionq tests, which is not a supported gate in their gateset. I added it to their gateset just to see if it would allow the test to pass (pending). @tanujkhattar what's the best thing to do here? Add it to their gateset? Create a |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #7118 +/- ##
========================================
Coverage 98.15% 98.16%
========================================
Files 1089 1093 +4
Lines 95251 95439 +188
========================================
+ Hits 93497 93683 +186
- Misses 1754 1756 +2 ☔ View full report in Codecov by Sentry. |
np.testing.assert_allclose(cirq.unitary(cgate), cirq.unitary(circuit), atol=1e-1) | ||
first_op = cirq.IdentityGate(qid_shape=shape).on(*qids) # To ensure same qid order | ||
circuit = cirq.Circuit(first_op, *decomposed) | ||
np.testing.assert_allclose(cirq.unitary(cgate), cirq.unitary(circuit), atol=1e-13) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can confirm the test failure in #7071 (comment) does not happen after this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fixes the test failure on my desktop that happened due to phase difference.
I'd defer to @tanujkhattar if this is an OK change for ionq.
Following up on #7112 (which is the first commit in this PR), this PR fixes the issue at its root: it adds a compensating
GlobalPhaseOperation
when decomposing aMatrixGate
. This allows the controlled decomposition tests to usenp.testing.assert_allclose
as desired, and also allows controlledMatrixGates
to be used in decompositions, so that restriction has been removed.I think this closes #6523, as the core of that issue is being able to decompose controlled
MatrixGates
, and the specific analytical decomposition methods do not state that they might return any global phase ops, and doing so could be a breaking change. So, this PR fixes the core issue, but with lower likelihood of introducing a breaking change.cc @pavoljuhas