@@ -403,6 +403,67 @@ def test_wire_order(self):
403
403
expected ,
404
404
)
405
405
406
+ < << << << HEAD
407
+ == == == =
408
+ def test_box_end_after_transpile (self ):
409
+ """Test that drawing a `box` doesn't explode."""
410
+ # The exact output is not important - feel free to change it. We only care that it doesn't
411
+ # explode when drawing.
412
+ qc = QuantumCircuit (5 )
413
+ qc = QuantumCircuit (4 )
414
+ with qc .box ():
415
+ qc .cx (0 , 1 )
416
+ qc .cx (0 , 3 )
417
+
418
+ qc_ = transpile (qc , initial_layout = [2 , 3 , 1 , 0 ])
419
+ # We don't care about trailing whitespace on a line.
420
+ actual = "\n " .join (
421
+ line .rstrip () for line in str (qc_ .draw ("text" , fold = 80 , idle_wires = True )).splitlines ()
422
+ )
423
+
424
+ expected = """\
425
+ ┌─────── ┌───┐ ───────┐
426
+ q_3 -> 0 ┤ ─────┤ X ├ ├─
427
+ │ └─┬─┘ │
428
+ q_2 -> 1 ┤ ───────┼── ├─
429
+ │ Box-0 │ End-0 │
430
+ q_0 -> 2 ┤ ──■────■── ├─
431
+ │ ┌─┴─┐ │
432
+ q_1 -> 3 ┤ ┤ X ├───── ├─
433
+ └─────── └───┘ ───────┘
434
+ """ .rstrip ()
435
+ self .assertEqual (actual , expected )
436
+
437
+ def test_basic_box (self ):
438
+ """Test that drawing a `box` doesn't explode."""
439
+ # The exact output is not important - feel free to change it. We only care that it doesn't
440
+ # explode when drawing.
441
+ qc = QuantumCircuit (5 )
442
+ with qc .box ():
443
+ qc .x (0 )
444
+ with qc .box ():
445
+ qc .cx (2 , 3 )
446
+ with qc .box ():
447
+ qc .noop (4 )
448
+ # We don't care about trailing whitespace on a line.
449
+ actual = "\n " .join (line .rstrip () for line in str (qc .draw ("text" , fold = 80 )).splitlines ())
450
+
451
+ expected = """\
452
+ ┌─────── ┌───┐ ───────┐
453
+ q_0: ┤ Box-0 ┤ X ├ End-0 ├────────────────────────────────────────────
454
+ └─────── └───┘ ───────┘
455
+ q_1: ───────────────────────────────────────────────────────────────────
456
+ ┌─────── ───────┐
457
+ q_2: ────────────────────────┤ ──■───────────────────── ├─
458
+ │ ┌─┴─┐ │
459
+ q_3: ────────────────────────┤ Box-0 ┤ X ├─────────────────── End-0 ├─
460
+ │ └───┘┌─────── ───────┐ │
461
+ q_4: ────────────────────────┤ ─────┤ Box-1 End-1 ├─ ├─
462
+ └─────── └─────── ───────┘ ───────┘
463
+ """ .rstrip ()
464
+ self .assertEqual (actual , expected )
465
+
466
+ >> >> >> > 3e96 ade54 (Fix display of Box End after transpile in text drawer (#14278))
406
467
def test_text_swap (self ):
407
468
"""Swap drawing."""
408
469
expected = "\n " .join (
0 commit comments