mirror of https://github.com/Qiskit/qiskit.git
Fix mpl circuit drawer with fold=-1 hanging with ControlFlow ops (#12016)
* Fix typing-extensions * Fix control flow with fold minus one
This commit is contained in:
parent
ad0b7f2f35
commit
43381ae1b1
|
@ -1544,7 +1544,7 @@ class MatplotlibDrawer:
|
|||
while end_x > 0.0:
|
||||
x_shift = fold_level * self._fold
|
||||
y_shift = fold_level * (glob_data["n_lines"] + 1)
|
||||
end_x = xpos + box_width - x_shift
|
||||
end_x = xpos + box_width - x_shift if self._fold > 0 else 0.0
|
||||
|
||||
if isinstance(node.op, IfElseOp):
|
||||
flow_text = " If"
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
---
|
||||
fixes:
|
||||
- |
|
||||
Fixed an issue with the :func:`circuit_drawer` or :meth:`QuantumCircuit.draw`
|
||||
when using the ``mpl`` output option where the program would hang if the
|
||||
circuit being drawn had a ControlFlow operation in it and the ``fold`` option
|
||||
was set to -1 (meaning no fold).
|
||||
Fixed `#12012 <https://github.com/Qiskit/qiskit/issues/12012>`__.
|
Binary file not shown.
After Width: | Height: | Size: 11 KiB |
|
@ -2228,6 +2228,27 @@ class TestCircuitMatplotlibDrawer(QiskitTestCase):
|
|||
)
|
||||
self.assertGreaterEqual(ratio, self.threshold)
|
||||
|
||||
def test_control_flow_with_fold_minus_one(self):
|
||||
"""Test control flow works with fold=-1. Qiskit issue #12012"""
|
||||
qreg = QuantumRegister(2, "qr")
|
||||
creg = ClassicalRegister(2, "cr")
|
||||
circuit = QuantumCircuit(qreg, creg)
|
||||
with circuit.if_test((creg[1], 1)):
|
||||
circuit.h(0)
|
||||
circuit.cx(0, 1)
|
||||
|
||||
fname = "control_flow_fold_minus_one.png"
|
||||
self.circuit_drawer(circuit, output="mpl", filename=fname, fold=-1)
|
||||
|
||||
ratio = VisualTestUtilities._save_diff(
|
||||
self._image_path(fname),
|
||||
self._reference_path(fname),
|
||||
fname,
|
||||
FAILURE_DIFF_DIR,
|
||||
FAILURE_PREFIX,
|
||||
)
|
||||
self.assertGreaterEqual(ratio, self.threshold)
|
||||
|
||||
def test_annotated_operation(self):
|
||||
"""Test AnnotatedOperations and other non-Instructions."""
|
||||
circuit = QuantumCircuit(3)
|
||||
|
|
Loading…
Reference in New Issue