Skip to content

Commit

Permalink
(non)Differentiable CV parameter-shift gradient transform (#1486)
Browse files Browse the repository at this point in the history
* more

* more

* more

* more

* more

* add tests

* more tests

* more tests

* changelog

* add todo

* fix

* fix

* fix

* Apply suggestions from code review

Co-authored-by: Olivia Di Matteo <2068515+glassnotes@users.noreply.github.com>

* add parameter-shift

* add parameter-shift

* changes

* fixes

* fixes

* suggested changes

* linting

* add tests

* add tests

* bug

* remove stack

* Apply suggestions from code review

Co-authored-by: Maria Schuld <mariaschuld@gmail.com>

* Update pennylane/gradients/finite_difference.py

* more

* suggested changes

* suggested changes

* typo

* Apply suggestions from code review

Co-authored-by: antalszava <antalszava@gmail.com>

* suggested changes

* Update pennylane/gradients/parameter_shift.py

Co-authored-by: antalszava <antalszava@gmail.com>

* suggested changes

* Apply suggestions from code review

Co-authored-by: Olivia Di Matteo <2068515+glassnotes@users.noreply.github.com>

* Update pennylane/gradients/parameter_shift.py

Co-authored-by: Olivia Di Matteo <2068515+glassnotes@users.noreply.github.com>

* suggested changes

* suggested changes

* suggested changes

* suggested changes

* suggested changes

* suggested changes

* suggested changes

* suggested changes

* Apply suggestions from code review

Co-authored-by: Maria Schuld <mariaschuld@gmail.com>

* added multiplier test

* Suggested changes

* suggested changes

* suggested changes

* typo

* more

* Apply suggestions from code review

Co-authored-by: Olivia Di Matteo <2068515+glassnotes@users.noreply.github.com>

* first commit

* first commit

* first commit

* more optimization

* more optimization

* more optimization

* tidying

* more

* fix

* fix

* suggested changes

* new post

* black

* tests

* Apply suggestions from code review

Co-authored-by: antalszava <antalszava@gmail.com>

* suggested changes

* suggested changes

* Apply suggestions from code review

Co-authored-by: Olivia Di Matteo <2068515+glassnotes@users.noreply.github.com>

* suggested changes

* Apply suggestions from code review

Co-authored-by: Olivia Di Matteo <2068515+glassnotes@users.noreply.github.com>

Co-authored-by: Olivia Di Matteo <2068515+glassnotes@users.noreply.github.com>
Co-authored-by: antalszava <antalszava@gmail.com>
Co-authored-by: Maria Schuld <mariaschuld@gmail.com>
  • Loading branch information
4 people authored Aug 5, 2021
1 parent d9383f6 commit c0cdff2
Show file tree
Hide file tree
Showing 8 changed files with 1,809 additions and 22 deletions.
4 changes: 4 additions & 0 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,14 @@
* A new gradients module `qml.gradients` has been added, which provides
differentiable quantum gradient transforms.
[(#1476)](https://github.com/PennyLaneAI/pennylane/pull/1476)
[(#1479)](https://github.com/PennyLaneAI/pennylane/pull/1479)
[(#1486)](https://github.com/PennyLaneAI/pennylane/pull/1486)

Available quantum gradient transforms include:

- `qml.gradients.finite_diff`
- `qml.gradients.param_shift`
- `qml.gradients.param_shift_cv`

For example,

Expand Down
2 changes: 2 additions & 0 deletions pennylane/gradients/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

from . import finite_difference
from . import parameter_shift
from . import parameter_shift_cv

from .finite_difference import finite_diff, finite_diff_coeffs, generate_shifted_tapes
from .parameter_shift import param_shift
from .parameter_shift_cv import param_shift_cv
4 changes: 2 additions & 2 deletions pennylane/gradients/finite_difference.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def generate_shifted_tapes(tape, idx, shifts, multipliers=None):
``idx`` shifted by consecutive values of ``shift``. The length
of the returned list of tapes will match the length of ``shifts``.
"""
params = tape.get_parameters()
params = list(tape.get_parameters())
tapes = []

for i, s in enumerate(shifts):
Expand Down Expand Up @@ -300,7 +300,7 @@ def processing_fn(results):
# In the future, we might want to change this so that only tuples
# of arrays are returned.
for i, g in enumerate(grads):
g = qml.math.convert_like(g, res[0])
g = qml.math.convert_like(g, results[0])
if hasattr(g, "dtype") and g.dtype is np.dtype("object"):
grads[i] = qml.math.hstack(g)

Expand Down
Loading

0 comments on commit c0cdff2

Please sign in to comment.