A Fourier Neural Operator trained to emulate the nonlinear evolution of a magnetized Kelvin–Helmholtz instability — and a rigorous test of whether it learns the underlying physics rather than interpolating the data.
Headline result: trained on data that deliberately excludes the band
Everything here is built from scratch: the pseudo-spectral MHD solver that generates the ground truth, the dataset, the neural operator, and the physics diagnostics.
A shear layer in a conducting fluid rolls up into Kelvin–Helmholtz (KH) vortices. An in-plane magnetic field aligned with the flow resists the roll-up through magnetic tension, and above a critical field strength the instability is suppressed. In terms of the Alfvénic Mach number,
linear theory for a vortex sheet places the marginal point at
A neural operator can obviously be trained to look like the solver. The sharper question — and the one this project is built around — is:
Can the operator recover the magnetic stabilization threshold in a region of parameter space it has never seen?
To answer it honestly, the training set deliberately excludes a band around the
threshold,
1 — Ground truth: a pseudo-spectral MHD solver.
2D incompressible MHD in a doubly periodic box, written in PyTorch. The state is two
scalar fields: vorticity
2 — Dataset. 280 simulations at
3 — Operator. A Fourier Neural Operator learning the one-step map
$(\omega, a)t \mapsto (\omega, a){t+\Delta t}$, conditioned on
Growth is cleanly exponential and resolution-converged (
Transverse kinetic energy
Rolled out autoregressively for 80 steps, the relative
This is the central finding.
A naive field loss produces an excellent-looking surrogate that is blind to the
instability. The reason is a separation of scales: the field is dominated by the static
shear layer (
Three successive changes to the training objective were required:
| Training scheme | Predicted |
corr. with truth | bias | sign correct |
|---|---|---|---|---|
| Full-field loss only | flat at |
— | — | — |
| + perturbation-only loss (Reynolds decomposition, scale-invariant) | grows everywhere — shape learned, rate not | — | — | — |
| + multi-step (rollout) training, |
tracks the truth, strong positive bias | 33% | ||
| + full data, |
tracks the truth closely | 73% | ||
| + longer rollout, |
near-quantitative agreement | 97% |
The two failure modes are worth seeing, because they are the evidence for the diagnosis above:
| naive field loss — instability invisible | perturbation loss only — over-amplified |
|---|---|
![]() |
![]() |
In its final form the operator reproduces the growth-rate curve across the held-out
band it was never trained on, including run-to-run structure driven by
against
Honest assessment. This is a genuine recovery of the magnetic stabilization
threshold from data that excluded it. The operator reproduces the true curve almost
point by point below
- End-to-end ownership of the full chain: physics → numerics → data → deep learning → evaluation, with no black boxes.
- A solver validated against analytic linear theory, not merely "looking plausible".
- An experimental design (the held-out threshold band) that makes the central claim falsifiable.
- Two genuine debugging results found by rigorous checking rather than assumed away: a time-step instability that silently corrupted 4% of the dataset, and an under-resolved shear layer.
- A result obtained by diagnosis rather than by tuning: the first two training objectives failed in opposite ways, and each fix followed from understanding why.
- Limitations quantified and reported (the residual bias) rather than omitted.
-
Residual positive bias (
$+0.034$ ) in the predicted growth rate, concentrated in the marginal region above$M_A \approx 2$ , which places the predicted threshold slightly below the solver's own. Each increase of the training rollout horizon reduced it ($K=4 \to 6 \to 8$ gave bias$0.168 \to 0.089 \to 0.034$ ), so a longer horizon, full-resolution ($128^2$ ) training and larger capacity are untried headroom. -
High-wavenumber noise: the operator adds spurious energy at small scales that the
solver dissipates (see
notebooks/05_energy_spectrum.png). - Ground-truth growth rates inside the marginal band are themselves noisy over the simulated horizon, which limits how sharply the test can discriminate.
- Only KH is covered; current-driven (kink) and magnetorotational instabilities are the planned extensions.
python -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt && pip install -e .
python scripts/generate_data.py --config configs/kh_baseline.yaml # ~3 h, 2.8 GB
python scripts/validate_solver.py # solver vs theory
python scripts/train.py --config configs/kh_baseline.yaml \
--epochs 20 --rollout-steps 6 --fluct-weight 1.0
python scripts/evaluate.py --config configs/kh_baseline.yaml \
--ckpt checkpoints/fno_best.pt --normalizer checkpoints/normalizer.jsonTraining uses CUDA or Apple MPS automatically when available (--device to force one).
pytest runs the full test suite (42 tests: spectral operators against analytic
derivatives, solver stability and physics regressions, data pipeline, model, losses).
src/mhd_fno/
├── solver/ # pseudo-spectral 2D MHD solver (spectral ops, KH initial state, engine)
├── data/ # parameter sweep, HDF5 generation, Dataset, normalization
├── models/ # Fourier Neural Operator
├── training/ # losses (incl. perturbation loss), trainer with multi-step rollout
├── evaluation/ # growth rates, rollout, energy spectra
└── utils/ # device selection
configs/ scripts/ tests/ notebooks/
The mean field is split off because a uniform
See ROADMAP.md for the phase-by-phase plan and design decisions.
MIT — see LICENSE.






