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:
- Return type:
- Returns:
Nested dict matching the Tesseract’s output schema, with differentiable array outputs as
torch.Tensor(withgrad_fnwhen 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()