Skip to content

Commit 416bafd

Browse files
committed
Be precise which 2-cycle needs to be avoided in the decomposition.
1 parent 551b87d commit 416bafd

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

cirq-core/cirq/ops/controlled_gate.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,12 @@ def _decompose_with_context_(
163163
self.num_controls(), self.control_values, self.control_qid_shape
164164
)
165165
# Prefer the subgate controlled version if available
166-
if controlled_sub_gate.__class__ != self.__class__:
167-
return controlled_sub_gate.on(*qubits)
166+
if self != controlled_sub_gate:
167+
# Prevent 2-cycle from appearing in recursive decomposition
168+
if not isinstance(controlled_sub_gate, ControlledGate) or not isinstance(
169+
controlled_sub_gate.sub_gate, common_gates.CZPowGate
170+
):
171+
return controlled_sub_gate.on(*qubits)
168172
if (
169173
protocols.has_unitary(self.sub_gate)
170174
and protocols.num_qubits(self.sub_gate) == 1

0 commit comments

Comments
 (0)