-
Notifications
You must be signed in to change notification settings - Fork 990
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 KakDecomposition._decompose_ by fixing factor of 2 error in exp(PauliString) #3125
Conversation
Strilanc
commented
Jul 7, 2020
- I compared against results from WolframAlpha to make sure the modified tests are now correct
…auliString) - I compared against results from WolframAlpha to make sure the modified tests are now correct
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 with two comments (one optional).
u = cirq.unitary(np.exp(-1j * np.pi / 4 * cirq.Z(a) * cirq.Z(b))) | ||
cirq.testing.assert_allclose_up_to_global_phase(u, | ||
np.diag([1, 1j, 1j, 1]), | ||
atol=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.
Stronger assertion:
cirq.testing. assert_allclose(u, np.diag(np.sqrt(-1j), np.sqrt(1j), np.sqrt(1j), np.sqrt(-1j)), atol=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.
I intentionally only did it up to global phase to make the test simpler to write, to make sure the complications weren't hiding a mistake.
|
||
|
||
@pytest.mark.parametrize('unitary', [ | ||
cirq.testing.random_unitary(4), |
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.
Optional: I wonder what distribution we get here on the elements of KAK (e.g. on the three interaction coefficients). A good addition to the random unitary test would be one synthesized from known coefficients, e.g.
u = np.exp(1j*np.pi*(0.2*cirq.unitary(cirq.XX) + 0.3*cirq.unitary(cirq.YY) + 0.4*cirq.unitary(cirq.ZZ)))
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 added a couple more cases. The "arbitrary fixed coefficients" case is very well covered by the random unitary; the corner cases have to do with interaction coefficients being zero or maxed.
…auliString) (quantumlib#3125) - I compared against results from WolframAlpha to make sure the modified tests are now correct