Skip to content

Commit cd63aad

Browse files
p51leemhucka
andauthored
Treat classically controlled ops as non-Clifford in dynamical_decoupling (#7621)
Classically controlled operations were passing `_is_clifford_op`, which led `dynamical_decoupling` to synthesize/invert through them and crash. Mark them non-Clifford for DD so they act as boundaries. Add regression test `test_classically_controlled_no_update_succeeds`. Fixes #7617 --------- Co-authored-by: Michael Hucka <mhucka@caltech.edu>
1 parent aa9a4da commit cd63aad

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

cirq-core/cirq/transformers/dynamical_decoupling.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from cirq import ops, protocols
2828
from cirq.circuits import Circuit, FrozenCircuit, Moment
2929
from cirq.protocols import unitary_protocol
30+
from cirq.protocols.control_key_protocol import control_keys
3031
from cirq.protocols.has_stabilizer_effect_protocol import has_stabilizer_effect
3132
from cirq.protocols.has_unitary_protocol import has_unitary
3233
from cirq.transformers import transformer_api
@@ -120,7 +121,7 @@ def _is_single_qubit_gate_moment(moment: Moment) -> bool:
120121

121122

122123
def _is_clifford_op(op: ops.Operation) -> bool:
123-
return has_unitary(op) and has_stabilizer_effect(op)
124+
return has_unitary(op) and has_stabilizer_effect(op) and not control_keys(op)
124125

125126

126127
def _calc_busy_moment_range_of_each_qubit(circuit: FrozenCircuit) -> dict[ops.Qid, list[int]]:

cirq-core/cirq/transformers/dynamical_decoupling_test.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import pytest
2222

2323
import cirq
24-
from cirq import add_dynamical_decoupling, CNOT, CZ, CZPowGate, H, X, Y, Z
24+
from cirq import add_dynamical_decoupling, CNOT, CZ, CZPowGate, H, I, measure, X, Y, Z
2525
from cirq.transformers.dynamical_decoupling import _CellType, _Grid
2626

2727

@@ -55,6 +55,22 @@ def assert_dd(
5555
assert_sim_eq(input_circuit, transformed_circuit)
5656

5757

58+
def test_classically_controlled_no_update_succeeds():
59+
"""Test case diagrams.
60+
Input:
61+
a: ───M───I───
62+
║ ║
63+
a: ═══@═══^═══
64+
"""
65+
a = cirq.NamedQubit('a')
66+
67+
input_circuit = cirq.Circuit(
68+
cirq.Moment(measure(a, key="a")), cirq.Moment(I(a).with_classical_controls("a"))
69+
)
70+
output_circuit = add_dynamical_decoupling(input_circuit)
71+
cirq.testing.assert_same_circuits(input_circuit, output_circuit)
72+
73+
5874
def test_no_insertion() -> None:
5975
"""Test case diagrams.
6076
Input:

0 commit comments

Comments
 (0)