`add_dynamical_decoupling` crash on classically controlled operation
Describe the issue
add-dynamical_decoupling treats classically controlled operations as Clifford because _is_clifford_op checks the operation directly:
def _is_clifford_op(op: ops.Operation) -> bool:
return has_unitary(op) and has_stabilizer_effect(op)
For a classically controlled op this passes, but later steps assumes a plain invertible gate/operation and crash.
Proposed fix: treat classically-controlled operations as non-Clifford:
def _is_clifford_op(op: ops.Operation) -> bool:
if op.gate:
return has_unitary(op.gate) and has_stabilizer_effect(op.gate)
return False
I’d like to work on this and will open a PR implementing the proposed fix.
Explain how to reproduce the bug or problem
from cirq import LineQubit, I, Circuit, measure
from cirq.transformers import add_dynamical_decoupling
q = LineQubit(0)
controlled = I(q).with_classical_controls("c")
circ = Circuit(measure(q, key="c"), controlled)
circ = add_dynamical_decoupling(circ)
Error
TypeError: object of type '<class 'list'>' isn't invertible. It has no __pow__ method (or the method returned NotImplemented) and it isn't an iterable of invertible objects.
Tell us the version of Cirq where this happens
Cirq version: 1.6.1
i would like to solve this issue . can i be assigned
@Vivek1106-04 Thank you for your interest! I've (finally) assigned it to you.
Hi @mhucka I just wanted to let you know that I already submitted a PR addressing this issue: #7621
Hi @mhucka I just wanted to let you know that I already submitted a PR addressing this issue: #7621
Whoops, thank you for saying something, and my apologies for missing that. (Sigh.) I'll assign this to you, then.