Skip to content

Commit

Permalink
Restore removed tests in test_circuit_drawer
Browse files Browse the repository at this point in the history
  • Loading branch information
mtreinish committed Feb 23, 2025
1 parent 6f3861a commit b47f82c
Showing 1 changed file with 69 additions and 1 deletion.
70 changes: 69 additions & 1 deletion test/python/visualization/test_circuit_drawer.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import warnings
from unittest.mock import patch

from qiskit import QuantumCircuit, visualization
from qiskit import ClassicalRegister, QuantumCircuit, QuantumRegister, visualization
from qiskit.utils import optionals
from qiskit.visualization.circuit import styles, text
from qiskit.visualization.exceptions import VisualizationError
Expand Down Expand Up @@ -141,6 +141,74 @@ def test_latex_output_file_correct_format(self):
self.assertIn(im.format.lower(), filename.rsplit(".", maxsplit=1)[-1])
os.remove(filename)

def test_wire_order(self):
"""Test wire_order
See: https://github.com/Qiskit/qiskit-terra/pull/9893"""
qr = QuantumRegister(4, "q")
cr = ClassicalRegister(4, "c")
cr2 = ClassicalRegister(2, "ca")
circuit = QuantumCircuit(qr, cr, cr2)
circuit.h(0)
circuit.h(3)
circuit.x(1)
with circuit.if_test((cr, 10)):
circuit.x(3)

expected = "\n".join(
[
" ",
" q_2: ────────────────────────────",
" ┌───┐┌────── ┌───┐ ───────┐ ",
" q_3: ┤ H ├┤ If-0 ┤ X ├ End-0 ├─",
" ├───┤└──╥─── └───┘ ───────┘ ",
" q_0: ┤ H ├───╫───────────────────",
" ├───┤ ║ ",
" q_1: ┤ X ├───╫───────────────────",
" └───┘┌──╨──┐ ",
" c: 4/═════╡ 0xa ╞════════════════",
" └─────┘ ",
"ca: 2/════════════════════════════",
" ",
]
)
result = visualization.circuit_drawer(circuit, output="text", wire_order=[2, 3, 0, 1])
self.assertEqual(result.__str__(), expected)

def test_wire_order_cregbundle(self):
"""Test wire_order with cregbundle=True
See: https://github.com/Qiskit/qiskit-terra/pull/9893"""
qr = QuantumRegister(4, "q")
cr = ClassicalRegister(4, "c")
cr2 = ClassicalRegister(2, "ca")
circuit = QuantumCircuit(qr, cr, cr2)
circuit.h(0)
circuit.h(3)
circuit.x(1)
with circuit.if_test((cr, 10)):
circuit.x(3)

expected = "\n".join(
[
" ",
" q_2: ────────────────────────────",
" ┌───┐┌────── ┌───┐ ───────┐ ",
" q_3: ┤ H ├┤ If-0 ┤ X ├ End-0 ├─",
" ├───┤└──╥─── └───┘ ───────┘ ",
" q_0: ┤ H ├───╫───────────────────",
" ├───┤ ║ ",
" q_1: ┤ X ├───╫───────────────────",
" └───┘┌──╨──┐ ",
" c: 4/═════╡ 0xa ╞════════════════",
" └─────┘ ",
"ca: 2/════════════════════════════",
" ",
]
)
result = visualization.circuit_drawer(
circuit, output="text", wire_order=[2, 3, 0, 1], cregbundle=True
)
self.assertEqual(result.__str__(), expected)

def test_wire_order_raises(self):
"""Verify we raise if using wire order incorrectly."""

Expand Down

0 comments on commit b47f82c

Please sign in to comment.