Skip to content
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

Add and Multiply operations for Resource objects #6567

Open
wants to merge 23 commits into
base: master
Choose a base branch
from

Conversation

willjmax
Copy link
Contributor

This PR adds add_in_series, add_in_parallel, mul_in_series, and mul_in_parallel for the Resource objects. [sc-77943].

Copy link
Contributor

Hello. You may have forgotten to update the changelog!
Please edit doc/releases/changelog-dev.md with:

  • A one-to-two sentence description of the change. You may include a small working example for new features.
  • A link back to this PR.
  • Your name (or GitHub username) in the contributors section.

Copy link

codecov bot commented Nov 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.29%. Comparing base (7da8831) to head (3d644c7).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6567      +/-   ##
==========================================
- Coverage   99.29%   99.29%   -0.01%     
==========================================
  Files         454      454              
  Lines       43270    43332      +62     
==========================================
+ Hits        42966    43027      +61     
- Misses        304      305       +1     

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

Copy link
Contributor

@Jaybsoni Jaybsoni left a comment

Choose a reason for hiding this comment

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

Looks good, just a few small comments 👍🏼. Also missing a changelog entry.

@@ -14,6 +14,9 @@
"""
Stores classes and logic to aggregate all the resource information from a quantum workflow.
"""
from __future__ import annotations
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
from __future__ import annotations

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is needed for the type hints to work. Is there a problem with this import?

pennylane/resource/resource.py Outdated Show resolved Hide resolved
pennylane/resource/resource.py Outdated Show resolved Hide resolved
tests/resource/test_resource.py Outdated Show resolved Hide resolved
@Jaybsoni
Copy link
Contributor

Actually looking at the docs, it would be nice to add examples in the doc-string for each of the functions. The information in the docstring (although sufficient) feels empty.

@Jaybsoni
Copy link
Contributor

Also you haven't updated the depth and shots arguments. For "series" resources the depth should add, while in parallel it should be the maximum of the two depth values. The shots should always add 👍🏼

Comment on lines +393 to +404
def _add_shots(s1: Shots, s2: Shots) -> Shots:
if s1.total_shots is None:
return s2

if s2.total_shots is None:
return s1

shot_vector = []
for shot in s1.shot_vector + s2.shot_vector:
shot_vector.append((shot.shots, shot.copies))

return Shots(shots=shot_vector)
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks good, I just wonder if it's ideal to have this defined here, or better in pennylane/measurements/shots.py as part of the Shots class.
Probably best to check with Soran.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was thinking the same thing, but I didn't want to add an unrelated file to the PR. I'll ask Soran.

Copy link
Contributor

Choose a reason for hiding this comment

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

The current location looks good to me. @Jaybsoni please also check.

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