From 4000e7335963755c4475a776fe7434e9976dc800 Mon Sep 17 00:00:00 2001 From: daxfo Date: Sun, 6 Apr 2025 11:58:38 -0700 Subject: [PATCH 1/5] Change classical control diagram symbols --- .../ops/classically_controlled_operation.py | 8 +- .../classically_controlled_operation_test.py | 98 +++++++++---------- cirq-core/cirq/ops/measurement_gate.py | 2 +- cirq-core/cirq/ops/pauli_measurement_gate.py | 2 +- .../transformers/merge_k_qubit_gates_test.py | 6 +- .../merge_single_qubit_gates_test.py | 4 +- .../optimize_for_target_gateset_test.py | 10 +- cirq-core/cirq/transformers/stratify_test.py | 4 +- .../compilation_target_gateset_test.py | 4 +- examples/quantum_teleportation.py | 4 +- 10 files changed, 71 insertions(+), 71 deletions(-) diff --git a/cirq-core/cirq/ops/classically_controlled_operation.py b/cirq-core/cirq/ops/classically_controlled_operation.py index 94465215a3b..99a37097e47 100644 --- a/cirq-core/cirq/ops/classically_controlled_operation.py +++ b/cirq-core/cirq/ops/classically_controlled_operation.py @@ -58,7 +58,7 @@ class ClassicallyControlledOperation(raw_types.Operation): ║ 1: ─────────────╫───X─── ║ ║ - control_key: ═══@═══^═══ + control_key: ═══V═══@═══ >>> circuit2 = cirq.Circuit([ ... cirq.measure(a, key='control_key1'), ... cirq.measure(b, key='control_key2'), @@ -71,9 +71,9 @@ class ClassicallyControlledOperation(raw_types.Operation): ║║ 2: ───────────────╫╫────X─── ║║ ║ - control_key1: ════@╬════^═══ + control_key1: ════V╬════@═══ ║ ║ - control_key2: ═════@════^═══ + control_key2: ═════V════@═══ └──┘ """ @@ -189,7 +189,7 @@ def _circuit_diagram_info_( control_label_count = 0 if args.label_map is not None: control_label_count = len({k for c in self._conditions for k in c.keys}) - wire_symbols = sub_info.wire_symbols + ('^',) * control_label_count + wire_symbols = sub_info.wire_symbols + ('@',) * control_label_count if control_label_count == 0 or any( not isinstance(c, value.KeyCondition) for c in self._conditions ): diff --git a/cirq-core/cirq/ops/classically_controlled_operation_test.py b/cirq-core/cirq/ops/classically_controlled_operation_test.py index 50bdc647a05..7388ceff447 100644 --- a/cirq-core/cirq/ops/classically_controlled_operation_test.py +++ b/cirq-core/cirq/ops/classically_controlled_operation_test.py @@ -33,7 +33,7 @@ def test_diagram(): ║ 1: ───╫───X─── ║ ║ -a: ═══@═══^═══ +a: ═══V═══@═══ """, use_unicode_characters=True, ) @@ -53,7 +53,7 @@ def test_diagram_pauli(): ║ 1: ───╫──────X─── ║ ║ -a: ═══@══════^═══ +a: ═══V══════@═══ """, use_unicode_characters=True, ) @@ -74,7 +74,7 @@ def test_diagram_extra_measurements(): ║ 1: ───╫───X──────── ║ ║ -a: ═══@═══^════════ +a: ═══V═══@════════ """, use_unicode_characters=True, ) @@ -91,7 +91,7 @@ def test_diagram_extra_controlled_bits(): ║ ║ 1: ───╫───X─── ║ ║ -a: ═══@═══^═══ +a: ═══V═══@═══ """, use_unicode_characters=True, ) @@ -112,9 +112,9 @@ def test_diagram_extra_control_bits(): ║ ║ 1: ───╫───╫───X─── ║ ║ ║ -a: ═══@═══╬═══^═══ +a: ═══V═══╬═══@═══ ║ ║ -b: ═══════@═══^═══ +b: ═══════V═══@═══ """, use_unicode_characters=True, ) @@ -137,9 +137,9 @@ def test_diagram_multiple_ops_single_moment(): ║ ║ 1: ────╫M─────╫X──── ║║ ║║ -a: ════@╬═════^╬════ +a: ════V╬═════@╬════ ║ ║ -b: ═════@══════^════ +b: ═════V══════@════ └──┘ └──┘ """, use_unicode_characters=True, @@ -161,7 +161,7 @@ def test_diagram_subcircuit(): [ ║ ] 0: ───[ 1: ───╫───X─── ]─── [ ║ ║ ] - [ a: ═══@═══^═══ ] + [ a: ═══V═══@═══ ] │ 1: ───#2─────────────────── """, @@ -186,11 +186,11 @@ def test_diagram_subcircuit_layered(): [ ║ ] 0: ───M───[ 1: ───╫───X─── ]─────── ║ [ ║ ║ ] - ║ [ a: ═══@═══^═══ ] + ║ [ a: ═══V═══@═══ ] ║ ║ 1: ───╫───#2───────────────────X─── ║ ║ ║ -a: ═══@═══╩════════════════════^═══ +a: ═══V═══╩════════════════════@═══ """, use_unicode_characters=True, ) @@ -509,7 +509,7 @@ def test_scope_local(): """ [ [ 0: ───M───X─── ] ] 0: ───[ 0: ───[ ║ ║ ]───────────────────────────────────── ]───────────────────────────────────── - [ [ a: ═══@═══^═══ ](loops=2, use_repetition_ids=True) ](loops=2, use_repetition_ids=True) + [ [ a: ═══V═══@═══ ](loops=2, use_repetition_ids=True) ](loops=2, use_repetition_ids=True) """, use_unicode_characters=True, ) @@ -519,13 +519,13 @@ def test_scope_local(): """ 0: ───────M───X───M───X───M───X───M───X─── ║ ║ ║ ║ ║ ║ ║ ║ -0:0:a: ═══@═══^═══╬═══╬═══╬═══╬═══╬═══╬═══ +0:0:a: ═══V═══@═══╬═══╬═══╬═══╬═══╬═══╬═══ ║ ║ ║ ║ ║ ║ -0:1:a: ═══════════@═══^═══╬═══╬═══╬═══╬═══ +0:1:a: ═══════════V═══@═══╬═══╬═══╬═══╬═══ ║ ║ ║ ║ -1:0:a: ═══════════════════@═══^═══╬═══╬═══ +1:0:a: ═══════════════════V═══@═══╬═══╬═══ ║ ║ -1:1:a: ═══════════════════════════@═══^═══ +1:1:a: ═══════════════════════════V═══@═══ """, use_unicode_characters=True, ) @@ -553,7 +553,7 @@ def test_scope_flatten_both(): """ [ [ 0: ───M───X─── ] ] 0: ───[ 0: ───[ ║ ║ ]──────────── ]──────────── - [ [ a: ═══@═══^═══ ](loops=2) ](loops=2) + [ [ a: ═══V═══@═══ ](loops=2) ](loops=2) """, use_unicode_characters=True, ) @@ -562,7 +562,7 @@ def test_scope_flatten_both(): """ 0: ───M───X───M───X───M───X───M───X─── ║ ║ ║ ║ ║ ║ ║ ║ -a: ═══@═══^═══@═══^═══@═══^═══@═══^═══ +a: ═══V═══@═══V═══@═══V═══@═══V═══@═══ """, use_unicode_characters=True, ) @@ -587,7 +587,7 @@ def test_scope_flatten_inner(): """ [ [ 0: ───M───X─── ] ] 0: ───[ 0: ───[ ║ ║ ]──────────── ]───────────────────────────────────── - [ [ a: ═══@═══^═══ ](loops=2) ](loops=2, use_repetition_ids=True) + [ [ a: ═══V═══@═══ ](loops=2) ](loops=2, use_repetition_ids=True) """, use_unicode_characters=True, ) @@ -596,9 +596,9 @@ def test_scope_flatten_inner(): """ 0: ─────M───X───M───X───M───X───M───X─── ║ ║ ║ ║ ║ ║ ║ ║ -0:a: ═══@═══^═══@═══^═══╬═══╬═══╬═══╬═══ +0:a: ═══V═══@═══V═══@═══╬═══╬═══╬═══╬═══ ║ ║ ║ ║ -1:a: ═══════════════════@═══^═══@═══^═══ +1:a: ═══════════════════V═══@═══V═══@═══ """, use_unicode_characters=True, ) @@ -623,7 +623,7 @@ def test_scope_flatten_outer(): """ [ [ 0: ───M───X─── ] ] 0: ───[ 0: ───[ ║ ║ ]───────────────────────────────────── ]──────────── - [ [ a: ═══@═══^═══ ](loops=2, use_repetition_ids=True) ](loops=2) + [ [ a: ═══V═══@═══ ](loops=2, use_repetition_ids=True) ](loops=2) """, use_unicode_characters=True, ) @@ -632,9 +632,9 @@ def test_scope_flatten_outer(): """ 0: ─────M───X───M───X───M───X───M───X─── ║ ║ ║ ║ ║ ║ ║ ║ -0:a: ═══@═══^═══╬═══╬═══@═══^═══╬═══╬═══ +0:a: ═══V═══@═══╬═══╬═══V═══@═══╬═══╬═══ ║ ║ ║ ║ -1:a: ═══════════@═══^═══════════@═══^═══ +1:a: ═══════════V═══@═══════════V═══@═══ """, use_unicode_characters=True, ) @@ -663,9 +663,9 @@ def test_scope_extern(): """ [ [ 0: ───M('a')───X─── ] ] [ 0: ───M───[ ║ ]───────────────────────────────────── ] -0: ───[ ║ [ b: ════════════^═══ ](loops=2, use_repetition_ids=True) ]───────────────────────────────────── +0: ───[ ║ [ b: ════════════@═══ ](loops=2, use_repetition_ids=True) ]───────────────────────────────────── [ ║ ║ ] - [ b: ═══@═══╩═══════════════════════════════════════════════════════════ ](loops=2, use_repetition_ids=True) + [ b: ═══V═══╩═══════════════════════════════════════════════════════════ ](loops=2, use_repetition_ids=True) """, use_unicode_characters=True, ) @@ -675,9 +675,9 @@ def test_scope_extern(): """ 0: ─────M───M('0:0:a')───X───M('0:1:a')───X───M───M('1:0:a')───X───M('1:1:a')───X─── ║ ║ ║ ║ ║ ║ -0:b: ═══@════════════════^════════════════^═══╬════════════════╬════════════════╬═══ +0:b: ═══V════════════════@════════════════@═══╬════════════════╬════════════════╬═══ ║ ║ ║ -1:b: ═════════════════════════════════════════@════════════════^════════════════^═══ +1:b: ═════════════════════════════════════════V════════════════@════════════════@═══ """, use_unicode_characters=True, ) @@ -712,9 +712,9 @@ def wrap_frozen(*ops): """ 0: ─────M───M('0:0:a')───X───M('0:1:a')───X───M───M('1:0:a')───X───M('1:1:a')───X─── ║ ║ ║ ║ ║ ║ -0:b: ═══@════════════════^════════════════^═══╬════════════════╬════════════════╬═══ +0:b: ═══V════════════════@════════════════@═══╬════════════════╬════════════════╬═══ ║ ║ ║ -1:b: ═════════════════════════════════════════@════════════════^════════════════^═══ +1:b: ═════════════════════════════════════════V════════════════@════════════════@═══ """, use_unicode_characters=True, ) @@ -741,7 +741,7 @@ def test_scope_root(): """ [ [ 0: ───M('a')───X─── ] ] [ 0: ───M('c')───[ ║ ]──────────── ] -0: ───[ [ b: ════════════^═══ ](loops=2) ]──────────── +0: ───[ [ b: ════════════@═══ ](loops=2) ]──────────── [ ║ ] [ b: ════════════╩══════════════════════════════════ ](loops=2) ║ @@ -754,7 +754,7 @@ def test_scope_root(): """ 0: ───M('c')───M('a')───X───M('a')───X───M('c')───M('a')───X───M('a')───X─── ║ ║ ║ ║ -b: ═════════════════════^════════════^═════════════════════^════════════^═══ +b: ═════════════════════@════════════@═════════════════════@════════════@═══ """, use_unicode_characters=True, ) @@ -784,7 +784,7 @@ def test_scope_extern_mismatch(): """ [ [ 0: ───M('a')───X─── ] ] [ 0: ───M('0:b')───[ ║ ]───────────────────────────────────── ] -0: ───[ [ b: ════════════^═══ ](loops=2, use_repetition_ids=True) ]───────────────────────────────────── +0: ───[ [ b: ════════════@═══ ](loops=2, use_repetition_ids=True) ]───────────────────────────────────── [ ║ ] [ b: ══════════════╩═══════════════════════════════════════════════════════════ ](loops=2, use_repetition_ids=True) ║ @@ -798,7 +798,7 @@ def test_scope_extern_mismatch(): """ 0: ───M('0:0:b')───M('0:0:a')───X───M('0:1:a')───X───M('1:0:b')───M('1:0:a')───X───M('1:1:a')───X─── ║ ║ ║ ║ -b: ═════════════════════════════^════════════════^═════════════════════════════^════════════════^═══ +b: ═════════════════════════════@════════════════@═════════════════════════════@════════════════@═══ """, use_unicode_characters=True, ) @@ -865,7 +865,7 @@ def test_layered_circuit_operations_with_controls_in_between(): """ 0: ───X───Y─── ║ ║ -m: ═══^═══^═══ +m: ═══@═══@═══ """, use_unicode_characters=True, ) @@ -961,15 +961,15 @@ def test_sympy_scope(): """ [ [ 0: ───M───X(conditions=[c | d, a & b])─── ] ] [ [ ║ ║ ] ] - [ [ a: ═══@═══^══════════════════════════════ ] ] + [ [ a: ═══V═══@══════════════════════════════ ] ] [ [ ║ ] ] - [ 0: ───M───M('0:c')───[ b: ═══════^══════════════════════════════ ]──────────── ] + [ 0: ───M───M('0:c')───[ b: ═══════@══════════════════════════════ ]──────────── ] [ ║ [ ║ ] ] - [ ║ [ c: ═══════^══════════════════════════════ ] ] + [ ║ [ c: ═══════@══════════════════════════════ ] ] 0: ───[ ║ [ ║ ] ]──────────── - [ ║ [ d: ═══════^══════════════════════════════ ](loops=2) ] + [ ║ [ d: ═══════@══════════════════════════════ ](loops=2) ] [ ║ ║ ] - [ b: ═══@══════════════╬════════════════════════════════════════════════════════ ] + [ b: ═══V══════════════╬════════════════════════════════════════════════════════ ] [ ║ ] [ c: ══════════════════╬════════════════════════════════════════════════════════ ] [ ║ ] @@ -988,13 +988,13 @@ def test_sympy_scope(): """ 0: ───M───M('0:c')───M───X(conditions=[c | d, a & b])───M───X(conditions=[c | d, a & b])───M───M('0:c')───M───X(conditions=[c | d, a & b])───M───X(conditions=[c | d, a & b])─── ║ ║ ║ ║ ║ ║ ║ ║ ║ ║ -a: ═══╬══════════════@═══^══════════════════════════════@═══^══════════════════════════════╬══════════════@═══^══════════════════════════════@═══^══════════════════════════════ +a: ═══╬══════════════V═══@══════════════════════════════V═══@══════════════════════════════╬══════════════V═══@══════════════════════════════V═══@══════════════════════════════ ║ ║ ║ ║ ║ ║ -b: ═══@══════════════════^══════════════════════════════════^══════════════════════════════@══════════════════^══════════════════════════════════^══════════════════════════════ +b: ═══V══════════════════@══════════════════════════════════@══════════════════════════════V══════════════════@══════════════════════════════════@══════════════════════════════ ║ ║ ║ ║ -c: ══════════════════════^══════════════════════════════════^═════════════════════════════════════════════════^══════════════════════════════════^══════════════════════════════ +c: ══════════════════════@══════════════════════════════════@═════════════════════════════════════════════════@══════════════════════════════════@══════════════════════════════ ║ ║ ║ ║ -d: ══════════════════════^══════════════════════════════════^═════════════════════════════════════════════════^══════════════════════════════════^══════════════════════════════ +d: ══════════════════════@══════════════════════════════════@═════════════════════════════════════════════════@══════════════════════════════════@══════════════════════════════ """, use_unicode_characters=True, ) @@ -1080,7 +1080,7 @@ def test_diagram_exponents(): ║ 1: ───╫───X^0.5─── ║ ║ -m: ═══@═══^═══════ +m: ═══V═══@═══════ """, ) @@ -1099,7 +1099,7 @@ def test_diagram_exponents_cx(): ║ ║ 2: ───╫───@─────── ║ ║ -m: ═══@═══^═══════ +m: ═══V═══@═══════ """, ) @@ -1121,9 +1121,9 @@ def test_diagram_exponents_multiple_keys(): ║║ 2: ─────╫╫────X^0.5─── ║║ ║ -m0: ════@╬════^═══════ +m0: ════V╬════@═══════ ║ ║ -m1: ═════@════^═══════ +m1: ═════V════@═══════ └──┘ """, ) @@ -1151,7 +1151,7 @@ def test_sympy_indexed_condition_circuit(): ║ 3: ───╫───X(conditions=[a[1] ^ a[2]])───M('b')─── ║ ║ -a: ═══@═══^══════════════════════════════════════ +a: ═══V═══@══════════════════════════════════════ """, ) result = sim.sample(circuit) diff --git a/cirq-core/cirq/ops/measurement_gate.py b/cirq-core/cirq/ops/measurement_gate.py index fba2e26146e..0251cfe948f 100644 --- a/cirq-core/cirq/ops/measurement_gate.py +++ b/cirq-core/cirq/ops/measurement_gate.py @@ -220,7 +220,7 @@ def _circuit_diagram_info_( if self.key not in label_map: symbols[0] += f"('{self.key}')" if self.key in label_map: - symbols += '@' + symbols += 'V' return protocols.CircuitDiagramInfo(symbols) diff --git a/cirq-core/cirq/ops/pauli_measurement_gate.py b/cirq-core/cirq/ops/pauli_measurement_gate.py index 8c796f8db33..6d1591a1f9f 100644 --- a/cirq-core/cirq/ops/pauli_measurement_gate.py +++ b/cirq-core/cirq/ops/pauli_measurement_gate.py @@ -172,7 +172,7 @@ def _circuit_diagram_info_( if self.key not in label_map: symbols[0] += f"('{self.key}')" if self.key in label_map: - symbols += '@' + symbols += 'V' return protocols.CircuitDiagramInfo(tuple(symbols)) 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 0cb33742e57..dfee2ced30c 100644 --- a/cirq-core/cirq/transformers/merge_k_qubit_gates_test.py +++ b/cirq-core/cirq/transformers/merge_k_qubit_gates_test.py @@ -128,7 +128,7 @@ def test_merge_complex_circuit_preserving_moment_structure(): │ │ ║ 2: ───H───X───────────────────────────X───────────────Z───────────M───╫─── ║ ║ -a: ═══════════════════════════════════════════════════════════════@═══^═══ +a: ═══════════════════════════════════════════════════════════════V═══@═══ ''', ) component_id = 0 @@ -155,7 +155,7 @@ def rewriter_merge_to_circuit_op(op: 'cirq.CircuitOperation') -> 'cirq.OP_TREE': │ │ ║ 2: ───#2──────────────────────────────────────────────────────────────────X───────────[ 2: ───Z─── ][3]───M───────────────────────╫─── ║ ║ -a: ═══════════════════════════════════════════════════════════════════════════════════════════════════════@═══════════════════════^═══''', +a: ═══════════════════════════════════════════════════════════════════════════════════════════════════════V═══════════════════════@═══''', ) component_id = 0 @@ -185,7 +185,7 @@ def rewriter_replace_with_decomp(op: 'cirq.CircuitOperation') -> 'cirq.OP_TREE': │ │ ║ 2: ───T[1]───iSwap^0.5───T[1]─────────────────────────────X───────────T[3]────────M─────────────────────────╫─── ║ ║ -a: ═══════════════════════════════════════════════════════════════════════════════@═════════════════════════^═══''', +a: ═══════════════════════════════════════════════════════════════════════════════V═════════════════════════@═══''', ) 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 7becfba26ff..63c3e60b6b0 100644 --- a/cirq-core/cirq/transformers/merge_single_qubit_gates_test.py +++ b/cirq-core/cirq/transformers/merge_single_qubit_gates_test.py @@ -159,7 +159,7 @@ def test_merge_single_qubit_moments_to_phxz(): ║ ║ 2: ───────T───────Y───────T───────Z──────────────────╫───╫─────── ║ ║ -a: ══════════════════════════════════════════════════@═══^═══════ +a: ══════════════════════════════════════════════════V═══@═══════ ''', ) context = cirq.TransformerContext(tags_to_ignore=("nocompile",)) @@ -173,7 +173,7 @@ def test_merge_single_qubit_moments_to_phxz(): ║ ║ 2: ───PhXZ(a=0.25,x=0,z=0.25)────Y───PhXZ(a=0.25,x=0,z=0.25)────Z──────────────────╫───╫─────── ║ ║ -a: ════════════════════════════════════════════════════════════════════════════════@═══^═══════ +a: ════════════════════════════════════════════════════════════════════════════════V═══@═══════ ''', ) 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 4dd840a7ece..b0179354655 100644 --- a/cirq-core/cirq/transformers/optimize_for_target_gateset_test.py +++ b/cirq-core/cirq/transformers/optimize_for_target_gateset_test.py @@ -58,7 +58,7 @@ def test_decompose_operations_to_target_gateset_default(): │ │ ║ │ 1: ───────×───────×───────────╫───X───T───×───T─── ║ ║ -m: ═══════════════════════════@═══^═══════════════''', +m: ═══════════════════════════V═══@═══════════════''', ) context = cirq.TransformerContext(tags_to_ignore=("ignore",)) c_new = _decompose_operations_to_target_gateset(c_orig, context=context) @@ -69,7 +69,7 @@ def test_decompose_operations_to_target_gateset_default(): │ │ │ │ ║ │ │ │ 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: ══════════════════════════════════════════════════════════════════════@═══^══════════════════════════════════════════════════════════ +m: ══════════════════════════════════════════════════════════════════════V═══@══════════════════════════════════════════════════════════ ''', ) @@ -104,7 +104,7 @@ def test_decompose_operations_to_target_gateset(): │ │ │ │ ║ │ │ │ 1: ───────X───@───X───────×───────────╫───X───H───X───@───X───H─── ║ ║ -m: ═══════════════════════════════════@═══^═══════════════════════''', +m: ═══════════════════════════════════V═══@═══════════════════════''', ) with pytest.raises(ValueError, match="Unable to convert"): @@ -168,7 +168,7 @@ def test_optimize_for_target_gateset(): │ │ ║ ║ │ 3: ───#4────X───────────╫───@───#4─────── ║ ║ -m: ═════════════════════@═══^════════════ +m: ═════════════════════V═══@════════════ ''', ) gateset = MatrixGateTargetGateset() @@ -186,7 +186,7 @@ def test_optimize_for_target_gateset(): │ │ │ │ ║ ║ │ │ │ │ 3: ────────────────────────M[2]───M[2]────────M[2]────X───────────╫───@────────M[2]────M[2]───M[2]────M[2]────────────────────── ║ ║ -m: ═══════════════════════════════════════════════════════════════@═══^═════════════════════════════════════════════════════════ +m: ═══════════════════════════════════════════════════════════════V═══@═════════════════════════════════════════════════════════ └────────┘ └────────┘ └────────┘ ''', ) diff --git a/cirq-core/cirq/transformers/stratify_test.py b/cirq-core/cirq/transformers/stratify_test.py index 88976eb39fd..a5c08fef549 100644 --- a/cirq-core/cirq/transformers/stratify_test.py +++ b/cirq-core/cirq/transformers/stratify_test.py @@ -288,7 +288,7 @@ def test_does_not_move_ccos_behind_measurement(): ║ ║ 2: ───╫───╫───X─── ║ ║ -m: ═══@═══^═══════ +m: ═══V═══@═══════ ''', ) c_out = cirq.stratified_circuit( @@ -304,7 +304,7 @@ def test_does_not_move_ccos_behind_measurement(): ║ ║ 2: ────╫X────╫─────── ║ ║ -m: ════@═════^═══════ +m: ════V═════@═══════ └──┘ ''', ) 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 7d7a16c95e0..df48f1ab88b 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 @@ -184,7 +184,7 @@ def test_two_qubit_compilation_merge_and_replace_inefficient_component(): │ │ │ │ │ ║ 1: ───────X───────@───────────────Z───────X───X───Z───────X───╫───X─── ║ ║ -m: ═══════════════════════════════════════════════════════════@═══^═══ +m: ═══════════════════════════════════════════════════════════V═══@═══ ''', ) c_new = cirq.optimize_for_target_gateset( @@ -199,7 +199,7 @@ def test_two_qubit_compilation_merge_and_replace_inefficient_component(): │ │ │ │ ║ 1: ───────X───────@───────────────X───X───Y───X───Z───╫───X─── ║ ║ -m: ═══════════════════════════════════════════════════@═══^═══ +m: ═══════════════════════════════════════════════════V═══@═══ ''', ) diff --git a/examples/quantum_teleportation.py b/examples/quantum_teleportation.py index b974f51c549..878d003e57b 100644 --- a/examples/quantum_teleportation.py +++ b/examples/quantum_teleportation.py @@ -27,9 +27,9 @@ │ ║ ║ 2: ─────────────────X─────────────╫────╫X────Z─── ║ ║║ ║ -alice: ═══════════════════════════@════╬^════╬═══ +alice: ═══════════════════════════V════╬@════╬═══ ║ ║ -msg: ══════════════════════════════════@═════^═══ +msg: ══════════════════════════════════V═════@═══ └──┘ Bloch Sphere of Message After Random X and Y Gates: From 010a770b491850054467da2dfef77acb4a4f26d6 Mon Sep 17 00:00:00 2001 From: daxfo Date: Mon, 7 Apr 2025 11:49:03 -0700 Subject: [PATCH 2/5] Fix svg for classical controls --- cirq-core/cirq/contrib/svg/svg.py | 38 +++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/cirq-core/cirq/contrib/svg/svg.py b/cirq-core/cirq/contrib/svg/svg.py index e2afc2d027c..d0ef4110cf7 100644 --- a/cirq-core/cirq/contrib/svg/svg.py +++ b/cirq-core/cirq/contrib/svg/svg.py @@ -183,13 +183,31 @@ def tdd_to_svg( t = ( f'' + ''' + + + + + + + + + + ''' ) # Developers: uncomment below to draw green lines to debug # col_starts and row_starts # t += _debug_spacing(col_starts, row_starts) - for yi, xi1, xi2, _, _ in tdd.horizontal_lines: + for yi, xi1, xi2, _, doubled in tdd.horizontal_lines: xi1 = cast(int, xi1) xi2 = cast(int, xi2) x1 = col_starts[xi1] + col_widths[xi1] / 2 @@ -203,9 +221,14 @@ def tdd_to_svg( stroke = QBLUE else: stroke = 'black' # pragma: no cover - t += f'' + t += ( + f'' + ) - for xi, yi1, yi2, _, _ in tdd.vertical_lines: + for xi, yi1, yi2, _, doubled in tdd.vertical_lines: + arrow = doubled and tdd.entries[xi, yi2].text == 'V' yi1 = yi_map[yi1] yi2 = yi_map[yi2] y1 = row_starts[yi1] + row_heights[yi1] / 2 @@ -213,7 +236,12 @@ def tdd_to_svg( xi = cast(int, xi) x = col_starts[xi] + col_widths[xi] / 2 - t += f'' + t += ( + f'' + ) for (xi, yi), v in tdd.entries.items(): yi = yi_map[yi] @@ -238,7 +266,7 @@ def tdd_to_svg( if v.text == '×': t += _text(x, y + 3, '×', fontsize=40) continue - if v.text == '': + if v.text == '' or v.text == 'V': continue v_text = fixup_text(v.text) From decb88f6fe0b2cf242c317c2b0c3cbe9e7af4a2d Mon Sep 17 00:00:00 2001 From: daxfo Date: Mon, 7 Apr 2025 11:55:56 -0700 Subject: [PATCH 3/5] Fix svg for classical controls --- cirq-core/cirq/contrib/svg/svg.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cirq-core/cirq/contrib/svg/svg.py b/cirq-core/cirq/contrib/svg/svg.py index d0ef4110cf7..42ceb51f734 100644 --- a/cirq-core/cirq/contrib/svg/svg.py +++ b/cirq-core/cirq/contrib/svg/svg.py @@ -223,7 +223,7 @@ def tdd_to_svg( stroke = 'black' # pragma: no cover t += ( f'' ) @@ -238,8 +238,8 @@ def tdd_to_svg( x = col_starts[xi] + col_widths[xi] / 2 t += ( f'' ) From 6824b8f4047cd7f22d7f7179087541f67cd149ce Mon Sep 17 00:00:00 2001 From: daxfo Date: Mon, 7 Apr 2025 12:02:58 -0700 Subject: [PATCH 4/5] Fix svg for classical controls --- cirq-core/cirq/contrib/svg/svg.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/cirq-core/cirq/contrib/svg/svg.py b/cirq-core/cirq/contrib/svg/svg.py index 42ceb51f734..8e062c11d96 100644 --- a/cirq-core/cirq/contrib/svg/svg.py +++ b/cirq-core/cirq/contrib/svg/svg.py @@ -221,14 +221,13 @@ def tdd_to_svg( stroke = QBLUE else: stroke = 'black' # pragma: no cover - t += ( - f'' - ) + t += f'' - ) + t += f' Date: Mon, 7 Apr 2025 12:22:28 -0700 Subject: [PATCH 5/5] coverage --- cirq-core/cirq/contrib/svg/svg_test.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cirq-core/cirq/contrib/svg/svg_test.py b/cirq-core/cirq/contrib/svg/svg_test.py index 301db010cea..5f14e9dabc3 100644 --- a/cirq-core/cirq/contrib/svg/svg_test.py +++ b/cirq-core/cirq/contrib/svg/svg_test.py @@ -18,12 +18,14 @@ def test_svg(): cirq.PhasedXPowGate(exponent=0.123, phase_exponent=0.456).on(c), cirq.Z(a), cirq.measure(a, b, c, key='z'), - cirq.MatrixGate(np.eye(2)).on(a), + cirq.MatrixGate(np.eye(2)).on(a).with_classical_controls('z'), ) ) assert '?' in svg_text assert '' in svg_text + assert 'double' in svg_text + assert 'arrow' in svg_text def test_svg_noise():