-
Notifications
You must be signed in to change notification settings - Fork 586
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
Allows shots to be passed to transforms at runtime #1707
Conversation
if device.shots != original_shots: | ||
device.shots = original_shots |
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.
@glassnotes this is the bug affecting the notebook - !=
isn't safe enough, better to simply always revert the shots.
Codecov Report
@@ Coverage Diff @@
## master #1707 +/- ##
=======================================
Coverage 99.20% 99.20%
=======================================
Files 201 201
Lines 15127 15134 +7
=======================================
+ Hits 15007 15014 +7
Misses 120 120
Continue to review full report at Codecov.
|
if shots == device.shots: | ||
yield | ||
return |
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.
Now, if shots == device.shots
, we yield and do nothing!
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.
Ah good idea!
|
||
# the original QNode is unaffected | ||
assert circuit(x).shape == tuple() | ||
assert circuit(x, shots=1000).shape == tuple() |
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 happens if a circuit uses the shots argument? This was always a tricky case, but shall we define intended behaviour with a test?
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.
We currently raise a deprecation warning in the QNode, let me check if it also occurs here, or if one should be added manually 🤔
Line 182 in 8a14365
if "shots" in inspect.signature(func).parameters: |
@@ -161,6 +161,7 @@ def jacobian_wrapper(*args, **kwargs): | |||
if not hybrid: | |||
return qjac | |||
|
|||
kwargs.pop("shots", False) |
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 is this needed?
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.
Ah, your comment just made me think of a better way, allowing this to be removed!
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 still have a very bad feeling about this syntax, but since we have it, it makes only sense to add it to the batch transforms!
Approving, but I would strongly recommend to improve the changelog :)
Co-authored-by: Maria Schuld <mariaschuld@gmail.com>
Context: The number of shots is currently a reserved runtime argument when calling QNodes. This PR enables this for batch transforms as well.
Description of the Change:
When a batch transform is called with
shots
as keyword argument, this is intercepted and used as a runtime argument when callingqml.execute()
.In addition, a small bug was found and fixed at the same time, whereby the number of shots was not returned to the original value after execution.
Benefits: Transforms can also be dynamically called with different shot values.
Possible Drawbacks: n/a
Related GitHub Issues: n/a