Skip to content

Commit

Permalink
code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
jcjaskula-aws committed Dec 27, 2023
1 parent 5a40951 commit d563c78
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
12 changes: 0 additions & 12 deletions src/braket/circuits/ascii_circuit_diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,17 +267,6 @@ def _ascii_diagram_column_set(
for i, moment_line in enumerate(column_str.split("\n")):
lines[i] += moment_line

# Adjust for column title width
col_title_width = len(col_title)
symbols_width = len(lines[0]) - 1
if symbols_width < col_title_width:
diff = col_title_width - symbols_width
for i in range(len(lines) - 1):
if lines[i].endswith("─"):
lines[i] += "─" * diff
else:
lines[i] += " "

first_line = "{:^{width}}│\n".format(col_title, width=len(lines[0]) - 1)

return first_line + "\n".join(lines)
Expand Down Expand Up @@ -384,7 +373,6 @@ def _ascii_diagram_column(
connections[qubit] = "below"
elif min(target_and_control) < qubit:
connections[qubit] = "above"
continue

elif qubit in control_qubits:
symbols[qubit] = "●" if map_control_qubit_states[qubit] else "◯"
Expand Down
38 changes: 25 additions & 13 deletions test/unit_tests/braket/circuits/test_ascii_circuit_diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,18 +229,18 @@ def test_time_width():


def test_connector_across_two_qubits():
circ = Circuit().cnot(3, 4).h(range(2, 6))
circ = Circuit().cnot(4, 3).h(range(2, 6))
expected = (
"T : │ 0 │ 1 │",
" ┌───┐ ",
"q2 : ─┤ H ├───────",
" └───┘ ",
" ┌───┐ ",
"q3 : ───●───┤ H ├─",
" └───┘ ",
" ┌─┴─┐ ┌───┐ ",
"q4 : ─┤ X ├─┤ H ├─",
" └───┘ └───┘ ",
" ┌───┐ ┌───┐ ",
"q3 : ─┤ X ├─┤ H ├─",
" └─┬─┘ └───┘ ",
" ┌───┐ ",
"q4 : ───●───┤ H ├─",
" └───┘ ",
" ┌───┐ ",
"q5 : ─┤ H ├───────",
" └───┘ ",
Expand All @@ -250,18 +250,18 @@ def test_connector_across_two_qubits():


def test_neg_control_qubits():
circ = Circuit().x(2, control=[0, 1], control_state=[0, 1])
circ = Circuit().x(1, control=[0, 2], control_state=[0, 1])
expected = (
"T : │ 0 │",
" ",
"q0 : ───◯───",
" │ ",
" │ ",
"q1 : ───●───",
" │ ",
" ┌─┴─┐ ",
"q2 : ─┤ X ├─",
" └───┘ ",
"q1 : ─┤ X ├─",
" └─┬─┘ ",
" │ ",
"q2 : ───●───",
" ",
"T : │ 0 │",
)
_assert_correct_diagram(circ, expected)
Expand Down Expand Up @@ -593,6 +593,18 @@ def to_ir(self, target):
_assert_correct_diagram(circ, expected)


def test_single_qubit_result_types_target_none():
circ = Circuit().h(0).probability()
expected = (
"T : │ 0 │ Result Types │",
" ┌───┐ ┌─────────────┐ ",
"q0 : ─┤ H ├─┤ Probability ├─",
" └───┘ └─────────────┘ ",
"T : │ 0 │ Result Types │",
)
_assert_correct_diagram(circ, expected)


def test_result_types_target_none():
circ = Circuit().h(0).h(100).probability()
expected = (
Expand Down

0 comments on commit d563c78

Please sign in to comment.