-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Handle all possible 1-qubit Clifford gates in Clifford simulator #2803
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
Conversation
This PR is related to issue #2423. |
@smitsanghavi, please have a look (looks like I can't add reviewers to this PR). |
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 few high level comments before diving deeper.
@@ -47,8 +48,16 @@ def __init__(self): | |||
self.init = True | |||
|
|||
@staticmethod | |||
def get_supported_gates() -> List['cirq.Gate']: | |||
return [cirq.X, cirq.Y, cirq.Z, cirq.H, cirq.S, cirq.CNOT, cirq.CZ] | |||
def is_supported_operation(op: 'cirq.Operation') -> bool: |
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 handling is being replaced with a has_stabilizer_effect protocol in #2760
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.
That PR have not been merged yet. As soon as it's merged, I'll update this PR to extend _has_stabilizer_effect_
on all matrices and to use it to check if gate can be simulated by Clifford simulator.
By the way, I think there is more elgeant way of implementing this - instead of defining _has_stabilizer_effect_
at every gate, we can do the following:
In has_stabilizer_effect_protocol.py check if gate has 2x2 uniary matrix (name it U).
If so, check that U@[email protected]().T
and U@[email protected]
are in set X, -X, Y, -Y, Z, -Z
.
This is also better than trying to match unitary with 24 matrices, as I am doing in this PR.
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 think this functionality belongs on cirq.SingleQubitCliffordGate
. Define a static method on that class called from_unitary
which takes a 2x2 unitary matrix or object with a 2x2 unitary matrix and returns an instance of cirq.SingleQubitCliffordGate
.
You can also define a cirq.SingleQubitCliffordGate.ALL
field which enumerates the 24 possible instances.
I added a method |
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. Please wait for Craig's approval too.
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 suggest also adding tests for the Clifford operations GlobalPhaseOperation and PauliString. I think these may hit corner cases that aren't handled yet.
I added tests for PauliString and GlobalPhaseOperation. GlobalPhaseOperation doesn't have any qubits, so it wasn't handled by my current implementation (which works for ops on exactly 1 qubit). So I just handled it separately (without involving single qubit Clifford gate). |
Craig, I can't merge this PR because you requested changes, but I addressed them. I think that some action from you is required to acknowledge that changes were made. |
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 (after merge conflict is fixed)
…into clifford-all-gates
Can we please merge this now? |
I used the fact that all 1-qubit gates can be generated by H and S gates, and there are only 24 of them (up to phase) - proof.
So, I can explicitly generate all those 24 gates as sequences of H and S gates (see generation code).
Then, I can compare given gate with all of those 24 gates and check if they differ only in phase. If so, I can implement given gate using existing implementation of S and H gates.
So, this PR ensures that Clifford simulator supports all possible 1-qubit Clifford gates.
Also updated function in mux.py which checks if circuit is Clifford circuit.
There was one test of determinism in mux_test.py which started failing, because now it's simulated on Clifford simulator. Currently Clifford simulator doesn't support taking seed parameter, so I changed that test to use another gate, which is not Clifford gate.