warp.autograd.jacobian#
- warp.autograd.jacobian(
- function,
- dim=None,
- inputs=None,
- outputs=None,
- input_output_mask=None,
- device=None,
- max_blocks=0,
- block_dim=256,
- max_outputs_per_var=-1,
- plot_jacobians=False,
- metadata=None,
Computes the Jacobians of a function or Warp kernel for the provided selection of differentiable inputs to differentiable outputs.
The input function can be either a Warp kernel (e.g. a function decorated by
@wp.kernel) or a regular Python function that accepts arguments (of which some must be Warp arrays) and returns a Warp array or a list of Warp arrays.In case
functionis a Warp kernel, its adjoint kernel is launched with the given inputs and outputs, as well as the provideddim,max_blocks, andblock_dimarguments (seewarp.launch()for more details).Note
If
functionis a Warp kernel, the input arguments must precede the output arguments in the kernel code definition.Only Warp arrays with
requires_grad=Trueare considered for the Jacobian computation.Function arguments of type
wp.structare not yet supported.- Parameters:
function (Kernel | Callable) – The Warp kernel function, or a regular Python function that returns a Warp array or a list of Warp arrays.
dim (tuple[int] | None) – The number of threads to launch the kernel, can be an integer, or a Tuple of ints. Only required if
functionis a Warp kernel.inputs (Sequence | None) – List of input variables. At least one of the arguments must be a Warp array with
requires_grad=True.outputs (Sequence | None) – List of output variables. Optional if the function is a regular Python function that returns a Warp array or a list of Warp arrays. Only required if
functionis a Warp kernel.input_output_mask (list[tuple[str | int, str | int]] | None) – List of tuples specifying the input-output pairs to compute the Jacobian for. Inputs and outputs can be identified either by their integer indices of where they appear in the kernel input/output arguments, or by the respective argument names as strings. If None, computes the Jacobian for all input-output pairs.
device (Device | str | None) – The device to launch on (optional). Only used if
functionis a Warp kernel.max_blocks – The maximum number of CUDA thread blocks to use. Only used if
functionis a Warp kernel.block_dim – The number of threads per block. Only used if
functionis a Warp kernel.max_outputs_per_var – Maximum number of output dimensions over which to evaluate the Jacobians for the input-output pairs. Evaluates all output dimensions if value <= 0.
plot_jacobians – If True, visualizes the computed Jacobians in a plot (requires
matplotlib).metadata (FunctionMetadata | None) – The metadata of the kernel function, containing the input and output labels, strides, and dtypes. If None or empty, the metadata is inferred from the kernel or function.
- Returns:
A dictionary of Jacobians, where the keys are tuples of input and output indices, and the values are the Jacobian matrices.
- Return type: