# qml.interfaces.torch.execute¶

execute(tapes, device, execute_fn, gradient_fn, gradient_kwargs, _n=1, max_diff=2, mode=None)[source]

Execute a batch of tapes with Torch parameters on a device.

This function may be called recursively, if gradient_fn is a differentiable transform, and _n < max_diff.

Parameters
• tapes (Sequence[QuantumTape]) – batch of tapes to execute

• device (Device) – Device to use to execute the batch of tapes. If the device does not provide a batch_execute method, by default the tapes will be executed in serial.

• execute_fn (callable) – The execution function used to execute the tapes during the forward pass. This function must return a tuple (results, jacobians). If jacobians is an empty list, then gradient_fn is used to compute the gradients during the backwards pass.

• gradient_kwargs (dict) – dictionary of keyword arguments to pass when determining the gradients of tapes

• _n (int) – a positive integer used to track nesting of derivatives, for example if the nth-order derivative is requested.

• max_diff (int) – If gradient_fn is a gradient transform, this option specifies the maximum order of derivatives to support. Increasing this value allows for higher order derivatives to be extracted, at the cost of additional (classical) computational overhead during the backwards pass.

• mode (str) – Whether the gradients should be computed on the forward pass (forward) or the backward pass (backward).

Returns

A nested list of tape results. Each element in the returned list corresponds in order to the provided tapes.

Return type

list[list[torch.Tensor]]