-
Notifications
You must be signed in to change notification settings - Fork 547
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 resources()
to qml.TrotterProduct
class
#5680
base: master
Are you sure you want to change the base?
Conversation
Hello. You may have forgotten to update the changelog!
|
[sc-62523] |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #5680 +/- ##
==========================================
- Coverage 99.68% 99.67% -0.01%
==========================================
Files 415 415
Lines 38886 38610 -276
==========================================
- Hits 38762 38485 -277
- Misses 124 125 +1 ☔ View full report in Codecov by Sentry. |
num_wires = len(self.wires) | ||
num_gates = len(decomp) | ||
|
||
unique_operation_decomp = (copy.deepcopy(op) for op in decomp) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I mean by the name unique_operation_decomp
is that this is a decomposition where each operation has been deep_copied so each one is unique (seperate hash) as opposed to the previous decomp where we were using multiple copies of the same operator.
We need "unique" deep-copies in order to properly count resources. Due to some legacy code in the circuit graph module.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Co-authored-by: Utkarsh <utkarshazad98@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Jaybsoni, please note my minor comments before merging.
qml.TrotterProduct(hamiltonian, time, n=5, order=2) | ||
return qml.expval(qml.Z(0)) | ||
|
||
tracked_resources = qml.specs(circ)()["resources"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we test with qml.Tracker
too?
* `qml.TrotterProduct` is now compatible with resource tracking by inheriting from `ResourcesOperation`. | ||
[(#5680)](https://github.com/PennyLaneAI/pennylane/pull/5680) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why it is under Breaking changes? Is there a bug report for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh nice catch, let me move it to improvements
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Jaybsoni!
|
||
assert expected_resources == tracked_resources | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be curious to have a test that calculates resources and error at the same time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Jaybsoni, looks good to me! Optionally, you might want to add an integration test with qml.Tracker
too.
Context:
qml.TrotterProduct()
now has error tracking functionality, but ins't compatible with resource tracking. This bug fix adds native resource tracking functionality to allow for compatibility with both pipelines.Description of the Change:
Inherit from
ResourcesOperation
class as well and directly implement the resource method.Benefits:
Allows for tracking resources without decomposing the template.
Possible Drawbacks:
If we change the target gate-set or want to decompose further, then this method is no longer accurate.
Related GitHub Issues:
Replicating most of this PR post release.