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

The idea

Simulation-based least squares already puts the simulator in the loop: pick (H,D)(H, D), simulate, compare with measurements. What it lacks is a cheap direction to move (H,D)(H, D). A grid search simulates many candidates, and finite differences need extra simulations per parameter.

Differentiable simulation writes the integrator itself in an automatic-differentiation framework. Each solver step is an ordinary differentiable operation, so reverse-mode AD returns

∂L∂θ,L(θ)=1N∑k(ω^k(θ)−ωkmeas)2,θ=(H,D),\frac{\partial \mathcal{L}}{\partial \theta}, \qquad \mathcal{L}(\theta) = \frac{1}{N}\sum_{k} \big(\hat{\omega}_k(\theta) - \omega^{\mathrm{meas}}_k\big)^2, \qquad \theta = (H, D),

from a single forward rollout and one backward pass, where ω^k(θ)\hat{\omega}_k(\theta) is the simulated speed at sample kk.

How the gradient flows

For the classical SMIB of SMIB dynamics, one RK4 step maps the state xk=(δk,ωk)x_k = (\delta_k, \omega_k) to

xk+1=ΦΔt(xk; θ,Xk),x_{k+1} = \Phi_{\Delta t}(x_k;\, \theta, X_k),

where XkX_k is the network reactance for the current stage (prefault, fault-on, postfault). The trajectory is a chain x0→x1→⋯→xNx_0 \to x_1 \to \cdots \to x_N, and the loss gradient is the chain rule along that chain. Backpropagation computes it automatically, carrying the sensitivity of each state to HH and DD backward through every step.

Two practical conditions make this work in the teaching model:

  1. Fault switching depends on time only. The reactance changes at fixed tft_f and tct_c, so put both on the step grid. Each step then sits inside one stage, and nothing non-differentiable happens inside a step. State-triggered events (protection acting on δ\delta) need event-aware solvers and are beyond this course.

  2. Scales are comparable. Fit log⁡H\log H and log⁡D\log D, and compare speed deviation ω−ω0\omega - \omega_0, as in gradient scaling.

Course helper: sciml_ps.smib_torch.rollout_smib (fixed-step RK4 in PyTorch, tensors (batch, time, 2)). parity_error checks it against the SciPy reference solver used in Lab 1.

Three estimators, one data contract

Simulation LS (grid or derivative-free)Differentiable simulationInverse PINN
Unknownsθ\thetaθ\thetaNN weights and θ\theta
Trajectory obeys the model?Exactly (solver)Exactly (solver)Approximately (residual penalty)
Gradient sourceNone or finite differencesAD through solver stepsAD through network and residual
Cost per iterationOne simulation per candidateOne rollout + backward passOne network pass over collocation points
NeedsAny simulatorDifferentiable solverNetwork, collocation design, loss weights
Main failure modeCoarse grid; many simulationsLong or stiff rollouts give poor gradients; solver must be rewritten in ADNetwork absorbs model error; weighting shifts θ\theta

The comparison rule from Lab 3 still holds: same measurements, noise, window, and bounds for every estimator, and a held-out disturbance for every estimate.

What it does not fix

Where it leads

Differentiable simulators are also the basis of hybrid models: a neural term trained inside the solver, next to the known swing equation. See Neural ODE / hybrid. That is how SciML models can later plug into established simulation workflows instead of replacing them.

Lab

Honesty rule

Fast convergence is not recovery. Report the true or reference θ\theta when known, the estimate, the bounds, and the held-out disturbance error, as for every other estimator.

Common misconceptions

References
  1. 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