-
Notifications
You must be signed in to change notification settings - Fork 603
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 parameter batch support to the AmplitudeEmbedding template #1761
Conversation
This modifies the AmplitudeEmbedding template to support a batch of parameters for the 'features' input. The pre-processing on the inputs is then applied for each feature_set in the batch.
@josh146 An existing test, The other thing I was considering is that since the template is not aware of whether the @qml.beta.qnode(dev)
def circuit(data, weights):
qml.templates.AmplitudeEmbedding([[1,1,1,1], [2,2,2,2]], wires=[0, 1]) |
Changes `test_throws_exception_if_features_wrong_shape` to only throw an error if the # of dimensions of the features tensor is >2, instead of the previous >1. This allows batched parameters to be passed.
Thanks @dime10!
Yes, this is a very good catch. I ran into the same issue recently updating the For now, I suggest removing this validation (and the corresponding
Yes, this one deserves more thought. No need to worry about it now for this PR, but something we should consider and fix in a subsequent PR 🙂 We are currently working on rethinking the @qml.beta.qnode(dev)
def circuit(data, weights):
qml.templates.AmplitudeEmbedding([[1,1,1,1], [2,2,2,2]], wires=[0, 1], batch_axes=0) In the meantime @dime10, let me know if you have any more questions, or otherwise, if the code is ready to be reviewed! |
Codecov Report
@@ Coverage Diff @@
## master #1761 +/- ##
=======================================
Coverage 98.90% 98.90%
=======================================
Files 206 206
Lines 15385 15388 +3
=======================================
+ Hits 15216 15219 +3
Misses 169 169
Continue to review full report at Codecov.
|
The `test_throws_exception_if_features_wrong_shape` is no longer applicable with batching, since it verifies that the template does not accept feature tensors with more than one dimension.
…to more_batch_templates
@josh146 This is ready for review. Thank you for answering my questions! |
Thanks @dime10! I will have a review out before the end of the day 🙂 |
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.
Great work @dime10, very nice as well to see that you have kept in the length normalization! I liked your solution re: iterating over the batch dimension - I suppose this works since we are under the assumption that there is only one batch dimension present.
I think this is good to go on my end, just two final changes needed:
- From my reading, I think the test
test_throws_exception_if_features_wrong_shape
can be 'undeleted'. - Don't forget to add your name, and a brief description of the change here, to the changelog! The changelog is in
doc/changelog-dev.md
.
Co-authored-by: Josh Izaac <josh146@gmail.com>
This reverts commit 3fdb175.
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.
@dime10 this looks great, happy to approve and merge it in!
Just before I do, don't forget to add a link to this PR in the changelog (it can be added to this existing entry
pennylane/doc/releases/changelog-dev.md
Line 19 in 1bca151
[(#1710)](https://github.com/PennyLaneAI/pennylane/pull/1710) |
Context: In PR #1710, support for creating PennyLane QNodes with batches of input parameters via
@qml.batch_params
was added. However, not all templates have support for this feature yet.Description of the Change:
for the 'features' input. The pre-processing on the inputs is then applied for each
feature_set in the batch.
test_batch_params.py file. Also removes a test in test_amplitude.py that is no longer
applicable.
Benefits: It's possible to use batched parameters on the AmplitudeEmbedding template.
Possible Drawbacks: Less robust input checks.
Related GitHub Issues: Closes #1745