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

Support autodiff and batching in kernel matrix functions #3742

Merged
merged 6 commits into from Feb 9, 2023

Conversation

dwierichs
Copy link
Contributor

Context:
There are two utility functions in pennylane/kernels/utils.py: square_kernel_matrix and kernel_matrix. They are written for Numpy, and partially for Autograd.

Description of the Change:
This PR makes the two functions fully compatible with Autograd, JAX, Tensorflow and PyTorch.
In addition it adds batching support to the functions, allowing the kernel to return a one-dimensional instead of a scalar output.

Benefits:
Differentiation/interface support. One can now make use of shot vector execution together with kernels.

Possible Drawbacks:
usual overhead of qml.math.

Related GitHub Issues:
implements #2492

@codecov
Copy link

codecov bot commented Feb 9, 2023

Codecov Report

Merging #3742 (cc28074) into master (5879039) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #3742   +/-   ##
=======================================
  Coverage   99.82%   99.82%           
=======================================
  Files         329      329           
  Lines       28848    28856    +8     
=======================================
+ Hits        28797    28805    +8     
  Misses         51       51           
Impacted Files Coverage Δ
pennylane/gradients/parameter_shift.py 100.00% <100.00%> (ø)
pennylane/kernels/utils.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Contributor

@mudit2812 mudit2812 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 some minor questions and comments, but overall, the changes are clear and well-thought out.

pennylane/kernels/utils.py Show resolved Hide resolved
pennylane/kernels/utils.py Show resolved Hide resolved
pennylane/kernels/utils.py Outdated Show resolved Hide resolved
tests/kernels/test_kernels.py Show resolved Hide resolved
@dwierichs dwierichs enabled auto-merge (squash) February 9, 2023 15:37
auto-merge was automatically disabled February 9, 2023 15:53

Merge queue setting changed

@dwierichs dwierichs added this pull request to the merge queue Feb 9, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Feb 9, 2023
@dwierichs dwierichs added this pull request to the merge queue Feb 9, 2023
@dwierichs dwierichs removed this pull request from the merge queue Feb 9, 2023
@rmoyard rmoyard enabled auto-merge (squash) February 9, 2023 19:04
@rmoyard rmoyard merged commit 0f48aa6 into master Feb 9, 2023
@rmoyard rmoyard deleted the kernels-utils-autodiff branch February 9, 2023 19:22
mudit2812 added a commit that referenced this pull request Apr 13, 2023
* everything,everywhere,all at once

* changelog

* add lintable test file

* Apply suggestions from code review

Co-authored-by: Mudit Pandey <muditpandey2812@gmail.com>

---------

Co-authored-by: Mudit Pandey <muditpandey2812@gmail.com>
Co-authored-by: Romain Moyard <rmoyard@gmail.com>
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.

Make kernel matrix functions compatible with all frameworks and JITting
3 participants