8000 Reduce space inside BoxOps and fix layering issues with boxes by enavarro51 · Pull Request #14529 · Qiskit/qiskit · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Reduce space inside BoxOps and fix layering issues with boxes #14529

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

Merged
merged 33 commits into from
Jun 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
08a23c5
Fix typing-extensions
enavarro51 Jan 4, 2024
8d06451
Merge branch 'main' of https://github.com/Qiskit/qiskit-terra into main
enavarro51 Jan 4, 2024
f70314a
Merge branch 'main' of https://github.com/Qiskit/qiskit-terra into main
enavarro51 Jan 12, 2024
c179d5b
Merge branch 'main' of https://github.com/Qiskit/qiskit-terra into main
enavarro51 Jan 31, 2024
83972c6
Merge branch 'main' of https://github.com/Qiskit/qiskit-terra into main
enavarro51 Feb 2, 2024
e6d975c
Merge branch 'main' of https://github.com/Qiskit/qiskit-terra into main
enavarro51 Feb 6, 2024
d698cac
Merge branch 'main' of https://github.com/Qiskit/qiskit-terra into main
enavarro51 Feb 11, 2024
415504a
Merge branch 'main' of https://github.com/Qiskit/qiskit-terra into main
enavarro51 Feb 14, 2024
b0e6690
Merge branch 'main' of https://github.com/Qiskit/qiskit-terra into main
enavarro51 Feb 25, 2024
f0731e6
Merge branch 'main' of https://github.com/Qiskit/qiskit-terra into main
enavarro51 Mar 5, 2024
e5c951b
Merge branch 'main' of https://github.com/Qiskit/qiskit-terra into main
enavarro51 Mar 15, 2024
2de1ea6
Merge branch 'main' of https://github.com/Qiskit/qiskit-terra into main
enavarro51 Mar 18, 2024
e815358
Merge branch 'main' of https://github.com/Qiskit/qiskit-terra into main
enavarro51 Apr 9, 2024
8a3fff9
Merge branch 'main' of https://github.com/Qiskit/qiskit-terra into main
enavarro51 Apr 16, 2024
ddeea5a
Merge branch 'main' of https://github.com/Qiskit/qiskit-terra into main
enavarro51 Apr 16, 2024
eabb707
Merge branch 'main' of https://github.com/Qiskit/qiskit-terra into main
enavarro51 Apr 25, 2024
ee27daa
Merge branch 'main' of https://github.com/Qiskit/qiskit-terra into main
enavarro51 May 6, 2024
46085a7
Merge branch 'main' of https://github.com/Qiskit/qiskit-terra into main
enavarro51 Jun 3, 2024
4eb3b78
Merge branch 'main' of https://github.com/Qiskit/qiskit-terra into main
enavarro51 Jun 14, 2024
9abb225
Merge branch 'main' of https://github.com/Qiskit/qiskit-terra into main
enavarro51 Jun 28, 2024
c37196e
Merge branch 'main' of https://github.com/Qiskit/qiskit-terra into main
enavarro51 Jul 3, 2024
809d16a
Merge branch 'main' of https://github.com/Qiskit/qiskit-terra into main
enavarro51 Jul 3, 2024
f06bccc
Merge branch 'main' of https://github.com/Qiskit/qiskit-terra into main
enavarro51 Sep 12, 2024
5167c90
Merge branch 'main' of https://github.com/Qiskit/qiskit-terra into main
enavarro51 May 1, 2025
c990f06
Merge branch 'main' of https://github.com/Qiskit/qiskit-terra into main
enavarro51 May 2, 2025
6cc3318
Merge branch 'main' of https://github.com/Qiskit/qiskit-terra into main
enavarro51 May 30, 2025
8ed4fa8
Reduce box sizing
enavarro51 Jun 3, 2025
f050a71
Fix layering of BoxOps with other ops
enavarro51 Jun 3, 2025
694dbc1
Lint and comments
enavarro51 Jun 3, 2025
c8c708e
Merge branch 'main' into box_space
enavarro51 Jun 3, 2025
11bf0eb
Update ref image
enavarro51 Jun 3, 2025
dda2ee5
Merge branch 'box_space' of github.com:enavarro51/qiskit-terra into b…
enavarro51 Jun 3, 2025
3d49a89
Add release note
jakelishman Jun 4, 2025
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
19 changes: 17 additions & 2 deletions qiskit/visualization/circuit/matplotlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,10 @@ def lookup_var(var):
for width, layer_num, flow_parent in flow_widths.values():
if layer_num != -1 and flow_parent == flow_drawer._flow_parent:
raw_gate_width += width
# This is necessary to prevent 1 being added to the width of a
# BoxOp in layer_widths at the end of this method
if isinstance(node.op, BoxOp):
raw_gate_width -= 0.001

# Need extra incr of 1.0 for else and case boxes
gate_width += raw_gate_width + (1.0 if circ_num > 0 else 0.0)
Expand Down Expand Up @@ -747,7 +751,13 @@ def _get_coords(
# increment by if/switch width. If more cases increment by width of previous cases.
if flow_parent is not None:
node_data[node].inside_flow = True
node_data[node].x_index = node_data[flow_parent].x_index + curr_x_index + 1
# front_space provides a space for 'If', 'While', etc. which is not
# necessary for a BoxOp
front_space = 0 if isinstance(flow_parent.op, BoxOp) else 1
node_data[node].x_index = (
node_data[flow_parent].x_index + curr_x_index + front_space
)

# If an else or case
if node_data[node].circ_num > 0:
for width in node_data[flow_parent].width[: node_data[node].circ_num]:
Expand Down Expand Up @@ -1555,7 +1565,9 @@ def _flow_op_gate(self, node, node_data, glob_data):
ypos = min(y[1] for y in xy)
ypos_max = max(y[1] for y in xy)

if_width = node_data[node].width[0] + WID
# If a BoxOp, bring the right side back tight against the gates to allow for
# better spacing
if_width = node_data[node].width[0] + (WID if not isinstance(node.op, BoxOp) else -0.19)
box_width = if_width
# Add the else and case widths to the if_width
for ewidth in node_data[node].width[1:]:
Expand Down Expand Up @@ -1605,6 +1617,9 @@ def _flow_op_gate(self, node, node_data, glob_data):
expr_spacer = 0.0
empty_default_spacer = 0.3 if len(node.op.blocks[-1]) == 0 else 0.0
elif isinstance(node.op, BoxOp):
# Move the X start position back for a BoxOp, since there is no
# leading text. This tightens the BoxOp with other ops.
xpos -= 0.15
op_spacer = 0.0
expr_spacer = 0.0
empty_default_spacer = 0.0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
other:
- |
The Matplotlib circuit drawer will now insert less extraneous space inside the left edge when
drawing :class:`.BoxOp` instances in circuits.
Binary file modified test/visual/mpl/circuit/references/basic_box.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -1168,6 +1168,7 @@ def test_basic_box(self):
qc = QuantumCircuit(5)
with qc.box():
qc.x(0)
qc.x(1)
with qc.box():
qc.cx(2, 3)
with qc.box():
Expand Down
0