API reference

PyTorch compatibility layer for Tesseract.

Provides apply_tesseract(), which wraps any Tesseract as a differentiable PyTorch operation supporting both reverse-mode (.backward()) and forward-mode (torch.autograd.forward_ad) automatic differentiation.

tesseract_torch.apply_tesseract(tesseract, inputs)[source]

Call a Tesseract as a differentiable PyTorch operation.

Infers which inputs/outputs are differentiable from the Tesseract’s schema. Torch tensors provided for differentiable fields participate in autograd; all other values are passed through as static inputs.

Supports both reverse-mode (.backward()) and forward-mode (torch.autograd.forward_ad) differentiation.

Parameters:
  • tesseract (Tesseract) – A Tesseract instance.

  • inputs (dict[str, Any]) – Nested dict matching the Tesseract’s input schema. Provide torch.Tensor for array fields you want gradients through, and plain Python / NumPy values for everything else.

Return type:

dict[str, Any]

Returns:

Nested dict matching the Tesseract’s output schema, with differentiable array outputs as torch.Tensor (with grad_fn when inputs require grad) and non-differentiable outputs as-is (NumPy arrays or scalars).

Example:

# Flat schema
result = apply_tesseract(quadratic, {"x": x, "A": A, "b": b})
result["y"].sum().backward()

# Nested schema
result = apply_tesseract(meshstats, {
    "mesh": {"n_points": 3, ..., "points": points_tensor}
})
result["statistics"]["barycenter"].sum().backward()