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

Improve and tidy implementation of hadamard gradient #6928

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
95823e0
cleaning up hadamard gradient
albi3ro Feb 4, 2025
da2275e
more improvements?
albi3ro Feb 4, 2025
4bc4bed
some fixes
albi3ro Feb 6, 2025
68fe169
more tests more fixes
albi3ro Feb 6, 2025
c322699
Merge branch 'master' into hadamard-grad-clean
albi3ro Feb 6, 2025
ca082cd
more testing
albi3ro Feb 6, 2025
6d78732
Update doc/releases/changelog-dev.md
albi3ro Feb 6, 2025
252a88a
more testing
albi3ro Feb 6, 2025
0bc9750
Merge branch 'hadamard-grad-clean' of https://github.com/PennyLaneAI/…
albi3ro Feb 6, 2025
f239100
fix generator
albi3ro Feb 6, 2025
6c62750
more whackamole
albi3ro Feb 6, 2025
fcd8896
revert Projector pauli rep change
albi3ro Feb 7, 2025
179444e
minor fix
albi3ro Feb 7, 2025
371961d
shot vector case
albi3ro Feb 7, 2025
23edfe1
Update pennylane/gradients/hadamard_gradient.py
albi3ro Feb 7, 2025
a085872
Merge branch 'master' into hadamard-grad-clean
albi3ro Feb 7, 2025
4a2e033
allow easier extension of methods
albi3ro Feb 7, 2025
47b5e15
i swear this is the last change
albi3ro Feb 7, 2025
2527025
fixing argnums
albi3ro Feb 7, 2025
a604245
additional coverage, docs
albi3ro Feb 7, 2025
9d6bdad
Merge branch 'master' into hadamard-grad-clean
albi3ro Feb 7, 2025
81017da
Update pennylane/transforms/core/transform_dispatcher.py
albi3ro Feb 7, 2025
ba9c768
docs
isaacdevlugt Feb 7, 2025
875c7e4
docs
isaacdevlugt Feb 7, 2025
3f6ca1f
Update pennylane/gradients/hadamard_gradient.py
andrijapau Feb 7, 2025
cf719eb
Update pennylane/gradients/hadamard_gradient.py
andrijapau Feb 7, 2025
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
3 changes: 3 additions & 0 deletions doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

<h3>Improvements 🛠</h3>

* `qml.gradients.hadamard_grad` can now differentiate anything with a generator, and can accept circuits with non-commuting measurements.
albi3ro marked this conversation as resolved.
Show resolved Hide resolved
[(#6928)](https://github.com/PennyLaneAI/pennylane/pull/6928)

* Add a `qml.capture.pause()` context manager for pausing program capture in an error-safe way.
[(#6911)](https://github.com/PennyLaneAI/pennylane/pull/6911)

Expand Down
8 changes: 4 additions & 4 deletions pennylane/gradients/gradient_transform.py
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be agnostic about list-versus-tuple consistently in our gradient spec. In the case of the hadamard grad, we initially create lists because we are iterating and pushing things in to the list. As much as I prefer tuples to lists, we shouldn't have to iteratively re-construct the whole data structure just to put it back into a tuple.

Original file line number Diff line number Diff line change
Expand Up @@ -382,13 +382,13 @@ def _contract_qjac_with_cjac(qjac, cjac, tape):
num_measurements = len(tape.measurements)
has_partitioned_shots = tape.shots.has_partitioned_shots

if isinstance(qjac, tuple) and len(qjac) == 1:
if isinstance(qjac, (tuple, list)) and len(qjac) == 1:
qjac = qjac[0]

if isinstance(cjac, tuple) and len(cjac) == 1:
if isinstance(cjac, (tuple, list)) and len(cjac) == 1:
cjac = cjac[0]

cjac_is_tuple = isinstance(cjac, tuple)
cjac_is_tuple = isinstance(cjac, (tuple, list))

multi_meas = num_measurements > 1

Expand All @@ -402,7 +402,7 @@ def _contract_qjac_with_cjac(qjac, cjac, tape):
_qjac = _qjac[0]
if has_partitioned_shots:
_qjac = _qjac[0]
single_tape_param = not isinstance(_qjac, tuple)
single_tape_param = not isinstance(_qjac, (tuple, list))

if single_tape_param:
# Without dimension (e.g. expval) or with dimension (e.g. probs)
Expand Down
Loading
Loading