Skip to content

Commit b67a3a8

Browse files
enavarro51jakelishman
authored andcommitted
Fix display of Box End after transpile in text drawer (#14278)
* Fix typing-extensions * Fix text drawer flow end display * Lint * Add reno --------- Co-authored-by: Jake Lishman <[email protected]> (cherry picked from commit 3e96ade)
1 parent 969b305 commit b67a3a8

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

qiskit/visualization/circuit/text.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1396,7 +1396,7 @@ def lookup_var(var):
13961396
layers.append(flow_layer2.full_layer)
13971397

13981398
# Draw the right box for End
1399-
flow_layer = self.draw_flow_box(node, flow_wire_map, CF_RIGHT, conditional=False)
1399+
flow_layer = self.draw_flow_box(node, wire_map, CF_RIGHT, conditional=False)
14001400
layers.append(flow_layer.full_layer)
14011401

14021402
def draw_flow_box(self, node, flow_wire_map, section, circ_num=0, conditional=False):
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
fixes:
3+
- |
4+
Fixed a visualization bug in the text circuit drawer where post-transpilation control-flow
5+
operations could have their closing "bracket" rendered vertically out of order. See
6+
`#14271 <https://github.com/Qiskit/qiskit/issues/14271>`__ for more detail.

test/python/visualization/test_circuit_text_drawer.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,35 @@ def test_wire_order(self):
397397
expected,
398398
)
399399

400+
def test_box_end_after_transpile(self):
401+
"""Test that drawing a `box` doesn't explode."""
402+
# The exact output is not important - feel free to change it. We only care that it doesn't
403+
# explode when drawing.
404+
qc = QuantumCircuit(5)
405+
qc = QuantumCircuit(4)
406+
with qc.box():
407+
qc.cx(0, 1)
408+
qc.cx(0, 3)
409+
410+
qc_ = transpile(qc, initial_layout=[2, 3, 1, 0])
411+
# We don't care about trailing whitespace on a line.
412+
actual = "\n".join(
413+
line.rstrip() for line in str(qc_.draw("text", fold=80, idle_wires=True)).splitlines()
414+
)
415+
416+
expected = """\
417+
┌─────── ┌───┐ ───────┐
418+
q_3 -> 0 ┤ ─────┤ X ├ ├─
419+
│ └─┬─┘ │
420+
q_2 -> 1 ┤ ───────┼── ├─
421+
│ Box-0 │ End-0 │
422+
q_0 -> 2 ┤ ──■────■── ├─
423+
│ ┌─┴─┐ │
424+
q_1 -> 3 ┤ ┤ X ├───── ├─
425+
└─────── └───┘ ───────┘
426+
""".rstrip()
427+
self.assertEqual(actual, expected)
428+
400429
def test_basic_box(self):
401430
"""Test that drawing a `box` doesn't explode."""
402431
# The exact output is not important - feel free to change it. We only care that it doesn't

0 commit comments

Comments
 (0)