Skip to content

Improved text drawing for dynamically allocated wires#9545

Open
albi3ro wants to merge 26 commits into
mainfrom
draw-allocation-v3
Open

Improved text drawing for dynamically allocated wires#9545
albi3ro wants to merge 26 commits into
mainfrom
draw-allocation-v3

Conversation

@albi3ro
Copy link
Copy Markdown
Contributor

@albi3ro albi3ro commented May 28, 2026

Context:

Inspecting circuits with draw and allocations is really ugly and hard to read. This improves that.

Description of the Change:

Adds handling for allowing quantum wires to have limited extent. Tries to reuse horizontal lines for multiple allocations if possible.

Benefits:

Easier inspection of circuits.

Possible Drawbacks:

Related GitHub Issues:

[sc-120927]

Comment thread pennylane/decomposition/decomposition_rule.py
Comment thread pennylane/allocation.py Outdated
Comment thread pennylane/drawer/_add_obj.py
Comment thread pennylane/allocation.py Outdated
Comment thread pennylane/allocation.py Outdated
Comment thread pennylane/transforms/decomp_inspector.py Outdated
Comment thread pennylane/transforms/decomp_inspector.py Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented May 29, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.45%. Comparing base (a048c9a) to head (421d463).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #9545   +/-   ##
=======================================
  Coverage   99.45%   99.45%           
=======================================
  Files         611      611           
  Lines       67612    67701   +89     
=======================================
+ Hits        67241    67330   +89     
  Misses        371      371           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@albi3ro albi3ro requested review from JerryChen97 and removed request for comp-phys-marc June 1, 2026 15:39
Comment thread pennylane/drawer/drawable_layers.py Outdated
Comment thread pennylane/drawer/drawable_layers.py Outdated
Comment thread pennylane/drawer/drawable_layers.py Outdated
Comment thread pennylane/allocation.py Outdated
Comment thread pennylane/drawer/utils.py Outdated
Comment thread pennylane/drawer/drawable_layers.py Outdated
Comment thread pennylane/drawer/utils.py Outdated
@albi3ro albi3ro requested a review from JerryChen97 June 2, 2026 16:03
Comment thread pennylane/drawer/utils.py
Copy link
Copy Markdown
Contributor

@astralcai astralcai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! The new circuit drawings look really nice now.

Comment thread tests/drawer/test_draw.py
qp.cond(m, qp.X)(0)

out = qp.draw(f)()
# fmt: off
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wow, didn't know you could do that.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we handle other places where config.n_wires should be used in this PR or a follow-up one

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What other places?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like, _add_cond_grouping_symbols, _add_mid_measure_grouping_symbol etc.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WHY SO MANY CASES!!!!

def f():
    m = qp.measure(0)
    with qp.allocate(1) as wires:
        qp.cond(m, qp.CNOT)((0,1))

    qp.H(0)
    qp.H(0)
    with qp.allocate(1) as wires:
        qp.cond(m, qp.CZ)((0,1))

print(qp.draw(f)())

good catch./

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know which ones are in the etc? That would help tremendously.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_add_subroutine_mcm_grouping_symbols
_add_cwire_measurement_grouping_symbols
So basically searching len(config.wire_map) within this file reveals them

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants