-
Notifications
You must be signed in to change notification settings - Fork 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
Add CliffordSimulator to cirq.Sample #2600
Conversation
smitsanghavi
commented
Nov 26, 2019
- cirq.sample calls CliffordSimulator when appropriate.
- All simulators called by cirq.sample now support 0 repetitions even when measurements are not terminal
- ClifforSimulator exposes supported gates and supports Param resolution
…called by cirq.sample now support 0 repititions even when measurements are not terminal
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
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 is a good start, but we're going to need some pretty wide ranging changes to enable making this change. We need to define three new protocols:
-
has_stabilizer_effect(self) -> bool
Operations and other objects can implement
_has_stabilizer_effect_
to indicate they are compatible with stabilizer simulation. We should add this to all existing stabilizer effects in Cirq, and also augment the standardized tests for gates to include a test like "if it has a stabilizer effect it better have the_has_stabilizer_effect_
method for efficiency" similar to the test we already have forhas_unitary
. If an object does not implement_has_stabilizer_effect_
the globalhas_stabilizer_effect
method will fall back to calling or_decompose_into_stabilizer_operations_
or else falling back to calling_decompose_
and checking if all the resulting operations all have stabilizer effects. -
decompose_into_stabilizer_operations(self) -> List['cirq.Operation']
Operations and other objects can implement
_decompose_into_stabilizer_operations_
to specify a decomposition into operations with stabilizer effects.If an object does not implement
_decompose_into_stabilizer_operations_
, the globaldecompose_into_stabilizer_operations
method will fall back to calling_decompose_
. -
apply_stabilizer_effect_to_ch_form(self, args: 'cirq.ApplyStabilizerEffectToChFormArgs')
"Atomic" operations that can't be decomposed into other stabilizer effects can specify this method for the Clifford simulator to call. The
ApplyStabilizerEffectToChFormArgs
would contain both the ch_form attribute and also a measurement record attribute.
We should include a unit test that defines a test gate that has a stabilizer effect via decomposition and via apply, and confirm that it works despite the simulator not knowing about it directly.
cirq/sim/mux.py
Outdated
|
||
if TYPE_CHECKING: | ||
import cirq | ||
|
||
|
||
def _is_clifford_circuit(program: 'cirq.Circuit') -> bool: | ||
return all( | ||
op.gate in clifford_simulator.CliffordSimulator.get_supported_gates() |
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 check will fail on gates that decompose into Clifford operations, such as cirq.ISWAP.
I think what we need to do here is to define an is clifford protocol as well as formalize the decompose_into_clifford
protocol. This line would then reduce to has_clifford(circuit)
.
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 TODO for now
I agree with the need to implement all the changes you suggested to make this fully work as intended in #2423 . This is just the initial version which aims to get this to start working for the simplest eligible circuits. Added a TODO to document that this approach is not permanent. |
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 as an interim thing