-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Update single-qubit cliffords to fix XZ decomposition. #3414
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
Changes from all commits
0ff6ed6
63a679f
b28d3cd
5d84191
999f41f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,8 @@ | |
|
|
||
| import matplotlib.pyplot as plt | ||
|
|
||
| import cirq | ||
| import cirq.experiments.qubit_characterizations as ceqc | ||
| from cirq import GridQubit | ||
| from cirq import circuits, ops, sim | ||
| from cirq.experiments import (rabi_oscillations, | ||
|
|
@@ -40,6 +42,44 @@ def test_rabi_oscillations(): | |
| assert rms_err < 0.1 | ||
|
|
||
|
|
||
| def test_single_qubit_cliffords(): | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optional: It seems easy to write a unit test that verifies the key property of the Clifford group - that it fixes the Pauli group - but it seems we don't have it. WDYT about adding it? (Strictly speaking this isn't related to this PR, but if we had this test then observing it pass before and after would provide a lot of confidence in the new logic.)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree we should have some better abstractions around the pauli group and clifford group, but I think I'll leave that as future work because we'll probably need some design discussion around that.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since one of your goals was to ensure at most one microwave gate in each decomposition, could you add a test for this? Otherwise, this can change on you later unexpectedly.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea. Done. |
||
| cliffords = ceqc._single_qubit_cliffords() | ||
| assert len(cliffords.c1_in_xy) == 24 | ||
| assert len(cliffords.c1_in_xz) == 24 | ||
|
|
||
| def unitary(gates): | ||
| U = np.eye(2) | ||
| for gate in gates: | ||
| U = cirq.unitary(gate) @ U | ||
| return U | ||
|
|
||
| xy_unitaries = [unitary(gates) for gates in cliffords.c1_in_xy] | ||
| xz_unitaries = [unitary(gates) for gates in cliffords.c1_in_xz] | ||
|
|
||
| def check_distinct(unitaries): | ||
| n = len(unitaries) | ||
| for i in range(n): | ||
| for j in range(i + 1, n): | ||
| Ui, Uj = unitaries[i], unitaries[j] | ||
| assert not cirq.allclose_up_to_global_phase(Ui, Uj), f'{i}, {j}' | ||
|
|
||
| # Check that unitaries in each decomposition are distinct. | ||
| check_distinct(xy_unitaries) | ||
| check_distinct(xz_unitaries) | ||
|
|
||
| # Check that each decomposition gives the same set of unitaries. | ||
| for Uxy in xy_unitaries: | ||
| assert any( | ||
| cirq.allclose_up_to_global_phase(Uxy, Uxz) for Uxz in xz_unitaries) | ||
|
|
||
| # Check that XZ decomposition has at most one X gate per clifford. | ||
| for gates in cliffords.c1_in_xz: | ||
| num_x = len([gate for gate in gates if isinstance(gate, cirq.XPowGate)]) | ||
| num_z = len([gate for gate in gates if isinstance(gate, cirq.ZPowGate)]) | ||
| assert num_x + num_z == len(gates) | ||
| assert num_x <= 1 | ||
|
|
||
|
|
||
| def test_single_qubit_randomized_benchmarking(): | ||
| # Check that the ground state population at the end of the Clifford | ||
| # sequences is always unity. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
nit: Maybe add comments up where
Cliffordsnamed tuple type is defined explaining the meaning of the five fields.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.
Changed
Cliffordsto a dataclass and added some documentation about what these are.