qp.math.in_backprop¶
- in_backprop(tensor, interface=None)[source]¶
Returns True if the tensor is considered to be in a backpropagation environment, it works for Autograd and Jax. It is not only checking the differentiability of the tensor like
requires_grad(), but rather checking if the gradient is actually calculated.- Parameters:
tensor (tensor_like) – input tensor
interface (str) – The name of the interface. Will be determined automatically if not provided.
- Returns:
whether the tensor is in a backpropagation environment or not.
- Return type:
bool
Example
>>> from pennylane import numpy as np >>> x = np.array(0.6, requires_grad=True) >>> in_backprop(x) False >>> def cost(x): ... print(in_backprop(x)) ... return x ** 2 >>> qp.grad(cost)(x) True tensor(1.2, requires_grad=True)
See also