← tomás.erdmannsdörffer ● trains live on your GPU · TensorFlow.js

Watch a neural network learn physics.

This page trains a Physics-Informed Neural Network in your browser to solve the 1D viscous Burgers equation, the canonical benchmark from Raissi et al. (2019). No data labels, no ground truth: the network learns purely from the PDE residual, boundary and initial conditions. Hit a preset and watch it converge.

PINNBurgers equationTensorFlow.js WebGLAutodiffZero data
1A net guesses u(t, x) A small MLP maps any point in spacetime to a solution value. At first it's nonsense.
2Autodiff grades it Exact derivatives ∂u/∂t, ∂u/∂x are plugged into the PDE. The violation is the loss.
3Adam fixes it Each step nudges the weights until the heatmap below satisfies the physics everywhere.

controls

smaller ν → sharper shock
∂u/∂t + u·∂u/∂x = ν·∂²u/∂x²
x ∈ [−1, 1] · t ∈ [0, 1]
u(0, x) = −sin(πx)
u(t, ±1) = 0
Loading TensorFlow.js…
iteration
0
total loss
-
pde residual
-
boundary + ic
-
Predicted solution u(t, x) x → horizontal · t → vertical (0 top, 1 bottom)
u = −1
u = +1
Solution slices u(x) over time t = 0 → 1, teal → coral
Loss curves (log scale) - total ·, pde ·, boundary

What's a Physics-Informed Neural Network?

A standard neural network learns from input/output pairs. A PINN learns from a differential equation. Instead of asking "what's the right answer for this input?" it asks "how badly does my prediction violate the laws of physics?", and uses that violation as the loss.

We build a network uθ(t, x) that maps a point in spacetime to a solution value, use automatic differentiation to get its partial derivatives, exactly, not numerically, and plug them into the PDE residual:

r(t, x) = ∂u/∂t + u · ∂u/∂x − ν · ∂²u/∂x²

A perfect solution has r = 0 everywhere, so the loss is the mean squared residual at random collocation points, plus penalties for the initial and boundary conditions:

L = λ · ‖r‖² + ‖u(0, x) + sin(πx)‖² + ‖u(t, ±1)‖²

why this matters

No training data is required: the "supervision" is the physics itself. That makes PINNs valuable for inverse problems, high-dimensional PDEs where meshes explode, and domains where the governing equations are known but measurements are scarce, like cardiac biomechanics, my MSc research area.

things to try

· Hit 🌊 shock wave and watch a discontinuity form near t ≈ 0.4.
· Set the PDE weight λ to 0.01, the network only learns the boundaries and ignores the physics.
· Hit 🐜 tiny net: an 8×2 MLP simply can't represent the solution. Underfitting, live.
· Push collocation points to 5000 for cleaner residuals at a higher cost per step.

implementation notes

Fully-connected tanh MLP. First derivatives via tf.grad; the second derivative uxx uses a central difference of ux at x ± ε, since TensorFlow.js can't differentiate through tf.grad like PyTorch's create_graph=True or JAX's jacfwd/jacrev: gradients still flow correctly because each ux is itself a full autodiff result. Adam optimizer, WebGL backend, and the training loop adapts how many steps it runs per frame to keep the page smooth on your device.