Skip to content

allow using AbstractArray for AOT compilation and specs#2953

Open
albi3ro wants to merge 8 commits into
mainfrom
abstract-array-inputs
Open

allow using AbstractArray for AOT compilation and specs#2953
albi3ro wants to merge 8 commits into
mainfrom
abstract-array-inputs

Conversation

@albi3ro

@albi3ro albi3ro commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Context:

I was messing around with AbstractArray, AbstractWires and resource estimation. I'd like to be able to use AbstractArray and AbstractWires to trigger pass-by-pass specs. I'd also like to use them to trigger AOT compilation via type-hints.

Description of the Change:

Various patches to treat AbstractArray and AbstractWires like abstract types.

Benefits:

Can now do:

@qp.qjit(capture=True)
@qp.qnode(qp.device('lightning.qubit', wires=4))
def c(x : qp.typing.AbstractArray((3,), float), wires : qp.wires.Wires[4]):
    @qp.for_loop(x.shape[0])
    def loop(i):
        qp.RX(x[i], wires[i])

    @qp.for_loop(wires.shape[0])
    def loop2(i):
        qp.X(i)

    loop()
    loop2()
    return qp.expval(qp.Z(0))

print(c.mlir)
@qp.qjit(capture=True)
@qp.qnode(qp.device('lightning.qubit', wires=4))
def c(x, wires):
    @qp.for_loop(x.shape[0])
    def loop(i):
        qp.RX(x[i], wires[i])

    @qp.for_loop(wires.shape[0])
    def loop2(i):
        qp.X(i)

    loop()
    loop2()
    return qp.expval(qp.Z(0))

s = qp.specs(c, level=0)(qp.typing.AbstractArray((3,), float), qp.wires.Wires[3])

Possible Drawbacks:

Related GitHub Issues:

[sc-122582]

Comment thread doc/releases/changelog-dev.md
@dime10

dime10 commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Sounds like you might need to bump the PL dependency?

@codecov

codecov Bot commented Jun 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.94%. Comparing base (67be2b6) to head (cb31e74).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2953      +/-   ##
==========================================
- Coverage   96.94%   96.94%   -0.01%     
==========================================
  Files         165      165              
  Lines       19089    19095       +6     
  Branches     1768     1769       +1     
==========================================
+ Hits        18506    18511       +5     
- Misses        430      431       +1     
  Partials      153      153              

☔ View full report in Codecov by Harness.
📢 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.

Comment thread frontend/catalyst/jax_extras/patches.py
Comment thread frontend/test/pytest/test_jit_behaviour.py

@comp-phys-marc comp-phys-marc left a comment

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.

Thanks for your patience as I learn the ropes.

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