diff --git a/doc/releases/changelog-dev.md b/doc/releases/changelog-dev.md index 826530f0d6c..a27bbe29056 100644 --- a/doc/releases/changelog-dev.md +++ b/doc/releases/changelog-dev.md @@ -90,6 +90,9 @@ visualizations, allowing global and per-wire customization with options like `color`, `linestyle`, and `linewidth`. [(#6486)](https://github.com/PennyLaneAI/pennylane/pull/6486) +* `QNode` and `qml.execute` now forbid certain keyword arguments from being passed positionally. + [(#6610)](https://github.com/PennyLaneAI/pennylane/pull/6610) + * Shortened the string representation for the `qml.S`, `qml.T`, and `qml.SX` operators. [(#6542)](https://github.com/PennyLaneAI/pennylane/pull/6542) diff --git a/pennylane/workflow/execution.py b/pennylane/workflow/execution.py index 75162c4db22..d4fc3ecab52 100644 --- a/pennylane/workflow/execution.py +++ b/pennylane/workflow/execution.py @@ -249,6 +249,7 @@ def execute( device: Union["qml.devices.LegacyDevice", "qml.devices.Device"], diff_method: Optional[Union[Callable, str, qml.transforms.core.TransformDispatcher]] = None, interface: Optional[str] = "auto", + *, transform_program=None, inner_transform=None, config=None, @@ -411,9 +412,16 @@ def cost_fn(params, x): gradient_kwargs = gradient_kwargs or {} mcm_config = mcm_config or {} - config = config or _get_execution_config( - diff_method, grad_on_execution, interface, device, device_vjp, mcm_config, gradient_kwargs - ) + if not config: + config = qml.devices.ExecutionConfig( + interface=interface, + gradient_method=diff_method, + grad_on_execution=None if grad_on_execution == "best" else grad_on_execution, + use_device_jacobian_product=device_vjp, + mcm_config=mcm_config, + gradient_keyword_arguments=gradient_kwargs, + ) + config = device.setup_execution_config(config) is_gradient_transform = isinstance(diff_method, qml.transforms.core.TransformDispatcher) transform_program, inner_transform = _make_transform_programs( @@ -601,18 +609,3 @@ def _make_transform_programs( transform_program = device.preprocess_transforms(config) return transform_program, inner_transform - - -def _get_execution_config( - diff_method, grad_on_execution, interface, device, device_vjp, mcm_config, gradient_kwargs -): - """Helper function to get the execution config.""" - config = qml.devices.ExecutionConfig( - interface=interface, - gradient_method=diff_method, - grad_on_execution=None if grad_on_execution == "best" else grad_on_execution, - use_device_jacobian_product=device_vjp, - mcm_config=mcm_config, - gradient_keyword_arguments=gradient_kwargs, - ) - return device.setup_execution_config(config) diff --git a/pennylane/workflow/qnode.py b/pennylane/workflow/qnode.py index e5c76495345..34abc47c57f 100644 --- a/pennylane/workflow/qnode.py +++ b/pennylane/workflow/qnode.py @@ -607,6 +607,7 @@ def __init__( device: SupportedDeviceAPIs, interface: SupportedInterfaceUserInput = "auto", diff_method: Union[TransformDispatcher, SupportedDiffMethods] = "best", + *, grad_on_execution: Literal[True, False, "best"] = "best", cache: Union[Cache, Literal["auto", True, False]] = "auto", cachesize: int = 10000,