quantumlib / Cirq

A Python framework for creating, editing, and invoking Noisy Intermediate Scale Quantum (NISQ) circuits.
Apache License 2.0
4.23k stars 1.01k forks source link

Add explicit `_act_on_` function for SingleQubitCliffordGate #5256

Open BichengYing opened 2 years ago

BichengYing commented 2 years ago

Is your feature request related to a use case or problem? Please describe. No.

Describe the solution you'd like The underlying data structure of SingleQubitCliffordGate is Clifford Tableau now but we don't have explicit _act_on_ for it. By now, the effect of SingleQubitCliffordGate applying to ActOnCliffordTableauArgs implicit works through the decomposition and act_on function of some basic gates, like X, Y, Z, H, etc. But it can be directly applied with underlying Tableau without calling decomposition. As for ActOnStabilizerCHFormArgs, I don't know if there is a way to do it through Tableau directly. We always can make that function as NotImplemented for CH_Form and fall back to old approach.

[optional] Additional context (e.g. screenshots) See #5069 for the context.

What is the urgency from your perspective for this issue? Is it blocking important work? P2 - we should do it in the next couple of quarters

tanujkhattar commented 2 years ago

Quoting Orion from Cirq Sync:

@daxfohl is doing "something" with act on args to make it cleaner and this looks related to his stuff.

daxfohl commented 2 years ago

I removed everywhere where the gates had special simulator-specific handling in their act_on implementation, basically establishing a convention that simulators were a layer on top of gates, not vice-versa. This was mostly done in #4748.

However IIUC these gates are targeted specifically to the Tableau sampler, and not be used as general-purpose gates. So it makes sense here to allow these gates to reference the Tableau directly in their act_on implementation. In fact it's a great example of when this pattern can be used, to create a special gate type specific to a simulator, without having to modify the simulator code itself.

The alternative would be to add some abstract get_custom_strategies() in act_on_stabilizer_args and append the results of that here. https://github.com/quantumlib/Cirq/blob/master/cirq-core/cirq/sim/clifford/act_on_stabilizer_args.py#L94. The default implementation would return an empty list, and the tableau implementation could return a strategy that handles SingleQubitCliffordGates.

That said, it seems like overkill and I think the act_on implementation is cleaner.