Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the text drawer with partially idle wires #13149

Merged
merged 5 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion qiskit/dagcircuit/dagcircuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -2090,7 +2090,7 @@ def layers(self, *, vars_mode: _VarsMode = "captures"):
new_layer = self.copy_empty_like(vars_mode=vars_mode)

for node in op_nodes:
new_layer._apply_op_node_back(node, check=False)
new_layer._apply_op_node_back(copy.copy(node), check=False)

# The quantum registers that have an operation in this layer.
support_list = [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
fixes:
- |
Fixed a bug in the circuit drawers, which could fail or omit wires if ``idle_wires=False``.
Fixed `#13128 <https://github.com/Qiskit/qiskit/issues/13128>`__ and `#13146 <https://github.com/Qiskit/qiskit/issues/13146>`__.
24 changes: 24 additions & 0 deletions test/python/visualization/test_circuit_text_drawer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4092,6 +4092,30 @@ def test_does_not_mutate_circuit(self):
circuit.draw(idle_wires=False)
self.assertEqual(circuit.num_qubits, before_qubits)

def test_wires_only_initially_idle(self):
"""Test a circuit where wires are only idle in the first layer.

Regression test for https://github.com/Qiskit/qiskit/issues/13128
"""
expected = "\n".join(
[
" ┌───┐ ░ ┌───┐",
"q_0: ┤ X ├─░─┤ H ├",
" └───┘ ░ ├───┤",
"q_1: ──────░─┤ H ├",
" ░ └───┘",
]
)
qc = QuantumCircuit(2)
qc.x(0)
qc.barrier([0, 1])
qc.h(range(2))

self.assertEqual(
str(circuit_drawer(qc, output="text", idle_wires=False)),
expected,
)


class TestTextNonRational(QiskitTestCase):
"""non-rational numbers are correctly represented"""
Expand Down