Skip to content

Implement automatic qubit management #1788

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 25 commits into from
Jun 11, 2025
Merged

Conversation

paul0403
Copy link
Member

@paul0403 paul0403 commented Jun 5, 2025

Context:
We wish to support automatic qubit management, i.e. when the user does not specify the number of wires in device initialization

@qjit
def workflow():
    dev = qml.device("lightning.qubit") # no wires here!
    @qml.qnode(dev)
    def circuit():
        qml.PauliX(wires=0)
        return qml.probs(wires=[2,3])  # non qjit is [1,0,0,0]
    return circuit()

Description of the Change:
A new unit attribute, auto_qubit_management, is added to the device init op. If no wires are specified during device init in user python, we trace to device init op with this attribute turned on.

In runtime, when a new user wire index is encountered in __catalyst__rt__array_get_element_ptr_1d, if the device is in automatic management mode (as indicated by the RTDevice constructor, set from the new attribute we added), we allocate new device qubits so that this new user wire index is an available qubit.

Benefits:
The automatic qubit management feature is now supported.

Possible Drawbacks:

  1. Catalyst and Pennylane interprets wire labels differently. See Add support for qml.map_wires #1800
  2. Potential out-of-memory error might be encountered in runtime.

[sc-86500]

@paul0403 paul0403 changed the title [WIP 🚧 ] Automatic qubit management Implement automatic qubit management Jun 6, 2025
@paul0403 paul0403 requested a review from dime10 June 6, 2025 20:07
Copy link
Contributor

@dime10 dime10 left a comment

Choose a reason for hiding this comment

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

Great, some smaller suggestions for improvements:

Copy link

codecov bot commented Jun 6, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.61%. Comparing base (4a4ec28) to head (0c6e45d).
Report is 4 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1788   +/-   ##
=======================================
  Coverage   96.60%   96.61%           
=======================================
  Files          82       82           
  Lines        9233     9260   +27     
  Branches      872      875    +3     
=======================================
+ Hits         8920     8947   +27     
  Misses        254      254           
  Partials       59       59           

☔ 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

@dime10 dime10 left a comment

Choose a reason for hiding this comment

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

Excellent 💯

@paul0403 paul0403 merged commit d23b9c3 into main Jun 11, 2025
39 checks passed
@paul0403 paul0403 deleted the paul0403/automatic_qubit_management branch June 11, 2025 15:39
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.

5 participants