Skip to content

Commit

Permalink
add default_diagram_builder field
Browse files Browse the repository at this point in the history
  • Loading branch information
jcjaskula-aws committed Dec 27, 2023
1 parent d627658 commit a1c44fe
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/braket/circuits/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class Circuit:
"""

_ALL_QUBITS = "ALL" # Flag to indicate all qubits in _qubit_observable_mapping
default_diagram_builder = BoxDrawingCircuitDiagram

@classmethod
def register_subroutine(cls, func: SubroutineCallable) -> None:
Expand Down Expand Up @@ -1493,7 +1494,7 @@ def __repr__(self) -> str:
)

def __str__(self):
return self.diagram(BoxDrawingCircuitDiagram)
return self.diagram(self.default_diagram_builder)

def __eq__(self, other):
if isinstance(other, Circuit):
Expand Down
8 changes: 4 additions & 4 deletions test/unit_tests/braket/circuits/test_ascii_circuit_diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
from braket.pulse import Frame, Port, PulseSequence


def _assert_correct_diagram(circ, expected):
assert AsciiCircuitDiagram.build_diagram(circ) == "\n".join(expected)


def test_empty_circuit():
assert AsciiCircuitDiagram.build_diagram(Circuit()) == ""

Expand Down Expand Up @@ -787,10 +791,6 @@ def test_pulse_gate_multi_qubit_circuit():
_assert_correct_diagram(circ, expected)


def _assert_correct_diagram(circ, expected):
assert AsciiCircuitDiagram.build_diagram(circ) == "\n".join(expected)


def test_circuit_with_nested_target_list():
circ = (
Circuit()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
from braket.pulse import Frame, Port, PulseSequence


def _assert_correct_diagram(circ, expected):
assert BoxDrawingCircuitDiagram.build_diagram(circ) == "\n".join(expected)


def test_empty_circuit():
assert BoxDrawingCircuitDiagram.build_diagram(Circuit()) == ""

Expand Down Expand Up @@ -865,10 +869,6 @@ def test_pulse_gate_multi_qubit_circuit():
_assert_correct_diagram(circ, expected)


def _assert_correct_diagram(circ, expected):
assert BoxDrawingCircuitDiagram.build_diagram(circ) == "\n".join(expected)


def test_circuit_with_nested_target_list():
circ = (
Circuit()
Expand Down
7 changes: 7 additions & 0 deletions test/unit_tests/braket/circuits/test_circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import braket.ir.jaqcd as jaqcd
from braket.circuits import (
AsciiCircuitDiagram,
BoxDrawingCircuitDiagram,
Circuit,
FreeParameter,
Expand Down Expand Up @@ -183,6 +184,12 @@ def test_str(h):
assert str(h) == expected


def test_change_diagram_builder(h):
Circuit.default_diagram_builder = AsciiCircuitDiagram
expected = AsciiCircuitDiagram.build_diagram(h)
assert str(h) == expected


def test_equality():
circ_1 = Circuit().h(0).probability([0, 1])
circ_2 = Circuit().h(0).probability([0, 1])
Expand Down

0 comments on commit a1c44fe

Please sign in to comment.