From 5bbfbf0e5b14f7d320ca2b7076b29a8dbf9762b6 Mon Sep 17 00:00:00 2001 From: rich Date: Tue, 19 Mar 2024 13:56:52 -0500 Subject: [PATCH 1/6] update drawers and tests --- cirq-core/cirq/circuits/circuit.py | 2 +- cirq-core/cirq/circuits/circuit_test.py | 4 +- cirq-core/cirq/ops/raw_types.py | 2 +- cirq-core/cirq/ops/raw_types_test.py | 24 ++-- .../circuit_diagram_info_protocol.py | 2 +- .../transformers/merge_k_qubit_gates_test.py | 46 +++--- .../merge_single_qubit_gates_test.py | 28 ++-- .../optimize_for_target_gateset_test.py | 74 +++++----- .../routing/visualize_routed_circuit_test.py | 34 ++--- cirq-core/cirq/transformers/stratify_test.py | 26 ++-- .../compilation_target_gateset_test.py | 32 ++--- .../transformer_primitives_test.py | 134 +++++++++--------- 12 files changed, 203 insertions(+), 205 deletions(-) diff --git a/cirq-core/cirq/circuits/circuit.py b/cirq-core/cirq/circuits/circuit.py index f0329266bdb..22d537c9c09 100644 --- a/cirq-core/cirq/circuits/circuit.py +++ b/cirq-core/cirq/circuits/circuit.py @@ -2630,7 +2630,7 @@ def _draw_moment_in_diagram( if desc: y = max(label_map.values(), default=0) + 1 if tags and include_tags: - desc = desc + str(tags) + desc = desc + f"[{', '.join(str(tag) for tag in tags)}]" out_diagram.write(x0, y, desc) if not non_global_ops: diff --git a/cirq-core/cirq/circuits/circuit_test.py b/cirq-core/cirq/circuits/circuit_test.py index f04c2dbc234..4494aaf9ae3 100644 --- a/cirq-core/cirq/circuits/circuit_test.py +++ b/cirq-core/cirq/circuits/circuit_test.py @@ -2305,9 +2305,9 @@ def test_diagram_global_phase(circuit_cls): cirq.testing.assert_has_diagram( c, """\ -2: ───X────────── +2: ───X──────── - π['tag']""", + π[tag]""", ) diff --git a/cirq-core/cirq/ops/raw_types.py b/cirq-core/cirq/ops/raw_types.py index 18fe6e22fc5..b3564e8e73b 100644 --- a/cirq-core/cirq/ops/raw_types.py +++ b/cirq-core/cirq/ops/raw_types.py @@ -921,7 +921,7 @@ def _circuit_diagram_info_( # Add tag to wire symbol if it exists. if sub_op_info is not NotImplemented and args.include_tags and sub_op_info.wire_symbols: sub_op_info.wire_symbols = ( - sub_op_info.wire_symbols[0] + str(list(self._tags)), + sub_op_info.wire_symbols[0] + f"[{', '.join(str(tag) for tag in self._tags)}]", ) + sub_op_info.wire_symbols[1:] return sub_op_info diff --git a/cirq-core/cirq/ops/raw_types_test.py b/cirq-core/cirq/ops/raw_types_test.py index 8acdbbacec2..20f9619efb3 100644 --- a/cirq-core/cirq/ops/raw_types_test.py +++ b/cirq-core/cirq/ops/raw_types_test.py @@ -490,9 +490,9 @@ def test_cannot_remap_non_measurement_gate(): def test_circuit_diagram(): class TaggyTag: - """Tag with a custom repr function to test circuit diagrams.""" + """Tag with a custom str function to test circuit diagrams.""" - def __repr__(self): + def __str__(self): return 'TaggyTag()' h = cirq.H(cirq.GridQubit(1, 1)) @@ -500,7 +500,7 @@ def __repr__(self): non_string_tag_h = h.with_tags(TaggyTag()) expected = cirq.CircuitDiagramInfo( - wire_symbols=("H['tag1']",), + wire_symbols=("H[tag1]",), exponent=1.0, connected=True, exponent_qubit_index=None, @@ -511,7 +511,7 @@ def __repr__(self): assert cirq.circuit_diagram_info(tagged_h, args) == cirq.circuit_diagram_info(h) c = cirq.Circuit(tagged_h) - diagram_with_tags = "(1, 1): ───H['tag1']───" + diagram_with_tags = "(1, 1): ───H[tag1]───" diagram_without_tags = "(1, 1): ───H───" assert str(cirq.Circuit(tagged_h)) == diagram_with_tags assert c.to_text_diagram() == diagram_with_tags @@ -531,7 +531,7 @@ def test_circuit_diagram_tagged_global_phase(): # Just global phase in a circuit assert cirq.circuit_diagram_info(global_phase, default='default') == 'default' cirq.testing.assert_has_diagram( - cirq.Circuit(global_phase), "\n\nglobal phase: π['tag0']", use_unicode_characters=True + cirq.Circuit(global_phase), "\n\nglobal phase: π[tag0]", use_unicode_characters=True ) cirq.testing.assert_has_diagram( cirq.Circuit(global_phase), @@ -558,9 +558,7 @@ def _circuit_diagram_info_( no_wire_symbol_op = NoWireSymbols(coefficient=-1.0)().with_tags('tag0') assert cirq.circuit_diagram_info(no_wire_symbol_op, default='default') == expected cirq.testing.assert_has_diagram( - cirq.Circuit(no_wire_symbol_op), - "\n\nglobal phase: π['tag0']", - use_unicode_characters=True, + cirq.Circuit(no_wire_symbol_op), "\n\nglobal phase: π[tag0]", use_unicode_characters=True ) # Two global phases in one moment @@ -570,9 +568,9 @@ def _circuit_diagram_info_( cirq.testing.assert_has_diagram( c, """\ -a: ─────────────X─────────────────── +a: ─────────────X─────────────── -global phase: π['tag1', 'tag2']""", +global phase: π[tag1, tag2]""", use_unicode_characters=True, precision=2, ) @@ -583,9 +581,9 @@ def _circuit_diagram_info_( cirq.testing.assert_has_diagram( c, """\ -a: ─────────────X['x_tag']─────X────────────── +a: ─────────────X[x_tag]─────X──────────── -global phase: 0.5π['tag1'] 0.5π['tag2'] +global phase: 0.5π[tag1] 0.5π[tag2] """, use_unicode_characters=True, include_tags=True, @@ -603,7 +601,7 @@ def __repr__(self): q = cirq.GridQubit(1, 1) expected = "(1, 1): ───guess-i-will-repr───" assert cirq.Circuit(NoCircuitDiagram()(q)).to_text_diagram() == expected - expected = "(1, 1): ───guess-i-will-repr['taggy']───" + expected = "(1, 1): ───guess-i-will-repr[taggy]───" assert cirq.Circuit(NoCircuitDiagram()(q).with_tags('taggy')).to_text_diagram() == expected diff --git a/cirq-core/cirq/protocols/circuit_diagram_info_protocol.py b/cirq-core/cirq/protocols/circuit_diagram_info_protocol.py index e54f0e8d2db..55c59bba527 100644 --- a/cirq-core/cirq/protocols/circuit_diagram_info_protocol.py +++ b/cirq-core/cirq/protocols/circuit_diagram_info_protocol.py @@ -354,7 +354,7 @@ def _op_info_with_fallback( # Add tags onto the representation, if they exist if op.tags: - name += f'{list(op.tags)}' + name += f"[{', '.join(str(tag) for tag in op.tags)}]" # Include ordering in the qubit labels. symbols = (name,) + tuple(f'#{i + 1}' for i in range(1, len(op.qubits))) diff --git a/cirq-core/cirq/transformers/merge_k_qubit_gates_test.py b/cirq-core/cirq/transformers/merge_k_qubit_gates_test.py index 7c28993e85f..0cb33742e57 100644 --- a/cirq-core/cirq/transformers/merge_k_qubit_gates_test.py +++ b/cirq-core/cirq/transformers/merge_k_qubit_gates_test.py @@ -122,13 +122,13 @@ def test_merge_complex_circuit_preserving_moment_structure(): cirq.testing.assert_has_diagram( c_orig, ''' -0: ───H───@───@───H───@───X───────@─────────────────X───X['ignore']───@───X─── - │ │ │ │ │ ║ -1: ───H───┼───X───────@───────Y───X───@['ignore']───────Y─────────────X───╫─── - │ │ ║ -2: ───H───X───────────────────────────X─────────────────Z─────────────M───╫─── - ║ ║ -a: ═══════════════════════════════════════════════════════════════════@═══^═══ +0: ───H───@───@───H───@───X───────@───────────────X───X[ignore]───@───X─── + │ │ │ │ │ ║ +1: ───H───┼───X───────@───────Y───X───@[ignore]───────Y───────────X───╫─── + │ │ ║ +2: ───H───X───────────────────────────X───────────────Z───────────M───╫─── + ║ ║ +a: ═══════════════════════════════════════════════════════════════@═══^═══ ''', ) component_id = 0 @@ -147,15 +147,15 @@ def rewriter_merge_to_circuit_op(op: 'cirq.CircuitOperation') -> 'cirq.OP_TREE': cirq.testing.assert_has_diagram( cirq.drop_empty_moments(c_new), ''' - [ 0: ───H───@─── ] [ 0: ───────@───H───@───X───@───X─── ] [ 0: ───────@─── ] -0: ───[ │ ]────────[ │ │ │ ]──────────────────────X['ignore']───────────[ │ ]────────X─── - [ 2: ───H───X─── ]['1'] [ 1: ───H───X───────@───Y───X─────── ]['2'] [ 1: ───Y───X─── ]['4'] ║ - │ │ │ ║ -1: ───┼─────────────────────────#2────────────────────────────────────────────@['ignore']─────────────────────────#2────────────────────────╫─── - │ │ ║ -2: ───#2──────────────────────────────────────────────────────────────────────X─────────────[ 2: ───Z─── ]['3']───M─────────────────────────╫─── - ║ ║ -a: ═══════════════════════════════════════════════════════════════════════════════════════════════════════════════@═════════════════════════^═══''', + [ 0: ───H───@─── ] [ 0: ───────@───H───@───X───@───X─── ] [ 0: ───────@─── ] +0: ───[ │ ]──────[ │ │ │ ]──────────────────X[ignore]───────────[ │ ]──────X─── + [ 2: ───H───X─── ][1] [ 1: ───H───X───────@───Y───X─────── ][2] [ 1: ───Y───X─── ][4] ║ + │ │ │ ║ +1: ───┼───────────────────────#2──────────────────────────────────────────@[ignore]───────────────────────#2──────────────────────╫─── + │ │ ║ +2: ───#2──────────────────────────────────────────────────────────────────X───────────[ 2: ───Z─── ][3]───M───────────────────────╫─── + ║ ║ +a: ═══════════════════════════════════════════════════════════════════════════════════════════════════════@═══════════════════════^═══''', ) component_id = 0 @@ -179,13 +179,13 @@ def rewriter_replace_with_decomp(op: 'cirq.CircuitOperation') -> 'cirq.OP_TREE': cirq.testing.assert_has_diagram( cirq.drop_empty_moments(c_new), ''' -0: ───T['1']───iSwap['1']───T['1']───T['2']───iSwap['2']───T['2']─────────────────X['ignore']───T['4']───iSwap['4']───T['4']───X─── - │ │ │ ║ -1: ────────────┼─────────────────────T['2']───iSwap^0.5────T['2']───@['ignore']─────────────────T['4']───iSwap^0.5────T['4']───╫─── - │ │ ║ -2: ───T['1']───iSwap^0.5────T['1']──────────────────────────────────X─────────────T['3']────────M──────────────────────────────╫─── - ║ ║ -a: ═════════════════════════════════════════════════════════════════════════════════════════════@══════════════════════════════^═══''', +0: ───T[1]───iSwap[1]────T[1]───T[2]───iSwap[2]────T[2]───────────────X[ignore]───T[4]───iSwap[4]────T[4]───X─── + │ │ │ ║ +1: ──────────┼──────────────────T[2]───iSwap^0.5───T[2]───@[ignore]───────────────T[4]───iSwap^0.5───T[4]───╫─── + │ │ ║ +2: ───T[1]───iSwap^0.5───T[1]─────────────────────────────X───────────T[3]────────M─────────────────────────╫─── + ║ ║ +a: ═══════════════════════════════════════════════════════════════════════════════@═════════════════════════^═══''', ) diff --git a/cirq-core/cirq/transformers/merge_single_qubit_gates_test.py b/cirq-core/cirq/transformers/merge_single_qubit_gates_test.py index 4b8bc688bcb..7becfba26ff 100644 --- a/cirq-core/cirq/transformers/merge_single_qubit_gates_test.py +++ b/cirq-core/cirq/transformers/merge_single_qubit_gates_test.py @@ -153,13 +153,13 @@ def test_merge_single_qubit_moments_to_phxz(): cirq.testing.assert_has_diagram( c_orig, ''' -0: ───X───────Y───@───X───────Y───Y['nocompile']───X───M─────────── - │ ║ -1: ───X───T───Y───@───X───T───Y───Z────────────────────╫───X───X─── - ║ ║ -2: ───────T───────Y───────T───────Z────────────────────╫───╫─────── - ║ ║ -a: ════════════════════════════════════════════════════@═══^═══════ +0: ───X───────Y───@───X───────Y───Y[nocompile]───X───M─────────── + │ ║ +1: ───X───T───Y───@───X───T───Y───Z──────────────────╫───X───X─── + ║ ║ +2: ───────T───────Y───────T───────Z──────────────────╫───╫─────── + ║ ║ +a: ══════════════════════════════════════════════════@═══^═══════ ''', ) context = cirq.TransformerContext(tags_to_ignore=("nocompile",)) @@ -167,13 +167,13 @@ def test_merge_single_qubit_moments_to_phxz(): cirq.testing.assert_has_diagram( c_new, ''' -0: ───PhXZ(a=-0.5,x=0,z=-1)──────@───PhXZ(a=-0.5,x=0,z=-1)──────Y['nocompile']───X───M─────────── - │ ║ -1: ───PhXZ(a=-0.25,x=0,z=0.75)───@───PhXZ(a=-0.25,x=0,z=0.75)───Z────────────────────╫───X───X─── - ║ ║ -2: ───PhXZ(a=0.25,x=0,z=0.25)────Y───PhXZ(a=0.25,x=0,z=0.25)────Z────────────────────╫───╫─────── - ║ ║ -a: ══════════════════════════════════════════════════════════════════════════════════@═══^═══════ +0: ───PhXZ(a=-0.5,x=0,z=-1)──────@───PhXZ(a=-0.5,x=0,z=-1)──────Y[nocompile]───X───M─────────── + │ ║ +1: ───PhXZ(a=-0.25,x=0,z=0.75)───@───PhXZ(a=-0.25,x=0,z=0.75)───Z──────────────────╫───X───X─── + ║ ║ +2: ───PhXZ(a=0.25,x=0,z=0.25)────Y───PhXZ(a=0.25,x=0,z=0.25)────Z──────────────────╫───╫─────── + ║ ║ +a: ════════════════════════════════════════════════════════════════════════════════@═══^═══════ ''', ) diff --git a/cirq-core/cirq/transformers/optimize_for_target_gateset_test.py b/cirq-core/cirq/transformers/optimize_for_target_gateset_test.py index e813b8a45f3..54ef36eaf43 100644 --- a/cirq-core/cirq/transformers/optimize_for_target_gateset_test.py +++ b/cirq-core/cirq/transformers/optimize_for_target_gateset_test.py @@ -53,22 +53,22 @@ def test_decompose_operations_to_target_gateset_default(): cirq.testing.assert_has_diagram( c_orig, ''' -0: ───T───×───T───×['ignore']───M───────T───×───T─── - │ │ ║ │ -1: ───────×───────×─────────────╫───X───T───×───T─── - ║ ║ -m: ═════════════════════════════@═══^═══════════════''', +0: ───T───×───T───×[ignore]───M───────T───×───T─── + │ │ ║ │ +1: ───────×───────×───────────╫───X───T───×───T─── + ║ ║ +m: ═══════════════════════════@═══^═══════════════''', ) context = cirq.TransformerContext(tags_to_ignore=("ignore",)) c_new = _decompose_operations_to_target_gateset(c_orig, context=context) cirq.testing.assert_has_diagram( c_new, ''' -0: ───T────────────@───Y^-0.5───@───Y^0.5────@───────────T───×['ignore']───M───────T────────────@───Y^-0.5───@───Y^0.5────@───────────T─── - │ │ │ │ ║ │ │ │ -1: ───────Y^-0.5───@───Y^0.5────@───Y^-0.5───@───Y^0.5───────×─────────────╫───X───T───Y^-0.5───@───Y^0.5────@───Y^-0.5───@───Y^0.5───T─── - ║ ║ -m: ════════════════════════════════════════════════════════════════════════@═══^══════════════════════════════════════════════════════════ +0: ───T────────────@───Y^-0.5───@───Y^0.5────@───────────T───×[ignore]───M───────T────────────@───Y^-0.5───@───Y^0.5────@───────────T─── + │ │ │ │ ║ │ │ │ +1: ───────Y^-0.5───@───Y^0.5────@───Y^-0.5───@───Y^0.5───────×───────────╫───X───T───Y^-0.5───@───Y^0.5────@───Y^-0.5───@───Y^0.5───T─── + ║ ║ +m: ══════════════════════════════════════════════════════════════════════@═══^══════════════════════════════════════════════════════════ ''', ) @@ -99,11 +99,11 @@ def test_decompose_operations_to_target_gateset(): cirq.testing.assert_has_diagram( c_new, ''' -0: ───H───@───X───@───H───×['ignore']───M───────H───@───X───@───H─── - │ │ │ │ ║ │ │ │ -1: ───────X───@───X───────×─────────────╫───X───H───X───@───X───H─── - ║ ║ -m: ═════════════════════════════════════@═══^═══════════════════════''', +0: ───H───@───X───@───H───×[ignore]───M───────H───@───X───@───H─── + │ │ │ │ ║ │ │ │ +1: ───────X───@───X───────×───────────╫───X───H───X───@───X───H─── + ║ ║ +m: ═══════════════════════════════════@═══^═══════════════════════''', ) with pytest.raises(ValueError, match="Unable to convert"): @@ -136,9 +136,9 @@ def test_optimize_for_target_gateset_default(): cirq.testing.assert_has_diagram( c_new, ''' -0: ───T────────────@───Y^-0.5───@───Y^0.5────@───────────T───×['ignore']─── +0: ───T────────────@───Y^-0.5───@───Y^0.5────@───────────T───×[ignore]─── │ │ │ │ -1: ───────Y^-0.5───@───Y^0.5────@───Y^-0.5───@───Y^0.5───────×───────────── +1: ───────Y^-0.5───@───Y^0.5────@───Y^-0.5───@───Y^0.5───────×─────────── ''', ) cirq.testing.assert_circuits_with_terminal_measurements_are_equivalent(c_orig, c_new, atol=1e-6) @@ -159,15 +159,15 @@ def test_optimize_for_target_gateset(): cirq.testing.assert_has_diagram( c_orig, ''' -0: ───qft───Y['ignore']───M───────qft^-1─── - │ ║ │ -1: ───#2────Y['ignore']───M───────#2─────── - │ ║ │ -2: ───#3────@['ignore']───╫───@───#3─────── - │ │ ║ ║ │ -3: ───#4────X─────────────╫───@───#4─────── - ║ ║ -m: ═══════════════════════@═══^════════════ +0: ───qft───Y[ignore]───M───────qft^-1─── + │ ║ │ +1: ───#2────Y[ignore]───M───────#2─────── + │ ║ │ +2: ───#3────@[ignore]───╫───@───#3─────── + │ │ ║ ║ │ +3: ───#4────X───────────╫───@───#4─────── + ║ ║ +m: ═════════════════════@═══^════════════ ''', ) gateset = MatrixGateTargetGateset() @@ -176,17 +176,17 @@ def test_optimize_for_target_gateset(): cirq.testing.assert_has_diagram( c_new, ''' - ┌────────┐ ┌────────┐ ┌────────┐ -0: ───M[1]──────────M[1]──────────────────────M[1]────Y['ignore']───M────────────M[1]───────────────────M[1]────────M[1]───M[1]─── - │ │ │ ║ │ │ │ │ -1: ───M[2]───M[1]───┼─────────────M[1]────M[1]┼───────Y['ignore']───M────────M[1]┼──────────────M[1]────┼───M[1]────┼──────M[2]─── - │ │ │ │ │ ║ │ │ │ │ │ │ -2: ──────────M[2]───M[2]───M[1]───┼───────M[2]┼───────@['ignore']───╫───@────M[2]┼───────M[1]───┼───────┼───M[2]────M[2]────────── - │ │ │ │ ║ ║ │ │ │ │ -3: ────────────────────────M[2]───M[2]────────M[2]────X─────────────╫───@────────M[2]────M[2]───M[2]────M[2]────────────────────── - ║ ║ -m: ═════════════════════════════════════════════════════════════════@═══^═════════════════════════════════════════════════════════ - └────────┘ └────────┘ └────────┘ + ┌────────┐ ┌────────┐ ┌────────┐ +0: ───M[1]──────────M[1]──────────────────────M[1]────Y[ignore]───M────────────M[1]───────────────────M[1]────────M[1]───M[1]─── + │ │ │ ║ │ │ │ │ +1: ───M[2]───M[1]───┼─────────────M[1]────M[1]┼───────Y[ignore]───M────────M[1]┼──────────────M[1]────┼───M[1]────┼──────M[2]─── + │ │ │ │ │ ║ │ │ │ │ │ │ +2: ──────────M[2]───M[2]───M[1]───┼───────M[2]┼───────@[ignore]───╫───@────M[2]┼───────M[1]───┼───────┼───M[2]────M[2]────────── + │ │ │ │ ║ ║ │ │ │ │ +3: ────────────────────────M[2]───M[2]────────M[2]────X───────────╫───@────────M[2]────M[2]───M[2]────M[2]────────────────────── + ║ ║ +m: ═══════════════════════════════════════════════════════════════@═══^═════════════════════════════════════════════════════════ + └────────┘ └────────┘ └────────┘ ''', ) diff --git a/cirq-core/cirq/transformers/routing/visualize_routed_circuit_test.py b/cirq-core/cirq/transformers/routing/visualize_routed_circuit_test.py index 7ab797ed10c..74e9054eb66 100644 --- a/cirq-core/cirq/transformers/routing/visualize_routed_circuit_test.py +++ b/cirq-core/cirq/transformers/routing/visualize_routed_circuit_test.py @@ -20,15 +20,15 @@ def test_routed_circuit_with_mapping_simple(): q = cirq.LineQubit.range(2) circuit = cirq.Circuit([cirq.Moment(cirq.SWAP(q[0], q[1]).with_tags(cirq.RoutingSwapTag()))]) expected_diagram = """ -0: ───q(0)───×[cirq.RoutingSwapTag()]───q(1)─── - │ │ │ -1: ───q(1)───×──────────────────────────q(0)───""" +0: ───q(0)───×[]───q(1)─── + │ │ │ +1: ───q(1)───×────────q(0)───""" cirq.testing.assert_has_diagram(cirq.routed_circuit_with_mapping(circuit), expected_diagram) expected_diagram_with_initial_mapping = """ -0: ───a───×[cirq.RoutingSwapTag()]───b─── - │ │ │ -1: ───b───×──────────────────────────a───""" +0: ───a───×[]───b─── + │ │ │ +1: ───b───×────────a───""" cirq.testing.assert_has_diagram( cirq.routed_circuit_with_mapping( circuit, {cirq.NamedQubit("a"): q[0], cirq.NamedQubit("b"): q[1]} @@ -74,16 +74,16 @@ def test_routed_circuit_with_mapping_multi_swaps(): ] ) expected_diagram = """ -0: ───q(0)──────────────────────────────────────q(0)───×[cirq.RoutingSwapTag()]───q(1)───────X─── - │ │ │ │ │ -1: ───q(1)───────────X──────────────────────────q(1)───×──────────────────────────q(0)───X───@─── - │ │ │ │ │ -2: ───q(2)───────@───@──────────────────────────q(2)───×──────────────────────────q(4)───@─────── - │ │ │ │ │ -3: ───q(3)───@───X───×──────────────────────────q(4)───×[cirq.RoutingSwapTag()]───q(2)─────────── - │ │ │ │ │ -4: ───q(4)───X───X───×[cirq.RoutingSwapTag()]───q(3)──────────────────────────────q(3)─────────── - │ │ │ │ -5: ───q(5)───────@──────────────────────────────q(5)──────────────────────────────q(5)─────────── +0: ───q(0)────────────────────q(0)───×[]───q(1)───────X─── + │ │ │ │ │ +1: ───q(1)───────────X────────q(1)───×────────q(0)───X───@─── + │ │ │ │ │ +2: ───q(2)───────@───@────────q(2)───×────────q(4)───@─────── + │ │ │ │ │ +3: ───q(3)───@───X───×────────q(4)───×[]───q(2)─────────── + │ │ │ │ │ +4: ───q(4)───X───X───×[]───q(3)────────────q(3)─────────── + │ │ │ │ +5: ───q(5)───────@────────────q(5)────────────q(5)─────────── """ cirq.testing.assert_has_diagram(cirq.routed_circuit_with_mapping(circuit), expected_diagram) diff --git a/cirq-core/cirq/transformers/stratify_test.py b/cirq-core/cirq/transformers/stratify_test.py index 0c0ee53f337..88976eb39fd 100644 --- a/cirq-core/cirq/transformers/stratify_test.py +++ b/cirq-core/cirq/transformers/stratify_test.py @@ -237,29 +237,29 @@ def test_stratify_respects_no_compile_operations(): cirq.testing.assert_has_diagram( input_circuit, ''' -0: ───X['nocompile']───────X───────iSwap─── - │ -1: ───iSwap['nocompile']───────────iSwap─── +0: ───X[nocompile]───────X───────iSwap─── + │ +1: ───iSwap[nocompile]───────────iSwap─── │ -2: ───iSwap──────────────────────────────── +2: ───iSwap────────────────────────────── -3: ────────────────────────iSwap───X─────── - │ -4: ───Z────────────────────iSwap─────────── +3: ──────────────────────iSwap───X─────── + │ +4: ───Z──────────────────iSwap─────────── ''', ) cirq.testing.assert_has_diagram( expected, ''' -0: ───────────────X['nocompile']───────X───iSwap─── - │ -1: ───────────────iSwap['nocompile']───────iSwap─── +0: ───────────────X[nocompile]───────X───iSwap─── + │ +1: ───────────────iSwap[nocompile]───────iSwap─── │ -2: ───────────────iSwap──────────────────────────── +2: ───────────────iSwap────────────────────────── -3: ───────iSwap────────────────────────X─────────── +3: ───────iSwap──────────────────────X─────────── │ -4: ───Z───iSwap──────────────────────────────────── +4: ───Z───iSwap────────────────────────────────── ''', ) cirq.testing.assert_same_circuits( diff --git a/cirq-core/cirq/transformers/target_gatesets/compilation_target_gateset_test.py b/cirq-core/cirq/transformers/target_gatesets/compilation_target_gateset_test.py index 39b5b757385..65ef918f087 100644 --- a/cirq-core/cirq/transformers/target_gatesets/compilation_target_gateset_test.py +++ b/cirq-core/cirq/transformers/target_gatesets/compilation_target_gateset_test.py @@ -138,9 +138,9 @@ def test_two_qubit_compilation_merge_and_replace_to_target_gateset(): cirq.testing.assert_has_diagram( c_orig, ''' -0: ───X───@['no_compile']───Z───X───@───Z───X─── - │ │ -1: ───Z───@─────────────────Z───────@───Z─────── +0: ───X───@[no_compile]───Z───X───@───Z───X─── + │ │ +1: ───Z───@───────────────Z───────@───Z─────── ''', ) c_new = cirq.optimize_for_target_gateset( @@ -151,9 +151,9 @@ def test_two_qubit_compilation_merge_and_replace_to_target_gateset(): cirq.testing.assert_has_diagram( c_new, ''' -0: ───X───@['no_compile']───X───@───Y───@───Z─── - │ │ │ -1: ───Z───@─────────────────X───X───Y───X───Z─── +0: ───X───@[no_compile]───X───@───Y───@───Z─── + │ │ │ +1: ───Z───@───────────────X───X───Y───X───Z─── ''', ) @@ -178,11 +178,11 @@ def test_two_qubit_compilation_merge_and_replace_inefficient_component(): cirq.testing.assert_has_diagram( c_orig, ''' -0: ───X───@───X───@['no_compile']───Z───X───@───@───Z───X───@───M─────── - │ │ │ │ │ ║ -1: ───────X───────@─────────────────Z───────X───X───Z───────X───╫───X─── - ║ ║ -m: ═════════════════════════════════════════════════════════════@═══^═══ +0: ───X───@───X───@[no_compile]───Z───X───@───@───Z───X───@───M─────── + │ │ │ │ │ ║ +1: ───────X───────@───────────────Z───────X───X───Z───────X───╫───X─── + ║ ║ +m: ═══════════════════════════════════════════════════════════@═══^═══ ''', ) c_new = cirq.optimize_for_target_gateset( @@ -193,11 +193,11 @@ def test_two_qubit_compilation_merge_and_replace_inefficient_component(): cirq.testing.assert_has_diagram( c_new, ''' -0: ───X───@───X───@['no_compile']───X───@───Y───@───Z───M─────── - │ │ │ │ ║ -1: ───────X───────@─────────────────X───X───Y───X───Z───╫───X─── - ║ ║ -m: ═════════════════════════════════════════════════════@═══^═══ +0: ───X───@───X───@[no_compile]───X───@───Y───@───Z───M─────── + │ │ │ │ ║ +1: ───────X───────@───────────────X───X───Y───X───Z───╫───X─── + ║ ║ +m: ═══════════════════════════════════════════════════@═══^═══ ''', ) diff --git a/cirq-core/cirq/transformers/transformer_primitives_test.py b/cirq-core/cirq/transformers/transformer_primitives_test.py index 957b386e92a..2da9108316a 100644 --- a/cirq-core/cirq/transformers/transformer_primitives_test.py +++ b/cirq-core/cirq/transformers/transformer_primitives_test.py @@ -140,29 +140,29 @@ def map_func(op: cirq.Operation, _: int) -> cirq.OP_TREE: cirq.testing.assert_has_diagram( c_orig_with_circuit_ops, ''' - [ [ 0: ───@─── ] ] - [ 0: ───[ │ ]────────────────────────────────────────────────────────────── ] - [ [ 1: ───X─── ](loops=2)['internal'] ] - [ │ ] - [ 1: ───#2────────────────────────────────────────────────────────────────────────── ] - [ ] - [ [ 2: ───X─── ] ] -0: ───[ 2: ───[ │ ]────────────────────────────────────────────────────────────── ]──────────────────────── - [ [ 3: ───@─── ](loops=2)['internal'] ] - [ │ ] - [ │ [ 3: ───@─── ] ] - [ 3: ───#2────────────────────────────────────[ │ ]──────────────────────── ] - [ [ 4: ───X─── ](loops=2)['internal'] ] - [ │ ] - [ 4: ─────────────────────────────────────────#2──────────────────────────────────── ](loops=6)['external'] + [ [ 0: ───@─── ] ] + [ 0: ───[ │ ]────────────────────────────────────────────────────────── ] + [ [ 1: ───X─── ](loops=2)[internal] ] + [ │ ] + [ 1: ───#2────────────────────────────────────────────────────────────────────── ] + [ ] + [ [ 2: ───X─── ] ] +0: ───[ 2: ───[ │ ]────────────────────────────────────────────────────────── ]────────────────────── + [ [ 3: ───@─── ](loops=2)[internal] ] + [ │ ] + [ │ [ 3: ───@─── ] ] + [ 3: ───#2──────────────────────────────────[ │ ]────────────────────── ] + [ [ 4: ───X─── ](loops=2)[internal] ] + [ │ ] + [ 4: ───────────────────────────────────────#2────────────────────────────────── ](loops=6)[external] │ -1: ───#2──────────────────────────────────────────────────────────────────────────────────────────────────────────── +1: ───#2────────────────────────────────────────────────────────────────────────────────────────────────────── │ -2: ───#3──────────────────────────────────────────────────────────────────────────────────────────────────────────── +2: ───#3────────────────────────────────────────────────────────────────────────────────────────────────────── │ -3: ───#4──────────────────────────────────────────────────────────────────────────────────────────────────────────── +3: ───#4────────────────────────────────────────────────────────────────────────────────────────────────────── │ -4: ───#5──────────────────────────────────────────────────────────────────────────────────────────────────────────── +4: ───#5────────────────────────────────────────────────────────────────────────────────────────────────────── ''', ) @@ -175,29 +175,29 @@ def map_func(op: cirq.Operation, _: int) -> cirq.OP_TREE: cirq.testing.assert_has_diagram( unroller(c_mapped, deep=True), ''' - [ [ 0: ───Z───@───Z─── ] ] - [ 0: ───[ │ ]────────────────────────────────────────────────────────────────────── ] - [ [ 1: ───Z───X───Z─── ](loops=2)['internal'] ] - [ │ ] - [ 1: ───#2────────────────────────────────────────────────────────────────────────────────────────── ] - [ ] - [ [ 2: ───Z───X───Z─── ] ] -0: ───[ 2: ───[ │ ]────────────────────────────────────────────────────────────────────── ]──────────────────────── - [ [ 3: ───Z───@───Z─── ](loops=2)['internal'] ] - [ │ ] - [ │ [ 3: ───Z───@───Z─── ] ] - [ 3: ───#2────────────────────────────────────────────[ │ ]──────────────────────── ] - [ [ 4: ───Z───X───Z─── ](loops=2)['internal'] ] - [ │ ] - [ 4: ─────────────────────────────────────────────────#2──────────────────────────────────────────── ](loops=6)['external'] + [ [ 0: ───Z───@───Z─── ] ] + [ 0: ───[ │ ]────────────────────────────────────────────────────────────────── ] + [ [ 1: ───Z───X───Z─── ](loops=2)[internal] ] + [ │ ] + [ 1: ───#2────────────────────────────────────────────────────────────────────────────────────── ] + [ ] + [ [ 2: ───Z───X───Z─── ] ] +0: ───[ 2: ───[ │ ]────────────────────────────────────────────────────────────────── ]────────────────────── + [ [ 3: ───Z───@───Z─── ](loops=2)[internal] ] + [ │ ] + [ │ [ 3: ───Z───@───Z─── ] ] + [ 3: ───#2──────────────────────────────────────────[ │ ]────────────────────── ] + [ [ 4: ───Z───X───Z─── ](loops=2)[internal] ] + [ │ ] + [ 4: ───────────────────────────────────────────────#2────────────────────────────────────────── ](loops=6)[external] │ -1: ───#2──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── +1: ───#2────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── │ -2: ───#3──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── +2: ───#3────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── │ -3: ───#4──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── +3: ───#4────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── │ -4: ───#5──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── +4: ───#5────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── ''', ) @@ -296,9 +296,9 @@ def test_unroll_circuit_op_and_variants(): cirq.testing.assert_has_diagram( mapped_circuit_deep, ''' -0: ───[ 0: ───X─── ]────────────────────────────────────────────────────────────X─── +0: ───[ 0: ───X─── ]──────────────────────────────────────────────────────────X─── -1: ────────────────────[ 1: ───[ 1: ───Z───Z─── ]['']─── ]─────── +1: ────────────────────[ 1: ───[ 1: ───Z───Z─── ][]─── ]─────── ''', ) for unroller in [ @@ -614,11 +614,11 @@ def test_merge_operations_merges_connected_component(): cirq.testing.assert_has_diagram( c_orig, ''' -0: ───H───@───@───H───@───X───────@───────X───X['ignore']───@─── - │ │ │ │ │ -1: ───H───┼───X───────@───────Y───X───@───────Y─────────────X─── +0: ───H───@───@───H───@───X───────@───────X───X[ignore]───@─── + │ │ │ │ │ +1: ───H───┼───X───────@───────Y───X───@───────Y───────────X─── │ │ -2: ───H───X───────────────────────────X───────────────────────── +2: ───H───X───────────────────────────X─────────────────────── ''', ) @@ -685,11 +685,11 @@ def test_merge_operations_to_circuit_op_merges_connected_component(): cirq.testing.assert_has_diagram( c_orig, ''' -0: ───H───@───@───H───@───X───────@───────X───X['ignore']───@─── - │ │ │ │ │ -1: ───H───┼───X───────@───────Y───X───@───────Y─────────────X─── +0: ───H───@───@───H───@───X───────@───────X───X[ignore]───@─── + │ │ │ │ │ +1: ───H───┼───X───────@───────Y───X───@───────Y───────────X─── │ │ -2: ───H───X───────────────────────────X───────────────────────── +2: ───H───X───────────────────────────X─────────────────────── ''', ) @@ -704,12 +704,12 @@ def can_merge(ops1: List['cirq.Operation'], ops2: List['cirq.Operation']) -> boo c_new, ''' [ 0: ───────@───H───@───X───@───X─── ] -0: ───H───@───────────[ │ │ │ ]─────────────────────────────────X['ignore']───@─── - │ [ 1: ───H───X───────@───Y───X─────── ]['merged'] │ - │ │ │ -1: ───────┼───────────#2─────────────────────────────────────────────────────────────@───────Y─────────────X─── - │ │ -2: ───H───X──────────────────────────────────────────────────────────────────────────X───────────────────────── +0: ───H───@───────────[ │ │ │ ]───────────────────────────────X[ignore]───@─── + │ [ 1: ───H───X───────@───Y───X─────── ][merged] │ + │ │ │ +1: ───────┼───────────#2───────────────────────────────────────────────────────────@───────Y───────────X─── + │ │ +2: ───H───X────────────────────────────────────────────────────────────────────────X─────────────────────── ''', ) @@ -720,11 +720,11 @@ def test_merge_2q_unitaries_to_circuit_op(): cirq.testing.assert_has_diagram( c_orig, ''' -0: ───H───@───@───H───@───X───────@───────X───X['ignore']───@─── - │ │ │ │ │ -1: ───H───┼───X───────@───────Y───X───@───────Y─────────────X─── +0: ───H───@───@───H───@───X───────@───────X───X[ignore]───@─── + │ │ │ │ │ +1: ───H───┼───X───────@───────Y───X───@───────Y───────────X─── │ │ -2: ───H───X───────────────────────────X─────────────────────M─── +2: ───H───X───────────────────────────X───────────────────M─── ''', ) @@ -734,15 +734,15 @@ def test_merge_2q_unitaries_to_circuit_op(): cirq.testing.assert_has_diagram( cirq.drop_empty_moments(c_new), ''' - [ 0: ───H───@─── ] [ 0: ───────@───H───@───X───@───X─── ] -0: ───[ │ ]─────────────[ │ │ │ ]────────────────────────────────────────────X['ignore']───@─── - [ 2: ───H───X─── ]['merged'] [ 1: ───H───X───────@───Y───X─────── ]['merged'] │ - │ │ │ - │ │ [ 1: ───@───Y─── ] │ -1: ───┼──────────────────────────────#2─────────────────────────────────────────────────[ │ ]───────────────────────────X─── - │ [ 2: ───X─────── ]['merged'] - │ │ -2: ───#2────────────────────────────────────────────────────────────────────────────────#2───────────────────────────────────────────M───''', + [ 0: ───H───@─── ] [ 0: ───────@───H───@───X───@───X─── ] +0: ───[ │ ]───────────[ │ │ │ ]────────────────────────────────────────X[ignore]───@─── + [ 2: ───H───X─── ][merged] [ 1: ───H───X───────@───Y───X─────── ][merged] │ + │ │ │ + │ │ [ 1: ───@───Y─── ] │ +1: ───┼────────────────────────────#2───────────────────────────────────────────────[ │ ]───────────────────────X─── + │ [ 2: ───X─────── ][merged] + │ │ +2: ───#2────────────────────────────────────────────────────────────────────────────#2───────────────────────────────────────M───''', ) From 2d45808b3db521f0e9f476f2b1e6de452c2c276b Mon Sep 17 00:00:00 2001 From: rich Date: Wed, 27 Mar 2024 13:01:50 -0500 Subject: [PATCH 2/6] missed an instance --- .../target_gatesets/sycamore_gateset_test.py | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/cirq-google/cirq_google/transformers/target_gatesets/sycamore_gateset_test.py b/cirq-google/cirq_google/transformers/target_gatesets/sycamore_gateset_test.py index d3cd62056b9..45459956ee7 100644 --- a/cirq-google/cirq_google/transformers/target_gatesets/sycamore_gateset_test.py +++ b/cirq-google/cirq_google/transformers/target_gatesets/sycamore_gateset_test.py @@ -49,13 +49,13 @@ def test_merge_swap_rzz_and_2q_unitaries(): cirq.testing.assert_has_diagram( c_orig, ''' - [ 0: ───@───H───@─── ] -0: ───×───ZZ───────ZZ────────×───×['ignore']───ZZ────────H───@───[ │ │ ]───────X───ZZ────────×───X['ignore']───@─── - │ │ │ │ │ │ │ [ 1: ───X───────@─── ] │ │ │ - │ │ │ │ │ │ │ │ │ │ │ -1: ───×───ZZ^0.5───ZZ^0.25───×───┼─────────────┼─────────H───┼───#2───────────────────────@───────ZZ^0.15───×───Y─────────────X─── - │ │ │ │ -2: ──────────────────────────────×─────────────ZZ^0.75───H───X────────────────────────────X─────────────────────────────────────── + [ 0: ───@───H───@─── ] +0: ───×───ZZ───────ZZ────────×───×[ignore]───ZZ────────H───@───[ │ │ ]───────X───ZZ────────×───X[ignore]───@─── + │ │ │ │ │ │ │ [ 1: ───X───────@─── ] │ │ │ + │ │ │ │ │ │ │ │ │ │ │ +1: ───×───ZZ^0.5───ZZ^0.25───×───┼───────────┼─────────H───┼───#2───────────────────────@───────ZZ^0.15───×───Y───────────X─── + │ │ │ │ +2: ──────────────────────────────×───────────ZZ^0.75───H───X────────────────────────────X───────────────────────────────────── ''', ) @@ -68,15 +68,15 @@ def test_merge_swap_rzz_and_2q_unitaries(): cirq.testing.assert_has_diagram( c_new, ''' - [ [ 0: ───@───H───@─── ] ] - [ 0: ───×───ZZ─────── ] [ 0: ───ZZ────────×─── ] [ 0: ───ZZ────────H───@─── ] [ 0: ───────[ │ │ ]───X─── ] [ 0: ───ZZ────────×─── ] [ 0: ───────@─── ] -0: ───[ │ │ ]───────────────────[ │ │ ]───────────────────×['ignore']───[ │ │ ]───────────────────────────[ [ 1: ───X───────@─── ] ]───────────────────────────[ │ │ ]───────────────────X['ignore']───[ │ ]─────────────────── - [ 1: ───×───ZZ^0.5─── ]['swap_rzz'] [ 1: ───ZZ^0.25───×─── ]['swap_rzz'] │ [ 2: ───ZZ^0.75───H───X─── ]['2q_component'] [ │ ] [ 1: ───ZZ^0.15───×─── ]['swap_rzz'] [ 1: ───Y───X─── ]['2q_component'] - │ │ │ │ [ 1: ───H───#2─────────────────────────── ]['2q_component'] │ │ - │ │ │ │ │ │ │ -1: ───#2────────────────────────────────────────#2─────────────────────────────────────────┼─────────────┼──────────────────────────────────────────────────────#2────────────────────────────────────────────────────────────@───────#2───────────────────────────────────────────────────────#2─────────────────────────────────── - │ │ │ -2: ────────────────────────────────────────────────────────────────────────────────────────×─────────────#2───────────────────────────────────────────────────────────────────────────────────────────────────────────────────X───────────────────────────────────────────────────────────────────────────────────────────────────── + [ [ 0: ───@───H───@─── ] ] + [ 0: ───×───ZZ─────── ] [ 0: ───ZZ────────×─── ] [ 0: ───ZZ────────H───@─── ] [ 0: ───────[ │ │ ]───X─── ] [ 0: ───ZZ────────×─── ] [ 0: ───────@─── ] +0: ───[ │ │ ]─────────────────[ │ │ ]─────────────────×[ignore]───[ │ │ ]─────────────────────────[ [ 1: ───X───────@─── ] ]─────────────────────────[ │ │ ]─────────────────X[ignore]───[ │ ]───────────────── + [ 1: ───×───ZZ^0.5─── ][swap_rzz] [ 1: ───ZZ^0.25───×─── ][swap_rzz] │ [ 2: ───ZZ^0.75───H───X─── ][2q_component] [ │ ] [ 1: ───ZZ^0.15───×─── ][swap_rzz] [ 1: ───Y───X─── ][2q_component] + │ │ │ │ [ 1: ───H───#2─────────────────────────── ][2q_component] │ │ + │ │ │ │ │ │ │ +1: ───#2──────────────────────────────────────#2───────────────────────────────────────┼───────────┼────────────────────────────────────────────────────#2──────────────────────────────────────────────────────────@───────#2───────────────────────────────────────────────────#2───────────────────────────────── + │ │ │ +2: ────────────────────────────────────────────────────────────────────────────────────×───────────#2───────────────────────────────────────────────────────────────────────────────────────────────────────────────X─────────────────────────────────────────────────────────────────────────────────────────────── ''', ) From 311207983336781984d89b8c7b1e0203ce3a0b8e Mon Sep 17 00:00:00 2001 From: rich Date: Wed, 27 Mar 2024 13:06:10 -0500 Subject: [PATCH 3/6] update test --- cirq-core/cirq/ops/raw_types_test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cirq-core/cirq/ops/raw_types_test.py b/cirq-core/cirq/ops/raw_types_test.py index 20f9619efb3..031f73256d6 100644 --- a/cirq-core/cirq/ops/raw_types_test.py +++ b/cirq-core/cirq/ops/raw_types_test.py @@ -493,7 +493,7 @@ class TaggyTag: """Tag with a custom str function to test circuit diagrams.""" def __str__(self): - return 'TaggyTag()' + return '' h = cirq.H(cirq.GridQubit(1, 1)) tagged_h = h.with_tags('tag1') @@ -518,7 +518,7 @@ def __str__(self): assert c.to_text_diagram(include_tags=False) == diagram_without_tags c = cirq.Circuit(non_string_tag_h) - diagram_with_non_string_tag = "(1, 1): ───H[TaggyTag()]───" + diagram_with_non_string_tag = "(1, 1): ───H[]───" assert c.to_text_diagram() == diagram_with_non_string_tag assert c.to_text_diagram(include_tags=False) == diagram_without_tags From 4fff692dd2940a17b40f52bb19ff40092d07dd93 Mon Sep 17 00:00:00 2001 From: rich Date: Wed, 27 Mar 2024 14:34:58 -0500 Subject: [PATCH 4/6] nit --- cirq-core/cirq/ops/raw_types_test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cirq-core/cirq/ops/raw_types_test.py b/cirq-core/cirq/ops/raw_types_test.py index 031f73256d6..a8b464f58ea 100644 --- a/cirq-core/cirq/ops/raw_types_test.py +++ b/cirq-core/cirq/ops/raw_types_test.py @@ -493,7 +493,7 @@ class TaggyTag: """Tag with a custom str function to test circuit diagrams.""" def __str__(self): - return '' + return '' h = cirq.H(cirq.GridQubit(1, 1)) tagged_h = h.with_tags('tag1') @@ -518,7 +518,7 @@ def __str__(self): assert c.to_text_diagram(include_tags=False) == diagram_without_tags c = cirq.Circuit(non_string_tag_h) - diagram_with_non_string_tag = "(1, 1): ───H[]───" + diagram_with_non_string_tag = "(1, 1): ───H[]───" assert c.to_text_diagram() == diagram_with_non_string_tag assert c.to_text_diagram(include_tags=False) == diagram_without_tags From 160ef83bdec96cf37771346e43835855a2aa5b2e Mon Sep 17 00:00:00 2001 From: richrines1 <85512171+richrines1@users.noreply.github.com> Date: Tue, 9 Apr 2024 15:35:59 -0500 Subject: [PATCH 5/6] Update cirq-core/cirq/circuits/circuit.py Co-authored-by: Pavol Juhas --- cirq-core/cirq/circuits/circuit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cirq-core/cirq/circuits/circuit.py b/cirq-core/cirq/circuits/circuit.py index 22d537c9c09..0f6895991d5 100644 --- a/cirq-core/cirq/circuits/circuit.py +++ b/cirq-core/cirq/circuits/circuit.py @@ -2630,7 +2630,7 @@ def _draw_moment_in_diagram( if desc: y = max(label_map.values(), default=0) + 1 if tags and include_tags: - desc = desc + f"[{', '.join(str(tag) for tag in tags)}]" + desc = desc + f"[{', '.join(map(str, tags))}]" out_diagram.write(x0, y, desc) if not non_global_ops: From c67984d2b64241e0e1d5c447de7b0d801932d007 Mon Sep 17 00:00:00 2001 From: Pavol Juhas Date: Tue, 9 Apr 2024 17:19:55 -0700 Subject: [PATCH 6/6] Use map to construct the tag string --- cirq-core/cirq/ops/raw_types.py | 2 +- cirq-core/cirq/protocols/circuit_diagram_info_protocol.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cirq-core/cirq/ops/raw_types.py b/cirq-core/cirq/ops/raw_types.py index b3564e8e73b..64bf87ae5bb 100644 --- a/cirq-core/cirq/ops/raw_types.py +++ b/cirq-core/cirq/ops/raw_types.py @@ -921,7 +921,7 @@ def _circuit_diagram_info_( # Add tag to wire symbol if it exists. if sub_op_info is not NotImplemented and args.include_tags and sub_op_info.wire_symbols: sub_op_info.wire_symbols = ( - sub_op_info.wire_symbols[0] + f"[{', '.join(str(tag) for tag in self._tags)}]", + sub_op_info.wire_symbols[0] + f"[{', '.join(map(str, self._tags))}]", ) + sub_op_info.wire_symbols[1:] return sub_op_info diff --git a/cirq-core/cirq/protocols/circuit_diagram_info_protocol.py b/cirq-core/cirq/protocols/circuit_diagram_info_protocol.py index 2e1da77926f..3b6b3445912 100644 --- a/cirq-core/cirq/protocols/circuit_diagram_info_protocol.py +++ b/cirq-core/cirq/protocols/circuit_diagram_info_protocol.py @@ -356,7 +356,7 @@ def _op_info_with_fallback( # Add tags onto the representation, if they exist if op.tags: - name += f"[{', '.join(str(tag) for tag in op.tags)}]" + name += f"[{', '.join(map(str, op.tags))}]" # Include ordering in the qubit labels. symbols = (name,) + tuple(f'#{i + 1}' for i in range(1, len(op.qubits)))