@@ -490,17 +490,17 @@ def test_cannot_remap_non_measurement_gate():
490
490
491
491
def test_circuit_diagram ():
492
492
class TaggyTag :
493
- """Tag with a custom repr function to test circuit diagrams."""
493
+ """Tag with a custom str function to test circuit diagrams."""
494
494
495
- def __repr__ (self ):
496
- return 'TaggyTag() '
495
+ def __str__ (self ):
496
+ return '<taggy> '
497
497
498
498
h = cirq .H (cirq .GridQubit (1 , 1 ))
499
499
tagged_h = h .with_tags ('tag1' )
500
500
non_string_tag_h = h .with_tags (TaggyTag ())
501
501
502
502
expected = cirq .CircuitDiagramInfo (
503
- wire_symbols = ("H[' tag1' ]" ,),
503
+ wire_symbols = ("H[tag1]" ,),
504
504
exponent = 1.0 ,
505
505
connected = True ,
506
506
exponent_qubit_index = None ,
@@ -511,14 +511,14 @@ def __repr__(self):
511
511
assert cirq .circuit_diagram_info (tagged_h , args ) == cirq .circuit_diagram_info (h )
512
512
513
513
c = cirq .Circuit (tagged_h )
514
- diagram_with_tags = "(1, 1): ───H[' tag1' ]───"
514
+ diagram_with_tags = "(1, 1): ───H[tag1]───"
515
515
diagram_without_tags = "(1, 1): ───H───"
516
516
assert str (cirq .Circuit (tagged_h )) == diagram_with_tags
517
517
assert c .to_text_diagram () == diagram_with_tags
518
518
assert c .to_text_diagram (include_tags = False ) == diagram_without_tags
519
519
520
520
c = cirq .Circuit (non_string_tag_h )
521
- diagram_with_non_string_tag = "(1, 1): ───H[TaggyTag() ]───"
521
+ diagram_with_non_string_tag = "(1, 1): ───H[<taggy> ]───"
522
522
assert c .to_text_diagram () == diagram_with_non_string_tag
523
523
assert c .to_text_diagram (include_tags = False ) == diagram_without_tags
524
524
@@ -531,7 +531,7 @@ def test_circuit_diagram_tagged_global_phase():
531
531
# Just global phase in a circuit
532
532
assert cirq .circuit_diagram_info (global_phase , default = 'default' ) == 'default'
533
533
cirq .testing .assert_has_diagram (
534
- cirq .Circuit (global_phase ), "\n \n global phase: π[' tag0' ]" , use_unicode_characters = True
534
+ cirq .Circuit (global_phase ), "\n \n global phase: π[tag0]" , use_unicode_characters = True
535
535
)
536
536
cirq .testing .assert_has_diagram (
537
537
cirq .Circuit (global_phase ),
@@ -558,9 +558,7 @@ def _circuit_diagram_info_(
558
558
no_wire_symbol_op = NoWireSymbols (coefficient = - 1.0 )().with_tags ('tag0' )
559
559
assert cirq .circuit_diagram_info (no_wire_symbol_op , default = 'default' ) == expected
560
560
cirq .testing .assert_has_diagram (
561
- cirq .Circuit (no_wire_symbol_op ),
562
- "\n \n global phase: π['tag0']" ,
563
- use_unicode_characters = True ,
561
+ cirq .Circuit (no_wire_symbol_op ), "\n \n global phase: π[tag0]" , use_unicode_characters = True
564
562
)
565
563
566
564
# Two global phases in one moment
@@ -570,9 +568,9 @@ def _circuit_diagram_info_(
570
568
cirq .testing .assert_has_diagram (
571
569
c ,
572
570
"""\
573
- a: ─────────────X───────────────────
571
+ a: ─────────────X───────────────
574
572
575
- global phase: π[' tag1', ' tag2' ]""" ,
573
+ global phase: π[tag1, tag2]""" ,
576
574
use_unicode_characters = True ,
577
575
precision = 2 ,
578
576
)
@@ -583,9 +581,9 @@ def _circuit_diagram_info_(
583
581
cirq .testing .assert_has_diagram (
584
582
c ,
585
583
"""\
586
- a: ─────────────X[' x_tag' ]─────X── ────────────
584
+ a: ─────────────X[x_tag]─────X────────────
587
585
588
- global phase: 0.5π[' tag1' ] 0.5π[' tag2' ]
586
+ global phase: 0.5π[tag1] 0.5π[tag2]
589
587
""" ,
590
588
use_unicode_characters = True ,
591
589
include_tags = True ,
@@ -603,7 +601,7 @@ def __repr__(self):
603
601
q = cirq .GridQubit (1 , 1 )
604
602
expected = "(1, 1): ───guess-i-will-repr───"
605
603
assert cirq .Circuit (NoCircuitDiagram ()(q )).to_text_diagram () == expected
606
- expected = "(1, 1): ───guess-i-will-repr[' taggy' ]───"
604
+ expected = "(1, 1): ───guess-i-will-repr[taggy]───"
607
605
assert cirq .Circuit (NoCircuitDiagram ()(q ).with_tags ('taggy' )).to_text_diagram () == expected
608
606
609
607
0 commit comments