Sanchez-Gonzalez, Godwin, Pfaff, Ying, Leskovec, Battaglia — ICML 2020

Learning to Simulate Complex Physics

Particles are nodes. Interactions are edges. A GNN predicts each particle's next-step acceleration. Roll it out 1000 steps and you get fluid dynamics, rigid bodies, and granular materials — no hand-crafted physics equations required.

Prerequisites: Basic Newtonian physics (force → acceleration → velocity → position) + What a graph neural network does. No simulation experience required.
8
Chapters
4+
Simulations
2002.09405
arXiv

Chapter 0: The Problem

Simulating physics is hard. Traditional particle simulators like SPH (Smoothed Particle Hydrodynamics) or FEM (Finite Element Method) run slowly because they solve differential equations at each time step. Millions of particles, thousands of time steps, hours of CPU time — and if you change the material from water to sand, you rewrite the whole solver.

What if the simulator learned from data instead? You have a high-fidelity reference simulator: expensive, slow, but accurate. Run it on thousands of scenarios. Record the particle positions at each time step. Train a neural network to predict the next state from the current one. At test time, run the neural network instead of the solver. It's 100,000x faster.

The key insight: Physics is local. A particle's next-state depends almost entirely on its nearby neighbors. Water molecules don't care about other molecules 10 meters away. This is exactly what GNNs are designed for — local message passing among neighbors. The GNN is not a coincidence here; it is the natural architecture for a domain where interactions are local, pairwise, and spatially structured.

The paper presents a single, unified framework called Graph Network-based Simulator (GNS) that works across multiple physics domains:

The same architecture, same hyperparameters, same training procedure — different training data, different behavior. The GNN learns the physics from trajectories; no equations are hard-coded.

The Speed-Accuracy Tradeoff

Traditional simulators are accurate but slow. Neural simulators are fast but approximate. Click particles to add them and watch the simplified physics — this is what GNS replaces the expensive solver with.

Why is a GNN a natural fit for physics simulation?

Chapter 1: Particles as Graphs

The first design decision: how to turn a physical system into a graph. The answer is beautifully simple. Each particle is a node. Two particles become connected by an edge if their Euclidean distance is below a threshold r — the interaction radius. This creates a connectivity radius graph, similar to a k-nearest-neighbors graph.

E = {(i,j) : ‖ xi - xj ‖ < r}

The interaction radius r is a hyperparameter. Too small: neighbors miss important interactions. Too large: every particle connects to every other, removing sparsity and defeating the purpose of a GNN. In practice, r is set based on the physics: for water, the interaction length is roughly 2× the average particle spacing.

Node features: Each node (particle) carries a feature vector encoding its recent history — specifically, the last C velocity vectors (a sliding window of recent motion). Why velocity history? Because many physical phenomena are non-Markovian: a particle's next acceleration depends on not just current position but recent trajectory (momentum effects, oscillations, memory of being compressed). The feature vector is [v(t), v(t-1), ..., v(t-C+1), particle_type] — shape [d·C + n_types].
Edge features: Each edge (pairwise interaction) carries the relative displacement vector and Euclidean distance between the two particles: [x_i - x_j, ||x_i - x_j||]. This encodes the geometry of the interaction — how far apart and in which direction. The GNN uses this to compute interaction forces that depend on geometry, as Newton's laws require.

Boundary Handling

Physical systems have walls, floors, and containers. These aren't particles, but they exert forces. GNS handles this with a trick: add the distance to each boundary as an extra dimension of the node feature vector. If the box has 4 walls, add 4 distances: [d_left, d_right, d_top, d_bottom]. The GNN learns from data how much walls affect particle motion — no hard-coded reflection equations.

Particle Graph Construction

Particles with edges drawn when distance < radius r. Drag the radius slider to see connectivity change. The GNN operates on this graph at every time step.

Interaction radius r 50
Why does GNS use a velocity history window as node features, rather than just current position?

Chapter 2: The Interaction Network — Live Sim

GNS uses a three-part GNN architecture: an encoder that embeds raw node and edge features into latent vectors, a processor (M message-passing layers) that propagates interactions through the graph, and a decoder that reads out each node's acceleration from its final latent vector.

Encoder
MLP(node features) → hv(0) ∈ R128. MLP(edge features) → eij(0) ∈ R128.
Processor (×M)
For each layer k: eijk+1 = MLP(hik ∥ hjk ∥ eijk). hvk+1 = MLP(hvk ∥ ∑j evjk+1). Residual connections on both.
Decoder
MLP(hvM) → äv ∈ Rd. This is the predicted acceleration for particle v.
Integration
vvt+1 = vvt + Δt · äv. xvt+1 = xvt + Δt · vvt+1. Euler integration.
GNS Particle Simulator — Interactive

