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
Add two-qubit unitary decomposition for (inverse) sqrt-iSWAP #4213
Conversation
8004fda
to
8fd5c4e
Compare
|
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.
Left a first round of comments. Still need to take a closer look at the math in _decomp_2sqrt_iswap_matrices
and _decomp_3sqrt_iswap_matrices
.
PTAL @tanujkhattar @dstrain115 @vtomole. Thanks for all the comments. I removed the conditional gate cleanup code and always output nice XPow/YPow/ZPow gates but no global phase. Let me know if I missed updating any doc strings. |
Since no one re-reviewed this yet, I added the |
Ping. |
As Tanuj is on reduced schedule this week, I can help out with the review. I'll get to this today. |
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.
LGTM, I only have a couple of nits.
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.
LGTM % nits
# No error tolerance needed | ||
ieq1 = y > np.pi / 8 | ||
ieq2 = z < 0 | ||
if ieq1: |
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.
IIUC, this is different (and better :)) from the reference implementation given in the paper in Algorithm-1. where they keep track of the intermediate single qubit rotations during canonicalization of the interaction coefficients. Instead of keeping track of the rotations, we simply recompute the kak and recurse for both single & two qubit case here.
I think it's worth adding a small description explaining the property of kak vectors that we can compose unitaries corresponding to (x1, y1, z1) and (x2, y2, z2) to form unitary corresponding to (x1 + x2, y1 + y2, z1 + z2), which is used here to break the problem into subtasks.
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'll do that. I couldn't get this part of the algorithm from the paper to work so this is actually an improvement over the paper that supports decomposing any gate into 3-sqrt-iSWAP.
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.
To clarify your statement, this doesn't "recompute" kak, it just uses kak_canonicalize_vector
to do the canonicalization automatically instead of manually like in Algorithm 1.
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.
Comment added.
*, | ||
single_qubit_gate_types=(cirq.ZPowGate, cirq.XPowGate, cirq.YPowGate), | ||
two_qubit_gate=cirq.SQRT_ISWAP, | ||
atol=1e-6, |
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.
It would be nice if the default atol
in cirq.allclose_up_to_global_phase
is enough. Right now, the default atol
returns false in many cases.
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.
Agreed. There is some source of numerical error that I couldn't track down. It doesn't help that some the Cirq linalg functions don't pass through atol to half of the functions they use internally (so default to 1e-8).
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.
Added a comment. It may be worth looking into the cause of this and also fixing various linalg functions that don't pass atol to their sub-functions.
Thanks for the reviews. I'll try to do these minor fixes tomorrow otherwise early next week. |
…lib#4213) - Add the method cirq.two_qubit_matrix_to_sqrt_iswap_operations() to optimally decompose with SQRT_ISWAP or SQRT_ISWAP_INV gates. - Add cirq.SQRT_ISWAP and cirq.SQRT_ISWAP_INV (aliases for cirq.ISWAP**0.5 and cirq.ISWAP**-0.5).
Follow up to quantumlib#4213. Fixes quantumlib#4083. (Also contains a one-line change to fix quantumlib#4225.) I'm open to name suggestions for `MergeInteractionsToSqrtIswap`.
Part of #4083.
cirq.two_qubit_matrix_to_sqrt_iswap_operations()
to optimally decompose withSQRT_ISWAP
orSQRT_ISWAP_INV
gates.cirq.SQRT_ISWAP
andcirq.SQRT_ISWAP_INV
(aliases forcirq.ISWAP**0.5
andcirq.ISWAP**-0.5
).