Skip to content

Commit

Permalink
Raise warning when falling back on param-shift (#224)
Browse files Browse the repository at this point in the history
  • Loading branch information
speller26 authored Jan 18, 2024
1 parent ec09acd commit c145947
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/braket/pennylane_plugin/braket_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

import collections
import numbers
import warnings
from collections.abc import Iterable, Sequence

# pylint: disable=invalid-name
Expand Down Expand Up @@ -848,6 +849,14 @@ def execute_and_gradients(self, circuits, **kwargs):
new_jac = np.tensor([])
elif len(observables) != 1 or measurements[0].return_type != Expectation:
gradient_circuits, post_processing_fn = param_shift(circuit)
warnings.warn(
"This circuit cannot be differentiated with the adjoint method. "
"Falling back to the parameter-shift method, which will execute "
f"{len(gradient_circuits)} circuits. "
"To use the adjoint gradient method, make sure the circuit's only measurement "
"is an expectation of one observable. "
"To avoid gradient calculation, mark parameters with `requires_grad=False`."
)
grad_circuit_results = [
self.execute(c, compute_gradient=False) for c in gradient_circuits
]
Expand Down

0 comments on commit c145947

Please sign in to comment.