A simplified GNS-style simulation. Particles interact via repulsion and gravity. Adjust message-passing depth and interaction radius. Add particles and watch the system evolve.

Interaction r 45
Gravity 3
python
class GNS(nn.Module):
    def __init__(self, input_dim, hidden=128, M=10):
        # Encoder: raw features → latent
        self.node_enc = MLP(input_dim, hidden)     # [d*C + types] → 128
        self.edge_enc = MLP(3, hidden)              # [rel_disp(2) + dist(1)] → 128
        # Processor: M rounds of message passing
        self.processors = nn.ModuleList([
            InteractionLayer(hidden) for _ in range(M)
        ])
        # Decoder: latent → acceleration
        self.decoder = MLP(hidden, 2)  # → (ax, ay)

    def forward(self, pos, vel_hist, particle_type, edges):
        # Build features
        node_feat = torch.cat([vel_hist, particle_type], dim=-1)
        i, j = edges
        rel_disp = pos[j] - pos[i]
        dist = rel_disp.norm(dim=-1, keepdim=True)
        edge_feat = torch.cat([rel_disp, dist], dim=-1)
        # Encode
        h = self.node_enc(node_feat)   # [N, 128]
        e = self.edge_enc(edge_feat)   # [E, 128]
        # Process (M rounds, with residuals)
        for layer in self.processors:
            h, e = layer(h, e, edges)
        # Decode acceleration
        acc = self.decoder(h)  # [N, 2] — predicted (ax, ay)
        return acc
What does the GNS decoder output, and how is it used to advance the simulation?

Chapter 3: Rollout

Training GNS to predict one-step acceleration is straightforward: minimize the L2 loss between the predicted and ground-truth acceleration at each time step. But the real challenge is rollout — autoregressive generation of long trajectories where each step's output becomes the next step's input.

Rollout compounding error: Suppose your model makes a small error at step 1: position is off by ε. At step 2, it operates on the corrupted position, making a slightly larger error. By step 100, these errors compound. Physics simulations run for thousands of steps — a model that looks good at one-step prediction can produce wildly unstable long rollouts. This is called exposure bias: the model was trained on clean ground-truth inputs but tested on its own noisy outputs.

GNS addresses exposure bias with noise injection during training. Before computing each training example, add small random Gaussian noise to the particle positions. This mimics the corrupted inputs the model will see during rollout. The model learns to be robust to small positional errors because it saw them during training.

˜xv = xv + εv, εv ~ N(0, σ2I)

The noise level σ is a crucial hyperparameter. Too small: model is still brittle at rollout. Too large: training is destabilized. The paper uses σ chosen to match the typical one-step positional error of a preliminary trained model — a principled data-driven calibration.

Training Target: Acceleration, not Position

Why train to predict acceleration rather than position directly? Because acceleration is bounded and smooth. Positions can drift arbitrarily. If you train to predict the next position and the current position has a small error, the model must output a large correction — amplifying instability. Acceleration prediction gives the physics integrator more natural control over trajectory correction.

Rollout Stability vs Noise

Compare rollout stability with and without noise injection at training time. Adjust noise level and see how long the simulation stays physically plausible.

Noise σ 0.0
Why does GNS inject noise into training inputs, even though real trajectories don't have noise?

Chapter 4: Generalization

The most striking claim of the GNS paper: a model trained on 1000-particle simulations generalizes to 5000-particle simulations. This is remarkable because the graph structure changes completely — different number of nodes, different connectivity, different dynamics. How?

Generalization through local processing: The GNS doesn't learn "a simulation of 1000 particles" — it learns "how one particle responds to its local neighbors." This local rule is the same whether there are 1000 or 5000 total particles. The GNN's message-passing operates on individual particles and their immediate neighborhood, not on the global graph. Global scale doesn't matter; local structure does.

This is why the GNN architecture is not just a design choice but a philosophical commitment. A fully connected network takes the entire state as input and cannot generalize to different system sizes. An LSTM processes a fixed-length sequence and has the same problem. The GNN processes each node's local neighborhood independently — and that operation scales to any number of nodes.

Material Generalization

GNS also generalizes across materials using the particle type feature. Each particle's feature vector includes a one-hot encoding of its material type (water, sand, goop, rigid). When a new simulation mixes materials, the GNN learns interactions between different type codes. The MultiMaterial scenario — water + sand + rigid blocks — is trained jointly and the GNN learns all pairwise interaction types from data.

Container Generalization

Training containers are rectangular boxes. At test time, the model encounters L-shaped containers, ramps, and bowls (in the ramp scenarios). Since boundary information is encoded as distances to boundary planes (not as explicit geometry), the model generalizes to different container shapes as long as the local boundary distance is still meaningful.

