-
Notifications
You must be signed in to change notification settings - Fork 39
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 VJP support to PL-Lightning #181
Conversation
Codecov Report
@@ Coverage Diff @@
## master #181 +/- ##
==========================================
+ Coverage 92.97% 94.23% +1.26%
==========================================
Files 4 4
Lines 185 243 +58
==========================================
+ Hits 172 229 +57
- Misses 13 14 +1
Continue to review full report at Codecov.
|
…nto lightning-add-vjp
…lightning into lightning-add-vjp
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.
Phenomenal work @maliasadi !
I had a few small comments. Also, just wondering if we can add tests that trigger the conditions CodeFactor/CodeCov complain about?
template class Pennylane::Algorithms::VectorJacobianProduct<float>; | ||
template class Pennylane::Algorithms::VectorJacobianProduct<double>; |
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.
Do you think this should be included in the Adjoint file, or separated into its own file in the algorithms directory?
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.
it's definitely better to be added into its own file namely JacobianProd.cpp
in the same directory.
Test_StateVector_Nonparam.cpp | ||
Test_StateVector_Param.cpp | ||
Test_StateVectorManaged_Nonparam.cpp | ||
Test_StateVectorManaged_Param.cpp | ||
Test_Util.cpp | ||
Test_Bindings.cpp |
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.
Just curious about the reordering of these? If ordering doesn't matter, I think keeping alphabetical may be a good idea.
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.
Nice catch! It wasn't intentional 🙂
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 @maliasadi! This is great, I've left some comments throughout.
Correct me if I am wrong, but currently the built-in Jacobian method only supports gradients technically, since only tapes with a single, scalar, output is supported?
As we iterate the gradient support in PL and lightning, I think it makes sense to 'decouple' the VJP and Jacobian methods at some point, so that a full Jacobian is not reconstructed when the VJP is requested
|
||
vjps = dev.batch_vjp(tapes, dys, vjp_pybind=vjp_pybind) | ||
|
||
assert sum(len(t) for t in vjps) == sum(len(t.trainable_params) for t in tapes) |
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.
really nice testing!!
Thank you @mlxd! I added |
Thank you @josh146! 🙂
You're right! However, one can use |
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 job putting this together @maliasadi
As discussed, I think we can safely merge this and build upon it later for the optimal implementation.
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.
Agree with Lee, great work @maliasadi!
Context:
Implement and Integrate Vector Jacobian Product (VJP) methods in PL-Lightning along with adding tests following PL implementation here and using
pybind11
.Description of the Change:
Add
vecMatrixProd
toUtil.hpp
and classVectorJacobianProduct
toAdjointDiff.cpp
with two public methods:tensorDot
: Calculates tensor-dot of a given vector of gradient outputs and a Jacobian.vectorJacobianProduct
: Calculates the vjp for the selected set of parametric gates utilizing theAdjointJacobian
method.These methods are fully tested at
Test_VectorJacobianProduct.cpp
.Python bindings are added to
Bindings.cpp
andlightning.qubit
is now offering two methods to compute vjps:vector_jacobian_product
: Generate the the vector-Jacobian products of a tape.batch_vjp
: Generate the the vector-Jacobian products of a batch of tapes.These methods are fully tested at
test_vector_jacobian_product
.