Skip to content

Commit f9e8f62

Browse files
andrijapauringo-but-quantummaliasadialbi3ro
authored
Update logic for enabling grad_on_execution in lightning_*.py devices (#1016)
**Context:** In PennyLane, `grad_on_execution` is expected to be enabled when the gradient method is set to `adjoint`. Since this is automatically true for Lightning devices, the `use_device_gradient` flag can serve as an additional condition to decide whether to enable `grad_on_execution`. This discrepancy caused certain Lightning device tests to fail during a PennyLane workflow clean-up PR. The issue arose because PennyLane expected `grad_on_execution` to be `None` but received `True` instead. Further details can be found in the [PR workflow](https://github.com/PennyLaneAI/pennylane/actions/runs/12129490447/job/33818035152?pr=6657). **Description of the Change:** Update logic for when `grad_on_execution` is turned on in `lightning` device configurations. **Benefits:** Unblocks PennyLaneAI/pennylane#6657 **Possible Drawbacks:** None. [sc-72150] --------- Co-authored-by: ringo-but-quantum <[email protected]> Co-authored-by: Ali Asadi <[email protected]> Co-authored-by: Christina Lee <[email protected]>
1 parent 158d393 commit f9e8f62

File tree

5 files changed

+19
-4
lines changed

5 files changed

+19
-4
lines changed

.github/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626

2727
### Improvements
2828

29+
* Update the logic for enabling `grad_on_execution` during device execution.
30+
[(#1016)](https://github.com/PennyLaneAI/pennylane-lightning/pull/1016)
31+
2932
* Reverse Lightning Qubit generators vector insertion order.
3033
[(#1009)](https://github.com/PennyLaneAI/pennylane-lightning/pull/1009)
3134

pennylane_lightning/core/_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616
Version number (major.minor.patch[-label])
1717
"""
1818

19-
__version__ = "0.40.0-dev26"
19+
__version__ = "0.40.0-dev27"

pennylane_lightning/lightning_gpu/lightning_gpu.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,11 @@ def _setup_execution_config(self, config):
299299
updated_values["gradient_method"] = "adjoint"
300300
if config.use_device_gradient is None:
301301
updated_values["use_device_gradient"] = config.gradient_method in ("best", "adjoint")
302-
if config.grad_on_execution is None:
302+
if (
303+
config.use_device_gradient
304+
or updated_values.get("use_device_gradient", False)
305+
and config.grad_on_execution is None
306+
):
303307
updated_values["grad_on_execution"] = True
304308

305309
new_device_options = dict(config.device_options)

pennylane_lightning/lightning_kokkos/lightning_kokkos.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,11 @@ def _setup_execution_config(self, config):
271271
updated_values["gradient_method"] = "adjoint"
272272
if config.use_device_gradient is None:
273273
updated_values["use_device_gradient"] = config.gradient_method in ("best", "adjoint")
274-
if config.grad_on_execution is None:
274+
if (
275+
config.use_device_gradient
276+
or updated_values.get("use_device_gradient", False)
277+
and config.grad_on_execution is None
278+
):
275279
updated_values["grad_on_execution"] = True
276280

277281
new_device_options = dict(config.device_options)

pennylane_lightning/lightning_qubit/lightning_qubit.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,11 @@ def _setup_execution_config(self, config):
310310
updated_values["gradient_method"] = "adjoint"
311311
if config.use_device_gradient is None:
312312
updated_values["use_device_gradient"] = config.gradient_method in ("best", "adjoint")
313-
if config.grad_on_execution is None:
313+
if (
314+
config.use_device_gradient
315+
or updated_values.get("use_device_gradient", False)
316+
and config.grad_on_execution is None
317+
):
314318
updated_values["grad_on_execution"] = True
315319

316320
new_device_options = dict(config.device_options)

0 commit comments

Comments
 (0)