Skip to content

Commit 21922ee

Browse files
authored
Remove pretty_name part 1 (#1340)
* Remove pretty_name part 1 * Fix tests * test changes * rotation strings * flaky test
1 parent 7e318f2 commit 21922ee

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+230
-227
lines changed

qualtran/_infra/adjoint_test.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,12 @@ def test_call_graph():
135135

136136
def test_names():
137137
atom = TestAtom()
138-
assert atom.pretty_name() == "TestAtom"
138+
assert str(atom) == "TestAtom"
139139
assert cast(Text, atom.wire_symbol(reg=None)).text == "TestAtom"
140140

141141
adj_atom = Adjoint(atom)
142-
assert adj_atom.pretty_name() == "TestAtom"
142+
assert str(adj_atom) == "Adjoint(subbloq=TestAtom)"
143143
assert cast(Text, adj_atom.wire_symbol(reg=None)).text == "TestAtom†"
144-
assert str(adj_atom) == "Adjoint(subbloq=TestAtom())"
145144

146145

147146
def test_wire_symbol():

qualtran/_infra/bloq.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def signature(self) -> 'Signature':
111111
"""
112112

113113
def pretty_name(self) -> str:
114-
return self.__class__.__name__
114+
return str(self)
115115

116116
def build_composite_bloq(self, bb: 'BloqBuilder', **soqs: 'SoquetT') -> Dict[str, 'SoquetT']:
117117
"""Override this method to define a Bloq in terms of its constituent parts.

qualtran/_infra/composite_bloq_test.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -446,24 +446,24 @@ def test_add_from(call_decompose):
446446
--------------------
447447
Split<1>
448448
TestParallelCombo<0>.reg -> reg
449-
reg[0] -> TestAtom()<2>.q
450-
reg[1] -> TestAtom()<3>.q
451-
reg[2] -> TestAtom()<4>.q
449+
reg[0] -> TestAtom<2>.q
450+
reg[1] -> TestAtom<3>.q
451+
reg[2] -> TestAtom<4>.q
452452
--------------------
453-
TestAtom()<2>
453+
TestAtom<2>
454454
Split<1>.reg[0] -> q
455455
q -> Join<5>.reg[0]
456-
TestAtom()<3>
456+
TestAtom<3>
457457
Split<1>.reg[1] -> q
458458
q -> Join<5>.reg[1]
459-
TestAtom()<4>
459+
TestAtom<4>
460460
Split<1>.reg[2] -> q
461461
q -> Join<5>.reg[2]
462462
--------------------
463463
Join<5>
464-
TestAtom()<2>.q -> reg[0]
465-
TestAtom()<3>.q -> reg[1]
466-
TestAtom()<4>.q -> reg[2]
464+
TestAtom<2>.q -> reg[0]
465+
TestAtom<3>.q -> reg[1]
466+
TestAtom<4>.q -> reg[2]
467467
reg -> RightDangle.stuff"""
468468
)
469469

qualtran/_infra/controlled.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -478,11 +478,6 @@ def wire_symbol(self, reg: Optional[Register], idx: Tuple[int, ...] = tuple()) -
478478
def adjoint(self) -> 'Bloq':
479479
return self.subbloq.adjoint().controlled(ctrl_spec=self.ctrl_spec)
480480

481-
def pretty_name(self) -> str:
482-
num_ctrls = self.ctrl_spec.num_qubits
483-
ctrl_string = 'C' if num_ctrls == 1 else f'C[{num_ctrls}]'
484-
return f'{ctrl_string}[{self.subbloq.pretty_name()}]'
485-
486481
def __str__(self) -> str:
487482
num_ctrls = self.ctrl_spec.num_qubits
488483
ctrl_string = 'C' if num_ctrls == 1 else f'C[{num_ctrls}]'

qualtran/_infra/controlled_test.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -212,32 +212,32 @@ def test_controlled_parallel():
212212
== """\
213213
Split<0>
214214
LeftDangle.reg -> reg
215-
reg[0] -> C[TestAtom()]<1>.q
216-
reg[1] -> C[TestAtom()]<2>.q
217-
reg[2] -> C[TestAtom()]<3>.q
215+
reg[0] -> C[TestAtom]<1>.q
216+
reg[1] -> C[TestAtom]<2>.q
217+
reg[2] -> C[TestAtom]<3>.q
218218
--------------------
219-
C[TestAtom()]<1>
219+
C[TestAtom]<1>
220220
LeftDangle.ctrl -> ctrl
221221
Split<0>.reg[0] -> q
222-
ctrl -> C[TestAtom()]<2>.ctrl
222+
ctrl -> C[TestAtom]<2>.ctrl
223223
q -> Join<4>.reg[0]
224224
--------------------
225-
C[TestAtom()]<2>
226-
C[TestAtom()]<1>.ctrl -> ctrl
225+
C[TestAtom]<2>
226+
C[TestAtom]<1>.ctrl -> ctrl
227227
Split<0>.reg[1] -> q
228-
ctrl -> C[TestAtom()]<3>.ctrl
228+
ctrl -> C[TestAtom]<3>.ctrl
229229
q -> Join<4>.reg[1]
230230
--------------------
231-
C[TestAtom()]<3>
232-
C[TestAtom()]<2>.ctrl -> ctrl
231+
C[TestAtom]<3>
232+
C[TestAtom]<2>.ctrl -> ctrl
233233
Split<0>.reg[2] -> q
234234
q -> Join<4>.reg[2]
235235
ctrl -> RightDangle.ctrl
236236
--------------------
237237
Join<4>
238-
C[TestAtom()]<1>.q -> reg[0]
239-
C[TestAtom()]<2>.q -> reg[1]
240-
C[TestAtom()]<3>.q -> reg[2]
238+
C[TestAtom]<1>.q -> reg[0]
239+
C[TestAtom]<2>.q -> reg[1]
240+
C[TestAtom]<3>.q -> reg[2]
241241
reg -> RightDangle.reg"""
242242
)
243243

@@ -247,7 +247,7 @@ def test_doubly_controlled():
247247
assert (
248248
bloq.as_composite_bloq().debug_text()
249249
== """\
250-
C[C[TestAtom()]]<0>
250+
C[C[TestAtom]]<0>
251251
LeftDangle.ctrl2 -> ctrl2
252252
LeftDangle.ctrl -> ctrl
253253
LeftDangle.q -> q

qualtran/_infra/quantum_graph_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,4 @@ def test_bloq_instance():
7070
binst_a = BloqInstance(TestAtom(), i=1)
7171
binst_b = BloqInstance(TestAtom(), i=1)
7272
assert binst_a == binst_b
73-
assert str(binst_a) == 'TestAtom()<1>'
73+
assert str(binst_a) == 'TestAtom<1>'

qualtran/bloqs/arithmetic/addition.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,9 +308,6 @@ def on_classical_vals(
308308
def with_registers(self, *new_registers: Union[int, Sequence[int]]):
309309
raise NotImplementedError("no need to implement with_registers.")
310310

311-
def pretty_name(self) -> str:
312-
return "c = a + b"
313-
314311
def decompose_from_registers(
315312
self, *, context: cirq.DecompositionContext, **quregs: NDArray[cirq.Qid]
316313
) -> cirq.OP_TREE:
@@ -340,6 +337,11 @@ def __pow__(self, power: int):
340337
return OutOfPlaceAdder(self.bitsize, is_adjoint=not self.is_adjoint)
341338
raise NotImplementedError("OutOfPlaceAdder.__pow__ defined only for +1/-1.")
342339

340+
def wire_symbol(self, reg: Optional[Register], idx: Tuple[int, ...] = tuple()) -> 'WireSymbol':
341+
if reg is None:
342+
return Text('c=a+b')
343+
return super().wire_symbol(reg, idx)
344+
343345

344346
@bloq_example(generalizer=ignore_split_join)
345347
def _add_oop_symb() -> OutOfPlaceAdder:

qualtran/bloqs/arithmetic/hamming_weight.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,6 @@ def bit_count_of_bitsize(self) -> SymbolicInt:
7979
return 1 # worst case
8080
return self.bitsize.bit_count()
8181

82-
def pretty_name(self) -> str:
83-
return "out = x.bit_count()"
84-
8582
def _three_to_two_adder(self, a, b, c, out) -> cirq.OP_TREE:
8683
return [
8784
[cirq.CX(a, b), cirq.CX(a, c)],

qualtran/bloqs/arithmetic/sorting.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,6 @@ def signature(self):
7373
]
7474
)
7575

76-
def pretty_name(self) -> str:
77-
return "Cmprtr"
78-
7976
def build_composite_bloq(
8077
self, bb: 'BloqBuilder', a: 'Soquet', b: 'Soquet'
8178
) -> dict[str, 'SoquetT']:
@@ -357,9 +354,6 @@ def num_comparisons(self) -> SymbolicInt:
357354
logk = bit_length(self.k - 1)
358355
return (self.k // 2) * ((logk * (logk + 1)) // 2)
359356

360-
def pretty_name(self) -> str:
361-
return "BSort"
362-
363357
def is_symbolic(self):
364358
return is_symbolic(self.bitsize, self.k)
365359

qualtran/bloqs/arithmetic/trigonometric/arcsin.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,6 @@ def signature(self):
7272
]
7373
)
7474

75-
def pretty_name(self) -> str:
76-
return "arcsin(x)"
77-
7875
def on_classical_vals(
7976
self, x: ClassicalValT, result: ClassicalValT
8077
) -> Dict[str, ClassicalValT]:

0 commit comments

Comments
 (0)