qml.grad

grad(func, argnum=None)[source]

Returns the gradient as a callable function of (functions of) QNodes.

Function arguments with the property requires_grad set to False will automatically be excluded from the gradient computation, unless the argnum keyword argument is passed.

Parameters

func (function) – a plain QNode, or a Python function that contains a combination of quantum and classical nodes

Keyword Arguments

argnum (int, list(int), None) – Which argument(s) to take the gradient with respect to. By default, the arguments themselves are used to determine differentiability, by examining the requires_grad property. Providing this keyword argument overrides this behaviour, allowing argument differentiability to be defined manually for the returned gradient function.

Returns

The function that returns the gradient of the input function with respect to the differentiable arguments, or, if specified, the arguments in argnum.

Return type

function