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 conditions, and initial condition. Running entirely on your device via TensorFlow.js with WebGL acceleration.
[01] Controls
[02] The PDE
u(0, x) = −sin(πx)
u(t, ±1) = 0
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.
Concretely, we build a network uθ(t, x) that takes a point in spacetime and predicts the solution value. We then use automatic differentiation to compute its partial derivatives — exactly, not numerically — and plug them into the PDE residual:
A perfect solution satisfies r = 0 everywhere. So the training loss is just the mean squared residual at a sample of random collocation points in the domain, plus penalty terms for the initial and boundary conditions:
Why this is interesting
No training data is required. The "supervision" is the physics itself. This makes PINNs valuable for inverse problems (recovering hidden parameters from sparse measurements), high-dimensional PDEs where mesh-based solvers explode, and problems where governing equations are known but measurements are scarce — like cardiac biomechanics, my MSc research area.
Things to try
· Crank viscosity down (ν = 0.001/π) and watch a shock form near t ≈ 0.4.
· Set the PDE weight λ to zero and watch the network only learn the boundaries.
· Drop hidden width to 8 and see the solution become unstable.
· Increase collocation points to 5000 for cleaner residuals at higher cost per step.
Implementation notes
The network is a fully-connected MLP with tanh activations. First derivatives
(ut, ux) are computed by automatic differentiation via
tf.grad. The second derivative uxx is approximated by a
central difference of ux evaluated at x ± ε — TensorFlow.js doesn't
support differentiating through tf.grad like PyTorch's
create_graph=True or JAX's jacfwd/jacrev, so we use a
hybrid scheme. Gradients still flow correctly through the FD stencil because each
ux evaluation is itself a full autodiff result. Training uses Adam.
Solution rendered to a 400×240 canvas with the RdBu_r diverging colormap on a 100×80
grid. Everything runs locally on your device's GPU via WebGL.