What GeneralizesHowLimit
Particle countLocal processing — node operation independent of NVery high particle counts may need sampling
Material mixMaterial type as a featureUnseen material type combinations
Container shapeBoundary as distance featureVery complex geometry not in training set
Initial conditionsLearned dynamics, not memorized trajectoriesExtrapolation far from training distribution
Why can GNS generalize from 1000-particle training to 5000-particle testing, while a fully connected network cannot?

Chapter 5: Results

GNS was evaluated on 5 physics domains with rollout lengths of 300-1000 steps. Metrics: mean squared error on particle positions (MSE) and qualitative visual fidelity assessed by human raters.

DomainParticlesRollout StepsPosition MSE (×10-4)Qualitative
WaterRamps~10006000.8Physically plausible splashing
SandRamps~10004001.2Correct pile formation angles
Goop~8005000.6Sticky deformation preserved
MultiMaterial~15003001.9Inter-material interactions correct
FluidShake~60010000.5Sloshing oscillations preserved
Speed comparison: The reference SPH simulator takes ~3 minutes per 600-step trajectory on a single CPU core. GNS takes ~2 seconds on a GPU — roughly 90× speedup. For robotics planning applications that need to simulate thousands of potential futures, this speedup is the difference between offline planning (use SPH) and real-time planning (use GNS).

Ablation studies confirmed three key design choices:

By approximately how much does GNS accelerate simulation compared to SPH?

Chapter 6: vs Traditional Simulation

Traditional physics simulators are built on first principles. They solve the Navier-Stokes equations for fluids, the Mohr-Coulomb yield criterion for sand, constitutive relations for elastic and plastic solids. Every material requires new equations, new numerical methods, new implementations. Each simulator is a specialized tool.

The model/code tradeoff: Traditional simulators encode physics in code (differential equations, discretization schemes, boundary condition solvers). GNS encodes physics in model weights — learned from data. Traditional simulators are exact but rigid. GNS is approximate but flexible. Neither is universally better. The right choice depends on your error tolerance, compute budget, and how much you care about being able to explain what the simulator is doing.

What GNS Cannot Do

Several failure modes of GNS are worth knowing:

PropertyTraditional (SPH/FEM)GNS
SpeedSlow (minutes/trajectory)Fast (seconds/trajectory)
Generalization to new materialNew code requiredNew training data required
Conservation lawsEnforced by constructionApproximate (may drift)
InterpretabilityFull (known equations)Black box
ExtrapolationReliable (solves equations)Risky (may fail out-of-distribution)
Multi-materialHard (different solvers)Easy (particle type feature)
What physical property can traditional simulators enforce by construction that GNS cannot guarantee?

Chapter 7: Connections

GNS is part of a broader movement: neural simulation, or replacing expensive physics solvers with learned surrogates. Understanding its lineage and successors maps the field.

MethodKey Ideavs GNS
Interaction Networks (Battaglia 2016)GNN for physics (precursor)GNS scales and adds noise augmentation
GNS (this paper)Particle GNN + noise + rollout
MeshGraphNets (Pfaff 2021)GNS on meshes (FEM graphs)Non-uniform mesh, same GNN backbone
DPI-Nets (Li 2019)Differentiable physics GNNGNS trains on data; DPI-Nets has analytic gradients
NeuralODE-based methodsLearn continuous dynamicsGNS uses discrete time steps; NeuralODE is continuous
Physics-informed NNs (PINNs)Embed PDEs as loss termsGNS is purely data-driven; PINNs use equation knowledge
MeshGraphNets extends GNS to structured mesh graphs (triangulated meshes from FEM). Instead of particles, nodes are mesh vertices. This handles scenarios where particle methods are inappropriate — thin shells, elastic solids, aerodynamic surfaces. The architecture is nearly identical to GNS; the graph construction is different. Both come from Deepmind's group.
Limitations: (1) Training data cost — you still need a reference simulator to generate trajectories. (2) Distribution shift — fails on scenarios far from training. (3) No physics guarantees — conservation laws, stability guarantees that classical solvers provide are absent. (4) Differentiability is non-trivial — using GNS gradients for optimization requires careful treatment of the rollout's many steps. (5) Contact and collision — very stiff interactions (solid-solid contact) are hard to learn accurately from particle data.

Go Deeper

  • MeshGraphNets (Pfaff et al. 2021) — GNS on FEM mesh graphs
  • Interaction Networks (Battaglia et al. 2016) — the architectural precursor
  • Neural ODEs (Chen et al. 2018) — continuous-time dynamics learning

Key Paper

Sanchez-Gonzalez et al. "Learning to Simulate Complex Physics with Graph Networks." ICML 2020. arXiv:2002.09405

"Physics is local. A particle obeys laws set by its neighbors — not the global configuration. The GNN knows this."