Cirq icon indicating copy to clipboard operation
Cirq copied to clipboard

`add_dynamical_decoupling` crash on classically controlled operation

Open p51lee opened this issue 3 months ago • 4 comments

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

p51lee avatar Aug 31 '25 12:08 p51lee

i would like to solve this issue . can i be assigned

Vivek1106-04 avatar Oct 29 '25 07:10 Vivek1106-04

@Vivek1106-04 Thank you for your interest! I've (finally) assigned it to you.

mhucka avatar Nov 28 '25 01:11 mhucka

Hi @mhucka I just wanted to let you know that I already submitted a PR addressing this issue: #7621

p51lee avatar Nov 28 '25 01:11 p51lee

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.

mhucka avatar Nov 29 '25 03:11 mhucka