Skip to content

Commit 6c38eed

Browse files
authored
Remove t_complexity from comparison bloqs (#996)
* Remove t_complexity from comparison bloqs - These bloqs already had call graphs. - Also fix them to pick up the number of cliffords from the other bloqs.
1 parent 71a84d2 commit 6c38eed

2 files changed

Lines changed: 9 additions & 28 deletions

File tree

qualtran/bloqs/arithmetic/comparison.py

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
from qualtran.bloqs.mcmt.and_bloq import And, MultiAnd
5252
from qualtran.bloqs.mcmt.multi_control_multi_target_pauli import MultiControlX
5353
from qualtran.cirq_interop.bit_tools import iter_bits
54-
from qualtran.cirq_interop.t_complexity_protocol import t_complexity, TComplexity
54+
from qualtran.cirq_interop.t_complexity_protocol import TComplexity
5555
from qualtran.drawing import WireSymbol
5656
from qualtran.drawing.musical_score import Text, TextBox
5757

@@ -628,12 +628,6 @@ def signature(self):
628628
a=QUInt(self.a_bitsize), b=QUInt(self.b_bitsize), target=QBit()
629629
)
630630

631-
def _t_complexity_(self) -> 'TComplexity':
632-
# TODO Determine precise clifford count and/or ignore.
633-
# See: https://github.com/quantumlib/Qualtran/issues/219
634-
# See: https://github.com/quantumlib/Qualtran/issues/217
635-
return t_complexity(LessThanEqual(self.a_bitsize, self.b_bitsize))
636-
637631
def wire_symbol(self, reg: Optional[Register], idx: Tuple[int, ...] = tuple()) -> WireSymbol:
638632
if reg is None:
639633
return Text("a>b")
@@ -646,11 +640,7 @@ def wire_symbol(self, reg: Optional[Register], idx: Tuple[int, ...] = tuple()) -
646640
raise ValueError(f'Unknown register name {reg.name}')
647641

648642
def build_call_graph(self, ssa: 'SympySymbolAllocator') -> Set['BloqCountT']:
649-
# TODO Determine precise clifford count and/or ignore.
650-
# See: https://github.com/quantumlib/Qualtran/issues/219
651-
# See: https://github.com/quantumlib/Qualtran/issues/217
652-
tc = t_complexity(LessThanEqual(self.a_bitsize, self.b_bitsize))
653-
return {(TGate(), tc.t)}
643+
return {(LessThanEqual(self.a_bitsize, self.b_bitsize), 1)}
654644

655645

656646
@bloq_example
@@ -868,12 +858,6 @@ class GreaterThanConstant(Bloq):
868858
def signature(self) -> Signature:
869859
return Signature.build_from_dtypes(x=QUInt(self.bitsize), target=QBit())
870860

871-
def _t_complexity_(self) -> TComplexity:
872-
# TODO Determine precise clifford count and/or ignore.
873-
# See: https://github.com/quantumlib/Qualtran/issues/219
874-
# See: https://github.com/quantumlib/Qualtran/issues/217
875-
return t_complexity(LessThanConstant(self.bitsize, less_than_val=self.val))
876-
877861
def wire_symbol(self, reg: Optional[Register], idx: Tuple[int, ...] = tuple()) -> WireSymbol:
878862
if reg is None:
879863
return Text("")
@@ -884,11 +868,7 @@ def wire_symbol(self, reg: Optional[Register], idx: Tuple[int, ...] = tuple()) -
884868
raise ValueError(f'Unknown register symbol {reg.name}')
885869

886870
def build_call_graph(self, ssa: 'SympySymbolAllocator') -> Set['BloqCountT']:
887-
# TODO Determine precise clifford count and/or ignore.
888-
# See: https://github.com/quantumlib/Qualtran/issues/219
889-
# See: https://github.com/quantumlib/Qualtran/issues/217
890-
tc = t_complexity(LessThanConstant(self.bitsize, less_than_val=self.val))
891-
return {(TGate(), tc.t)}
871+
return {(LessThanConstant(self.bitsize, less_than_val=self.val), 1)}
892872

893873

894874
@bloq_example
@@ -923,9 +903,6 @@ class EqualsAConstant(Bloq):
923903
def signature(self) -> Signature:
924904
return Signature.build_from_dtypes(x=QUInt(self.bitsize), target=QBit())
925905

926-
def _t_complexity_(self) -> 'TComplexity':
927-
return TComplexity(t=4 * (self.bitsize - 1))
928-
929906
def wire_symbol(self, reg: Optional[Register], idx: Tuple[int, ...] = tuple()) -> WireSymbol:
930907
if reg is None:
931908
return Text("")

qualtran/bloqs/arithmetic/comparison_test.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
LinearDepthGreaterThan,
3333
)
3434
from qualtran.cirq_interop.bit_tools import iter_bits
35+
from qualtran.cirq_interop.t_complexity_protocol import t_complexity, TComplexity
3536
from qualtran.cirq_interop.testing import (
3637
assert_circuit_inp_out_cirqsim,
3738
assert_decompose_is_consistent_with_t_complexity,
@@ -179,10 +180,10 @@ def test_greater_than_manual():
179180
anc = bb.add_register('result', 1)
180181
q0, q1, anc = bb.add(GreaterThan(bitsize, bitsize), a=q0, b=q1, target=anc)
181182
cbloq = bb.finalize(a=q0, b=q1, result=anc)
182-
cbloq.t_complexity()
183183
qlt_testing.assert_wire_symbols_match_expected(
184184
GreaterThanConstant(bitsize, 17), ['In(x)', '⨁(x > 17)']
185185
)
186+
assert cbloq.t_complexity() == t_complexity(LessThanEqual(bitsize, bitsize))
186187

187188

188189
@pytest.mark.parametrize('bitsize', [1, 2, 5])
@@ -229,10 +230,12 @@ def test_greater_than_constant():
229230
anc = bb.add_register('result', 1)
230231
q0, anc = bb.add(GreaterThanConstant(bitsize, 17), x=q0, target=anc)
231232
cbloq = bb.finalize(x=q0, result=anc)
232-
cbloq.t_complexity()
233233
qlt_testing.assert_wire_symbols_match_expected(
234234
GreaterThanConstant(bitsize, 17), ['In(x)', '⨁(x > 17)']
235235
)
236+
assert t_complexity(GreaterThanConstant(bitsize, 17)) == t_complexity(
237+
LessThanConstant(bitsize, 17)
238+
)
236239

237240

238241
def test_equals_a_constant():
@@ -246,6 +249,7 @@ def test_equals_a_constant():
246249
qlt_testing.assert_wire_symbols_match_expected(
247250
EqualsAConstant(bitsize, 17), ['In(x)', '⨁(x = 17)']
248251
)
252+
assert t_complexity(EqualsAConstant(bitsize, 17)) == TComplexity(t=4 * (bitsize - 1))
249253

250254

251255
@pytest.mark.notebook

0 commit comments

Comments
 (0)