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.

Learning goals

Reading

Why AD matters for PINNs

Physics residuals need ∂x^/∂t\partial \hat{x}/\partial t (and often parameter sensitivities). Finite differences are noisy and scale poorly. Automatic differentiation gives exact derivatives of the computational graph (up to machine precision) for the operations you coded.

In a typical collocation PINN:

  1. Network maps t↦x^(t)t \mapsto \hat{x}(t)

  2. AD supplies x^˙\dot{\hat{x}}

  3. Residual r(x^,x^˙,u,θ)r(\hat{x},\dot{\hat{x}},u,\theta) enters Lphys\mathcal{L}_{\mathrm{phys}}

Forward vs reverse mode (intuition)

PINN training almost always uses reverse mode on a scalar total loss.

Gradient scaling

AD gives exact gradients, but exact gradients can still point in an unhelpful direction when the loss terms have very different scales.

In the classical SMIB of SMIB dynamics, ω\omega is in rad/s. It sits near ω0=2π⋅60≈377\omega_0 = 2\pi \cdot 60 \approx 377, while its swing is a few rad/s. The angle δ\delta is of order 1 rad. Unscaled, rωr_\omega and the ω\omega data term can dominate the total loss, so training mostly fits speed and neglects angle. Inverse problems have the same issue in parameter space: H≈5H \approx 5 and D≈0.1D \approx 0.1 have very different sensitivities.

Practical fixes, in the order to try them:

  1. Non-dimensionalize states. Train on Δω=ω−ω0\Delta\omega = \omega - \omega_0 (or Δω/ω0\Delta\omega/\omega_0) and δ−δ0\delta - \delta_0, not raw ω\omega.

  2. Normalize each loss term by a typical magnitude, or report per-term losses so imbalance is visible.

  3. Rescale parameters. Optimize log⁡H\log H and log⁡D\log D, or values divided by a nominal, inside stated bounds.

  4. Weight terms explicitly (λphys\lambda_{\mathrm{phys}} and per-state weights) and report the weights used.

Plain words: the optimizer follows whichever number is biggest. Make the numbers comparable before trusting the fit.

Further reading: Thuerey et al. (2021) treat this problem in depth, including scale-invariant physics training and half-inverse gradients demonstrated on coupled oscillators. Those algorithms are beyond this course; the fixes above are enough for the labs.

Worked example

Differentiate sin⁡(wt)\sin(w t) w.r.t. tt with AD in PyTorch/torch.autograd and compare to wcos⁡(wt)w\cos(w t).

Lab

Further reading

Common misconceptions

References
  1. Baydin, A. G., Pearlmutter, B. A., Radul, A. A., & Siskind, J. M. (2015). Automatic differentiation in machine learning: a survey. arXiv. 10.48550/arXiv.1502.05767
  2. Bishop, C. M., & Bishop, H. (2024). Deep Learning: Foundations and Concepts. Springer. 10.1007/978-3-031-45468-4
  3. Thuerey, N., Holzschuh, B., Holl, P., Kohl, G., Lino, M., Liu, Q., Schnell, P., & Trost, F. (2021). Physics-based Deep Learning. arXiv. 10.48550/arXiv.2109.05237
  4. Rampure, S. (n.d.). EECS 245 course notes. Retrieved October 14, 2026, from https://notes.eecs245.org/