Skip to content

Commit

Permalink
change to printing with fixed precision
Browse files Browse the repository at this point in the history
  • Loading branch information
jcjaskula-aws committed Dec 12, 2023
1 parent 095fb68 commit 8ebb0ce
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
11 changes: 7 additions & 4 deletions src/braket/circuits/ascii_circuit_diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions test/unit_tests/braket/circuits/test_ascii_circuit_diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 8ebb0ce

Please sign in to comment.