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 support for the new VQE workflows to the differentiable batch execution pipeline #1608
Conversation
[ch8557] |
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 only minor comments, this will be such a nice feature to have! 💯
|
||
a, b, c = coeffs | ||
x, y = weights | ||
tape.trainable_params = {0, 1, 2, 4} |
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.
Any reason it is not using all 3 coeffs of H?
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.
Oh... very good question 🤔 I remember doing this deliberately, but for the life of me cannot remember the reason!
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.
Oh! Sorry I misread this line. At first I thought it was ==
, but now I realize it is an assignment =
.
Basically, I want to test the case where not all Hamiltonian coefficients are trainable, just to make the test more complicated.
@@ -738,6 +738,29 @@ def trainable_params(self, param_indices): | |||
|
|||
self._trainable_params = param_indices | |||
|
|||
def get_operation(self, idx): |
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 a thought; could name this get_trainable_operation
?
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.
@anthayes92 that was my original name 😆
Oddly, I found myself getting confused while writing this, and decided it was better to mirror the existing tape.get_parameters()
method (which by default only gets trainable parameters).
Awesome addition @josh146 ! Very thorough testing |
Co-authored-by: Olivia Di Matteo <2068515+glassnotes@users.noreply.github.com>
Context: In #1483, #1596, and #1551, support was added for:
expval(H)
inside of a QNodedefault.qubit
, to support Hamiltonians directly.However, these changes were not ported over to the new differentiable batch-execute pipeline.
Description of the Change:
Add support for differentiating (one or more) Hamiltonians to
qml.gradients.param_shift
.Modify
hamiltonian_grad
to support multiple Hamiltonians (return expval(H1), expval(H2)
), as this is supported execution behaviour.Fixes a couple of bugs with the Autograd and TensorFlow batch interfaces
Adds tests
Benefits: returning
expval(H)
from QNodes is now supported within the new batch-differentiable pipeline.Possible Drawbacks: n/a
Related GitHub Issues: n/a