Skip to content

Conversation

@paul0403
Copy link
Member

@paul0403 paul0403 commented Oct 2, 2025

Context:
With capture enabled, it was decided that the allocation size can only be static.

However, the current error message just falls through to whatever first error is encountered down the line. For the user this is not very actionable.

qml.capture.enable()

@qml.qnode(qml.device("default.qubit", wires=10))
def circuit(n: int):
    qml.X(0)                        # |10>

    with qml.allocate(n) as q:      # |10> and |0>, 1 dynamically allocated qubit
        qml.X(q[0])                 # |10> and |1>
        qml.CNOT(wires=[q[0], 1])   # |11> and |1>

    return qml.probs(wires=[0, 1])

print(circuit(1))
  File "/home/paul.wang/catalyst_new/catalyst/cat_env/lib/python3.11/site-packages/pennylane/workflow/_capture_qnode.py", line 481, in _extract_qfunc_jaxpr
    raise CaptureError(
pennylane.exceptions.CaptureError: Autograph must be used when Python control flow is dependent on a dynamic variable (a function input). Please ensure that autograph is being correctly enabled with `qml.capture.run_autograph` or disabled with `qml.capture.disable_autograph` or consider using PennyLane native control flow functions like `qml.for_loop`, `qml.while_loop`, or `qml.cond`.

Description of the Change:
Raise a better error message.

Benefits:
Clearer suggestion for user action.

[sc-100475]

@paul0403 paul0403 added this to the v0.43 milestone Oct 2, 2025
@codecov
Copy link

codecov bot commented Oct 2, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.42%. Comparing base (8ebe766) to head (a318891).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #8381   +/-   ##
=======================================
  Coverage   99.42%   99.42%           
=======================================
  Files         582      582           
  Lines       60902    60905    +3     
=======================================
+ Hits        60551    60554    +3     
  Misses        351      351           

☔ 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.

Copy link
Contributor

@dwierichs dwierichs left a comment

Choose a reason for hiding this comment

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

LGTM, just one optional suggestion.

@paul0403 paul0403 added this pull request to the merge queue Oct 2, 2025
Merged via the queue into master with commit b579df0 Oct 2, 2025
54 checks passed
@paul0403 paul0403 deleted the paul0403/dynalloc_static_size_capture branch October 2, 2025 20:38
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.

4 participants