-
Notifications
You must be signed in to change notification settings - Fork 575
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
Standardize batch transform UI #1810
Conversation
Hello. You may have forgotten to update the changelog!
|
Codecov Report
@@ Coverage Diff @@
## master #1810 +/- ##
=======================================
Coverage 98.92% 98.92%
=======================================
Files 209 209
Lines 15756 15783 +27
=======================================
+ Hits 15587 15614 +27
Misses 169 169
Continue to review full report at Codecov.
|
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.
@josh146 I've just done a quick pass and left some initial questions. Very glad to have the new feature!
@@ -414,11 +414,16 @@ def _validate_backprop_method(device, interface): | |||
if interface in backprop_devices: | |||
# TODO: need a better way of passing existing device init options | |||
# to a new device? | |||
expand_fn = device.expand_fn |
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.
Regarding the TODO above, I guess we need something like device.clone()
?
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.
This is a todo we have kinda put on the backlog, just because the need for it disappears if we simply merge all the default qubit subclasses. Which should hopefully be doable now with qml.math
!
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.
🤞 🤞
|
||
def wrapper(qnode): | ||
if isinstance(qnode, qml.Device): |
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've gotten a bit tangled here; earlier we checked if the input was a device. But here, we're in the case where the input is a QNode, and with is a wrapper that can consider an argument that is a device?
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.
This is because the @batch_transform
decorator is trying to be too clever 😬 I originally coded it up so that all of the following UIs work:
# inline syntax
qnode = qml.batch_transform(qnode, *transform_args)
tapes, fn = qml.batch_transform(tape, *transform_args)
dev = qml.batch_transform(dev, *transform_args)
# decorator syntax
qnode = qml.batch_transform(*transform_args)(qnode)
tapes, fn = qml.batch_transform(*transform_args)(tape)
dev = qml.batch_transform(*transform_args)(dev)
The first three if statements cover the inline cases, this if statement covers the decorator syntax (hence the additional nested wrapper).
The reason for this complication is that
- I wanted to preserve the inline syntax, since
qml.metric_tensor(qnode, *targs)
has worked like this for a very long time. - I also wanted to preserve the decorator syntax used by qfunc transforms and
qml.grad
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 okay, thanks for clarifying that!
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 @josh146 for the clarifications! Looks good 👍
@@ -414,11 +414,16 @@ def _validate_backprop_method(device, interface): | |||
if interface in backprop_devices: | |||
# TODO: need a better way of passing existing device init options | |||
# to a new device? | |||
expand_fn = device.expand_fn |
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.
🤞 🤞
|
||
def wrapper(qnode): | ||
if isinstance(qnode, qml.Device): |
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 okay, thanks for clarifying that!
Context: #1809 standardizes
@qfunc_transforms
to have the same consistent UI regardless of whether it is applied to qfuncs, tapes, or devices. This PR makes the equivalent change to the@batch_transform
decorator.Description of the Change:
The UI is now consistent with qfunc transforms
Batch transforms can be bound to devices
Fixes a bug found in the device class when creating a backprop device
Example:
Benefits: Makes the batch transform UI consistent with the qfunc transform UI, and fixes various UI bugs and edge cases.
Possible Drawbacks: n/a
Related GitHub Issues: n/a