Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

PDE parameter estimation

Part 6.3: Fitting a PDE Model to Data

Estimate advection velocity (U) and diffusion coefficient (κ) of the 1D advection-diffusion equation from synthetic observations.

Stack: equinox (model) · diffrax (PDE solver) · optax (optimizer) · coordax (state wrapping)

Problem Setup: 1D Advection-Diffusion

PDE: ∂T/∂t = −U·∂T/∂x + κ·∂²T/∂x² (periodic domain)

Spatial domain: 0.0 — 98.4 km  (64 pts)
True params: U=5.0 km/h, κ=0.5 km²/h

PDE Right-Hand Side (Spectral, Periodic BC)

RHS range: -17.034 — 16.797 K/h

Generate Synthetic Observations

Observations: ('time', 'space'), shape: (11, 64)
Noise: 0.5 K (Gaussian)

PDE Model with Equinox

Initial guess: U=3.0, κ=0.20000000298023224

Loss Function and Optimization

Loss at initial guess: 17.1521
Loss at true params:   0.2363
  iter  25: loss=13.6256  U=3.251  κ=0.4448
  iter  50: loss=10.2988  U=3.501  κ=0.6630
  iter  75: loss=7.4664  U=3.745  κ=0.8407
  iter 100: loss=5.2027  U=3.974  κ=0.9729
  iter 125: loss=3.5026  U=4.183  κ=1.0598
  iter 150: loss=2.2995  U=4.367  κ=1.1055
  iter 175: loss=1.4947  U=4.523  κ=1.1174
  iter 200: loss=0.9843  U=4.651  κ=1.1038
  iter 225: loss=0.6763  U=4.753  κ=1.0725
  iter 250: loss=0.4981  U=4.831  κ=1.0303
  iter 275: loss=0.3976  U=4.889  κ=0.9822
  iter 300: loss=0.3410  U=4.930  κ=0.9319
  iter 325: loss=0.3079  U=4.958  κ=0.8817
  iter 350: loss=0.2871  U=4.977  κ=0.8333
  iter 375: loss=0.2729  U=4.988  κ=0.7877
  iter 400: loss=0.2626  U=4.995  κ=0.7456
  iter 425: loss=0.2549  U=4.999  κ=0.7075
  iter 450: loss=0.2491  U=5.001  κ=0.6734
  iter 475: loss=0.2449  U=5.002  κ=0.6436
  iter 500: loss=0.2419  U=5.003  κ=0.6179

Optimization: 18.8s for 500 steps
True:      U=5.0, κ=0.5
Recovered: U=5.0029, κ=0.6179
U error: 0.0029
κ error: 0.1179

Coordax: Wrap Predictions and Residuals

Predictions: ('time', 'space'), shape: (11, 64)
Residual RMS: 0.4918 K
Prediction time-mean: ('space',), shape: (64,)
Spatial mean time series: ('time',), shape: (11,)

Key Patterns

  • equinox.Module — structured, differentiable model with static fields
  • diffrax inside __call__ — fully differentiable PDE solve
  • optax.adam — gradient-based optimizer
  • eqx.filter_value_and_grad — differentiates only array leaves
  • coordax — wraps prediction/observation arrays with time & space coordinates
  • Pattern: generate obs → define loss → optimize → wrap results as Fields