From 8ebb0cecd6dc4239cbe74da6d39d091dd8c1b8e7 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Jaskula Date: Tue, 12 Dec 2023 13:06:51 +0100 Subject: [PATCH] change to printing with fixed precision --- src/braket/circuits/ascii_circuit_diagram.py | 11 +++++++---- .../braket/circuits/test_ascii_circuit_diagram.py | 10 +++++----- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/braket/circuits/ascii_circuit_diagram.py b/src/braket/circuits/ascii_circuit_diagram.py index eb9b7eaf5..660fb73e8 100644 --- a/src/braket/circuits/ascii_circuit_diagram.py +++ b/src/braket/circuits/ascii_circuit_diagram.py @@ -390,12 +390,15 @@ def _create_output( output = "" if global_phase is not None: - global_phase = ( - round(global_phase, 2) if isinstance(global_phase, float) else global_phase + global_phase_str = ( + f"{global_phase:.2f}" if isinstance(global_phase, float) else str(global_phase) ) - symbols_width = max([symbols_width, len(str(global_phase))]) + symbols_width = max([symbols_width, len(global_phase_str)]) output += "{0:{fill}{align}{width}}|\n".format( - str(global_phase), fill=" ", align="^", width=symbols_width + global_phase_str, + fill=" ", + align="^", + width=symbols_width, ) for qubit in qubits: diff --git a/test/unit_tests/braket/circuits/test_ascii_circuit_diagram.py b/test/unit_tests/braket/circuits/test_ascii_circuit_diagram.py index b258c0ee4..916bfb050 100644 --- a/test/unit_tests/braket/circuits/test_ascii_circuit_diagram.py +++ b/test/unit_tests/braket/circuits/test_ascii_circuit_diagram.py @@ -82,12 +82,12 @@ def test_one_gate_with_global_phase(target): def test_one_gate_with_zero_global_phase(): circ = Circuit().gphase(-0.15).x(target=0).gphase(0.15) expected = ( - "T : | 0 | 1 |", - "GP : |-0.15|0.0|", - " ", - "q0 : -X---------", + "T : | 0 | 1 |", + "GP : |-0.15|0.00|", + " ", + "q0 : -X----------", "", - "T : | 0 | 1 |", + "T : | 0 | 1 |", ) _assert_correct_diagram(circ, expected)