Skip to content

Commit

Permalink
move some code into make_execution_config
Browse files Browse the repository at this point in the history
  • Loading branch information
andrijapau committed Nov 15, 2024
1 parent 1d0e488 commit 2e0fee8
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions pennylane/workflow/qnode.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def _convert_to_interface(res, interface):
def _make_execution_config(
circuit: Optional["QNode"], diff_method=None, mcm_config=None
) -> "qml.devices.ExecutionConfig":
circuit_interface = getattr(circuit, "interface", None)
execute_kwargs = getattr(circuit, "execute_kwargs", {})
gradient_kwargs = getattr(circuit, "gradient_kwargs", {})
grad_on_execution = execute_kwargs.get("grad_on_execution")
Expand All @@ -98,8 +99,12 @@ def _make_execution_config(
elif grad_on_execution == "best":
grad_on_execution = None

# Mapping numpy to None here because `qml.execute` will map None back into
# numpy. If we do not do this, numpy will become autograd in `qml.execute`.
# If the user specified interface="numpy", it would've already been converted to
# "autograd", and it wouldn't be affected.
return qml.devices.ExecutionConfig(
interface=getattr(circuit, "interface", None),
interface=None if circuit_interface == "numpy" else circuit_interface,
gradient_keyword_arguments=gradient_kwargs,
gradient_method=diff_method,
grad_on_execution=grad_on_execution,
Expand Down Expand Up @@ -970,13 +975,6 @@ def _execution_component(self, args: tuple, kwargs: dict) -> qml.typing.Result:
mcm_config = copy.copy(execute_kwargs["mcm_config"])

config = _make_execution_config(self, self.diff_method, mcm_config=mcm_config)

# Mapping numpy to None here because `qml.execute` will map None back into
# numpy. If we do not do this, numpy will become autograd in `qml.execute`.
# If the user specified interface="numpy", it would've already been converted to
# "autograd", and it wouldn't be affected.
_interface_user_input = None if self.interface == "numpy" else self.interface
config.interface = _interface_user_input
config = _resolve_execution_config(
(self._tape,), self.device, config, self.transform_program
)
Expand Down

0 comments on commit 2e0fee8

Please sign in to comment.