Skip to content

Commit fefe350

Browse files
authored
Make SingleQubitCompare output registers directional (#6312)
1 parent fee056e commit fefe350

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

cirq-ft/cirq_ft/algos/arithmetic_gates.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,15 @@ class SingleQubitCompare(infra.GateWithRegisters):
222222

223223
@cached_property
224224
def signature(self) -> infra.Signature:
225-
return infra.Signature.build(a=1, b=1, less_than=1, greater_than=1)
225+
one_side = infra.Side.RIGHT if not self.adjoint else infra.Side.LEFT
226+
return infra.Signature(
227+
[
228+
infra.Register('a', 1),
229+
infra.Register('b', 1),
230+
infra.Register('less_than', 1, side=one_side),
231+
infra.Register('greater_than', 1, side=one_side),
232+
]
233+
)
226234

227235
def __repr__(self) -> str:
228236
return f'cirq_ft.algos.SingleQubitCompare({self.adjoint})'

cirq-ft/cirq_ft/algos/arithmetic_gates_test.py

+3
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,9 @@ def test_single_qubit_compare_protocols(adjoint: bool):
357357
g = cirq_ft.algos.SingleQubitCompare(adjoint=adjoint)
358358
cirq_ft.testing.assert_decompose_is_consistent_with_t_complexity(g)
359359
cirq.testing.assert_equivalent_repr(g, setup_code='import cirq_ft')
360+
expected_side = cirq_ft.infra.Side.LEFT if adjoint else cirq_ft.infra.Side.RIGHT
361+
assert g.signature[2] == cirq_ft.Register('less_than', 1, side=expected_side)
362+
assert g.signature[3] == cirq_ft.Register('greater_than', 1, side=expected_side)
360363

361364
with pytest.raises(ValueError):
362365
_ = g**0.5 # type: ignore

0 commit comments

Comments
 (0)