Skip to content

Commit

Permalink
Bugfix in _strat_has_stabilizer_effect_from_decompose (quantumlib#6467)
Browse files Browse the repository at this point in the history
  • Loading branch information
tanujkhattar authored Feb 16, 2024
1 parent 0db32a9 commit 77df0c0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
6 changes: 1 addition & 5 deletions cirq/protocols/has_stabilizer_effect_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,7 @@ def _strat_has_stabilizer_effect_from_unitary(val: Any) -> Optional[bool]:


def _strat_has_stabilizer_effect_from_decompose(val: Any) -> Optional[bool]:
qid_shape = qid_shape_protocol.qid_shape(val, default=None)
if qid_shape is None or len(qid_shape) <= 3:
return None

decomposition = decompose_protocol.decompose_once(val, default=None)
decomposition, _, _ = decompose_protocol._try_decompose_into_operations_and_qubits(val)
if decomposition is None:
return None
for op in decomposition:
Expand Down
17 changes: 13 additions & 4 deletions cirq/protocols/has_stabilizer_effect_protocol_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ def _has_stabilizer_effect_(self):
return True


q = cirq.LineQubit(0)


class EmptyOp(cirq.Operation):
"""A trivial operation."""

def __init__(self, q: cirq.Qid = cirq.LineQubit(0)):
self.q = q

@property
def qubits(self):
return (q,)
return (self.q,)

def with_qubits(self, *new_qubits): # pragma: no cover
return self
Expand Down Expand Up @@ -97,6 +97,14 @@ def qubits(self):
return cirq.LineQubit.range(self.unitary.shape[0].bit_length() - 1)


class GateDecomposes(cirq.Gate):
def _num_qubits_(self):
return 1

def _decompose_(self, qubits):
yield YesOp(*qubits)


def test_inconclusive():
assert not cirq.has_stabilizer_effect(object())
assert not cirq.has_stabilizer_effect('boo')
Expand Down Expand Up @@ -146,3 +154,4 @@ def test_via_decompose():
assert not cirq.has_stabilizer_effect(
OpWithUnitary(cirq.unitary(cirq.Circuit(cirq.T.on_each(cirq.LineQubit.range(4)))))
)
assert cirq.has_stabilizer_effect(GateDecomposes())

0 comments on commit 77df0c0

Please sign in to comment.