⚙️ torch-diffsim#

torch-diffsim is a minimal differentiable physics simulator built entirely in PyTorch. It uses semi-implicit (symplectic Euler) time integration for tetrahedral finite element method (FEM) simulations with full automatic differentiation support.

Key Features#

  • PyTorch-native rollouts. Put simulation inside an nn.Module training loop and call loss.backward().

  • Tetrahedral FEM. Stable Neo-Hookean elasticity with lumped vertex masses and a semi-implicit Euler core.

  • Explicit boundary conditions. Fix selected vertices while preserving gradients through every unconstrained degree of freedom.

  • Inspectable fields. Compute deformation gradients, Cauchy stress, strain, element Jacobians, and energies from tensors.

  • Three contact levels. Fast ground projection, a differentiable finite penalty, or optional frictionless IPC with CCD.

  • Minimal implementation. The mechanics are compact enough to read, validate, and extend.

Installation#

Install torch-diffsim using pip:

pip install torch-diffsim

# Optional IPC backend
pip install "torch-diffsim[ipc]"

Or install from source:

git clone https://github.com/Rishit-dagli/torch-diffsim
cd torch-diffsim
pip install -e .

Start here#

Run the two small examples:

# Fixed ear-tip boundary conditions, deformation, stress, and strain
python examples/suspended_bunny.py

# Shared neural feedback trained through four 48-step FEM conditions
python examples/train_neural_controller.py --plot neural_bunny.png

The Quickstart shows the corresponding code. The Examples page adds the small-system IPC contact demo and describes what each visualization should do.

Documentation Contents#

Indices and tables#