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

Add DeviceDerivatives jacobian product calculator #4527

Merged
merged 67 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from 61 commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
922625e
add jacobianproductcalculator base class and TransformDerivatives
albi3ro Aug 2, 2023
94f1f38
add JacobianProductCalculator and TransformDerivatives
albi3ro Aug 3, 2023
e8bb908
Merge branch 'master' into jacobian_product_class
albi3ro Aug 3, 2023
b5246a2
Update pennylane/interfaces/jacobian_products.py
albi3ro Aug 3, 2023
82fe7d6
add tests
albi3ro Aug 3, 2023
9ac16a9
Merge branch 'master' into jacobian_product_class
albi3ro Aug 3, 2023
ba8a498
Update doc/releases/changelog-dev.md
albi3ro Aug 3, 2023
9de89a4
Update pennylane/interfaces/jacobian_products.py
albi3ro Aug 3, 2023
a2ab25e
Apply suggestions from code review
albi3ro Aug 3, 2023
12f5606
experimental device jps
albi3ro Aug 4, 2023
8e663d6
add tests for differentiability and jitting
albi3ro Aug 4, 2023
5f350e1
Update pennylane/gradients/jvp.py
albi3ro Aug 8, 2023
66356ce
device derivatives and jacobian products
albi3ro Aug 9, 2023
6b67bf7
some more documentation and testing
albi3ro Aug 9, 2023
550e1df
some minor updates
albi3ro Aug 10, 2023
763652f
Update pennylane/interfaces/jacobian_products.py
albi3ro Aug 22, 2023
a531ca5
Apply suggestions from code review
albi3ro Aug 22, 2023
6c3cf0a
Merge branch 'master' into jacobian_product_class
albi3ro Aug 22, 2023
7dedb4f
update docstrings
albi3ro Aug 22, 2023
0bc9474
update name in init
albi3ro Aug 22, 2023
0289fae
logging and some comments
albi3ro Aug 24, 2023
1ee2b90
minor documentation changes
albi3ro Aug 24, 2023
4c92e0c
Apply suggestions from code review
albi3ro Aug 24, 2023
7aec029
[skip-ci] Apply suggestions from code review
albi3ro Aug 25, 2023
9cf4686
mvp for device jacobian products [skip-ci]
albi3ro Aug 25, 2023
e89693b
Merge branch 'jacobian_product_class' into jpc-devices
albi3ro Aug 25, 2023
7cdfd2e
Merge branch 'master' into jacobian_product_class
albi3ro Aug 28, 2023
079e887
Merge branch 'jacobian_product_class' into jpc-devices
albi3ro Aug 28, 2023
0df2a56
[skip ci] adding documentation and tests
albi3ro Aug 28, 2023
359199f
fix some tests and documentation
albi3ro Aug 29, 2023
c377f29
pragma no cover on log statements
albi3ro Aug 29, 2023
5c84a83
more documentation and testing
albi3ro Aug 30, 2023
dfa999c
more tests
albi3ro Aug 30, 2023
f7669f7
Merge branch 'master' into jacobian_product_class
albi3ro Aug 30, 2023
e689cb0
update
albi3ro Aug 30, 2023
4dbbe41
minor fixes
albi3ro Aug 31, 2023
c88b8c5
Merge branch 'master' into jacobian_product_class
albi3ro Sep 19, 2023
87d6494
Merge branch 'master' into jacobian_product_class
albi3ro Sep 20, 2023
e21528d
fix tests
albi3ro Sep 20, 2023
eba3024
Merge branch 'master' into jacobian_product_class
albi3ro Sep 21, 2023
65ec306
Merge branch 'jacobian_product_class' into jpc-devices
albi3ro Sep 21, 2023
2a70d79
fix for new device
albi3ro Sep 22, 2023
1275484
Merge branch 'master' into jpc-devices
albi3ro Sep 27, 2023
4bcae7f
fix broken tests
albi3ro Sep 27, 2023
e00d1ba
fix test
albi3ro Sep 27, 2023
ee15456
cover branch
albi3ro Sep 27, 2023
6cd2db0
depend on batch hash, hope fixes flaky failures
albi3ro Oct 2, 2023
b42adc5
Merge branch 'master' into jpc-devices
albi3ro Oct 2, 2023
8201f8b
Apply suggestions from code review
albi3ro Oct 4, 2023
2378e22
responding to feedback
albi3ro Oct 4, 2023
bc8b3e1
fix merge conflict
albi3ro Oct 4, 2023
6d1db14
rename to DeviceDerivatives
albi3ro Oct 4, 2023
232f6e7
test with shot vectors
albi3ro Oct 4, 2023
da79e5c
Update pennylane/interfaces/jacobian_products.py
albi3ro Oct 5, 2023
22ca172
Merge branch 'master' into jpc-devices
albi3ro Oct 5, 2023
e66a0a1
adding shot vector jvp support
albi3ro Oct 5, 2023
e967fda
Update tests/interfaces/test_jacobian_products.py
albi3ro Oct 6, 2023
57eadf6
black
albi3ro Oct 6, 2023
ada4c49
pylint silence
albi3ro Oct 13, 2023
a7a7c26
Merge branch 'master' into jpc-devices
albi3ro Oct 13, 2023
d263536
Merge branch 'master' into jpc-devices
albi3ro Oct 18, 2023
1c57024
allow only some with shot vectors
albi3ro Oct 18, 2023
f64c03e
rename to execute_and_cache_jacobian
albi3ro Oct 19, 2023
83bc4fb
Merge branch 'master' into jpc-devices
albi3ro Oct 19, 2023
3c77ec7
Update pennylane/interfaces/jacobian_products.py
albi3ro Oct 19, 2023
e6cd12f
Merge branch 'master' into jpc-devices
albi3ro Oct 19, 2023
4ffaf5f
Merge branch 'master' into jpc-devices
albi3ro Oct 19, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,10 @@
[(#4628)](https://github.com/PennyLaneAI/pennylane/pull/4628)
[(#4649)](https://github.com/PennyLaneAI/pennylane/pull/4649)

* The `JacobianProductCalculator` abstract base class and implementation `TransformJacobianProducts`
have been added to `pennylane.interfaces.jacobian_products`.
* The `JacobianProductCalculator` abstract base class and implementations `TransformJacobianProducts`
and `DeviceDerivatives` have been added to `pennylane.interfaces.jacobian_products`.
albi3ro marked this conversation as resolved.
Show resolved Hide resolved
[(#4435)](https://github.com/PennyLaneAI/pennylane/pull/4435)
[(#4527)](https://github.com/PennyLaneAI/pennylane/pull/4527)

* Extended ``qml.qchem.import_state`` to import wavefunctions from MPS DMRG and SHCI classical
calculations performed with the Block2 and Dice libraries, incorporating new tests and wavefunction
Expand Down
6 changes: 6 additions & 0 deletions pennylane/_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,9 @@ def execute_and_gradients(self, circuits, method="jacobian", **kwargs):
tuple[list[array[float]], list[array[float]]]: Tuple containing list of measured value(s)
and list of Jacobians. Returned Jacobians should be of shape ``(output_shape, num_params)``.
"""
if self.tracker.active:
albi3ro marked this conversation as resolved.
Show resolved Hide resolved
self.tracker.update(execute_and_derivative_batches=1, derivatives=len(circuits))
self.tracker.record()
gradient_method = getattr(self, method)

res = []
Expand Down Expand Up @@ -593,6 +596,9 @@ def gradients(self, circuits, method="jacobian", **kwargs):
list[array[float]]: List of Jacobians. Returned Jacobians should be of
shape ``(output_shape, num_params)``.
"""
if self.tracker.active:
self.tracker.update(derivatives=len(circuits))
self.tracker.record()
gradient_method = getattr(self, method)
return [gradient_method(circuit, **kwargs) for circuit in circuits]

Expand Down
18 changes: 12 additions & 6 deletions pennylane/gradients/hadamard_gradient.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ def hadamard_grad(
assert_no_state_returns(tape.measurements, transform_name)
assert_no_variance(tape.measurements, transform_name)
assert_no_tape_batching(tape, transform_name)
if len(tape.measurements) > 1 and tape.shots.has_partitioned_shots:
raise NotImplementedError(
"hadamard gradient does not support multiple measurements with partitioned shots."
)

if argnum is None and not tape.trainable_params:
return _no_trainable_grad(tape)
Expand Down Expand Up @@ -323,12 +327,14 @@ def _expval_hadamard_grad(tape, argnum, aux_wire):
multi_params = len(tape.trainable_params) > 1

def processing_fn(results): # pylint: disable=too-many-branches
final_res = [
[qml.math.convert_like(2 * coeff * r, r) for r in res]
if isinstance(res, tuple)
else qml.math.convert_like(2 * coeff * res, res)
for coeff, res in zip(coeffs, results)
]
"""Post processing function for computing a hadamard gradient."""
final_res = []
for coeff, res in zip(coeffs, results):
if isinstance(res, tuple):
new_val = [qml.math.convert_like(2 * coeff * r, r) for r in res]
else:
new_val = qml.math.convert_like(2 * coeff * res, res)
final_res.append(new_val)

# Post process for probs
if measurements_probs:
Expand Down
1 change: 1 addition & 0 deletions pennylane/interfaces/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@

~interfaces.jacobian_products.JacobianProductCalculator
~interfaces.jacobian_products.TransformJacobianProducts
~interfaces.jacobian_products.DeviceDerivatives

"""
from .execution import cache_execute, execute, INTERFACE_MAP, SUPPORTED_INTERFACES
Expand Down
Loading
Loading