Skip to content

Add resource tracking to NullQubit #1619

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

Open
wants to merge 58 commits into
base: main
Choose a base branch
from
Open

Conversation

jzaia18
Copy link

@jzaia18 jzaia18 commented Apr 7, 2025

Context:
For benchmarking, we need a method of precise resource tracking. This method has to be compatible with code run directly from PennyLane and should be able to track precise resources after various transformation passes have already occurred.

See also: https://github.com/PennyLaneAI/pennylane-benchmarks/pull/76 and PennyLaneAI/pennylane#7226

Description of the Change:
Adds 2 new class attributes to NullQubit, as well as an optional argument to its constructor. When this option is toggled on, NullQubit will track precise gate counts while "executing" a circuit and save them to a file when all qubits are released.

Benefits:
It is now possible to track precise gate counts (with or without gate decomposition or other transformation passes) for measuring circuit complexity.

Possible Drawbacks:
This implementation currently write the resources JSON to a file on disk as opposed to neatly returning an object back through to the Python caller in PennyLane. In the future, a more robust solution may be desired.

Related GitHub Issues:
[sc-88213]

@jzaia18 jzaia18 requested a review from maliasadi April 7, 2025 19:32
@jzaia18 jzaia18 self-assigned this Apr 7, 2025
Copy link

codecov bot commented Apr 7, 2025

Codecov Report

Attention: Patch coverage is 94.61538% with 7 lines in your changes missing coverage. Please review.

Project coverage is 96.58%. Comparing base (1749d2b) to head (9fa1287).

Files with missing lines Patch % Lines
runtime/lib/backend/null_qubit/NullQubit.hpp 88.70% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1619      +/-   ##
==========================================
+ Coverage   96.51%   96.58%   +0.07%     
==========================================
  Files          82       82              
  Lines        9029     9158     +129     
  Branches      861      861              
==========================================
+ Hits         8714     8845     +131     
+ Misses        258      256       -2     
  Partials       57       57              

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

@jzaia18 jzaia18 marked this pull request as draft April 7, 2025 19:47
@dime10
Copy link
Contributor

dime10 commented Apr 7, 2025

Oh wow, I was just starting on this as well a couple of hours ago (just as a hack) 😆 Super useful though, thanks!

Copy link
Member

@maliasadi maliasadi left a comment

Choose a reason for hiding this comment

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

Thanks @jzaia18!

@jzaia18 jzaia18 changed the title [WIP] Add resource tracking to NullQubit Add resource tracking to NullQubit Apr 16, 2025
@jzaia18 jzaia18 marked this pull request as ready for review April 16, 2025 18:47
github-merge-queue bot pushed a commit to PennyLaneAI/pennylane that referenced this pull request May 5, 2025
**Context:** PR #7226 added a resource-tracking feature to PennyLane.
The same feature is desired in Catalyst:
PennyLaneAI/catalyst#1619

**Description of the Change:** Adds a class attribute to `null.qubit`
which allows the `resource_tracking` argument to get passed through to
Catalyst.

**Benefits:** `track_resources` can more cleanly be passed through to
Catalyst.

**Possible Drawbacks:**

**Related GitHub Issues:**
#7226
PennyLaneAI/catalyst#1619
PennyLaneAI/pennylane-benchmarks#76
[sc-88213](https://app.shortcut.com/xanaduai/story/88213)

---------

Co-authored-by: Ali Asadi <[email protected]>
austingmhuang pushed a commit to PennyLaneAI/pennylane that referenced this pull request May 6, 2025
**Context:** PR #7226 added a resource-tracking feature to PennyLane.
The same feature is desired in Catalyst:
PennyLaneAI/catalyst#1619

**Description of the Change:** Adds a class attribute to `null.qubit`
which allows the `resource_tracking` argument to get passed through to
Catalyst.

**Benefits:** `track_resources` can more cleanly be passed through to
Catalyst.

**Possible Drawbacks:**

**Related GitHub Issues:**
#7226
PennyLaneAI/catalyst#1619
PennyLaneAI/pennylane-benchmarks#76
[sc-88213](https://app.shortcut.com/xanaduai/story/88213)

---------

Co-authored-by: Ali Asadi <[email protected]>
@jzaia18 jzaia18 requested a review from dime10 May 7, 2025 15:18
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.

🎉

Copy link
Member

@maliasadi maliasadi left a comment

Choose a reason for hiding this comment

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

Nice work @jzaia18! 🥳 Just a few minor comments to resolve before merge!

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