Experiments
Code, results, and reproducibility of experiments E1–E3
About All the experiments on this site run on an ordinary processor (Intel Xeon, 4 cores, 2.30 GHz, no GPU), in Python 3.13 with NumPy 2.5, SciPy 1.18, Matplotlib 3.11 and PyTorch 2.15 (CPU build). They are small-scale test benches: they test ideas and mechanisms, not performance on real dynamo data. All the numbers quoted in the report come from the result files described here.

Code organization
The experiments/ folder of the repository contains everything needed to reproduce the results. The generic tools (flow matching, Heun sampler, distances, tilting, the 2D MHD and ABC induction solvers) live in the milady package (src/milady/), which the thesis reuses; the scripts import them with the exact settings of the published runs, and tests/test_shared_tools.py checks that they reproduce the earlier code bit for bit.
| File | Role |
|---|---|
common.py |
Networks (MLP, equivariant symmetrization) and training loop; re-exports, with the settings of the runs, conditional flow matching and the Heun scheme (milady.train.flow), the metrics (energy distance, sliced Wasserstein: milady.eval.metrics) and exponential tilting (regularized I-projection: milady.eval.tilt). |
e1_gissinger.py |
E1: invariant distribution of the Gissinger (2012) reversal model, conditioned on \Gamma; symmetry, stationarity identities, Rice formula. Costly steps are cached in results/cache_e1/. |
mhd2d.py |
Pseudo-spectral solver for forced incompressible 2D MHD, in potentials (\omega, a) (re-export of milady.sim.mhd2d). |
e2_data.py |
E2: 2D MHD snapshots for eleven values of \eta (six for training, five for testing). |
e2_mhd2d.py |
E2: free baseline and four divergence-constraint mechanisms, distributional stationarity loss, tilting versus per-sample rescaling. |
e3_abc.py |
E3: kinematic dynamo of the ABC flow, growth rate as a function of Rm (solver milady.sim.induction3d). |
unet.py |
Small periodic U-Net (not used in the final results: too slow on CPU, see below). |
figures.py |
Plots of the results (figures/<name>.png and .svg). |
digest.py |
Numerical digest results/digest.md, the source of the tables of the report. |
Reproducing the results
cd experiments
./run_stage.sh # E1-E3, five seeds, then figures and digest: about 6 h on 4 cores
# or step by step:
python3 e3_abc.py # E3, about 24 min
python3 e2_data.py # E2, data: about 30 min
python3 e2_mhd2d.py --seed k # E2, models, seed k = 0..4: about 38 min each
python3 e1_gissinger.py --train-only --seeds k # E1, training of seed k (resumable cache)
python3 e1_gissinger.py --seeds 0 1 2 3 4 # E1, evaluation over the seeds: about 25 min
python3 figures.py && python3 digest.py > results/digest.mdEach script accepts --quick for a reduced version (from a few minutes to about twenty minutes for E1), useful for checking the installation. The published runs use seeds 0 to 4 for E1 and E2 (./run_stage.sh, one process per seed, two at a time); the digest reports the spread across seeds. The durations given were measured on the machine described above.
E1 — dipole reversals
Gissinger’s three-mode model serves as a “pocket dynamo”: it has the symmetry \mathbf{B}\to-\mathbf{B}, an onset threshold for reversals (between \Gamma = 0.86 and 0.865) and exactly known dynamics. We learn the stationary distribution p(Q, D, V \mid \Gamma) by conditional flow matching, then measure the effect of the symmetry imposed by construction, of the stationarity loss, and of the per-sample projection. The frequency of zero crossings of D (reversals and excursions) is estimated from the generated distribution alone, through the Rice formula.
In short: the equivariant velocity field keeps the distribution symmetric at every value of \Gamma, whereas data augmentation symmetrizes it only at training values; projecting each sample onto \mathrm{d}E/\mathrm{d}t = 0 multiplies the energy distance to the true distribution by about 10; Rice’s formula recovers the crossing frequency with a cumulative error of 12% far from the threshold (up to 41% at a single value) and of 59% near the threshold (one seed); over five seeds, the stationarity loss does no better than a control run on a good model and diverges on a biased model.
Results and discussion: report, section E1. Interactive diagram: Gissinger model.



E2 — 2D MHD and divergence constraints
Forced 2D MHD produces fields (\mathbf{u}, \mathbf{B}) that are divergence-free by construction. We generate these fields conditionally on the parameter \eta in the truncated Fourier basis (220 independent modes per scalar field), which is a POD basis without reduction for a translation-invariant law on a periodic domain (up to a rotation of the modes once the cross helicity couples \mathbf{u} and \mathbf{B}). We compare the free baseline with four ways of handling the divergence, then the effect of a distributional constraint on the energy budget.
Results and discussion: report, section E2.


A first attempt with a periodic U-Net on the 32\times32 grid (file unet.py) cost about 0.3 s per training step on this processor: five variants would have required several hours in total (about 30 min each at the 6000-iteration budget). Switching to the truncated Fourier basis keeps the comparison clean (same network, same budget for all variants) at a cost compatible with a CPU. The internship itself would run on GPU, with field architectures (U-Nets, transformers, functional decoders).
E3 — ABC kinematic dynamo
The induction equation with the imposed ABC flow is solved by a 32^3 pseudo-spectral method. The growth rate \gamma(Rm) changes sign at Rm \approx 8.87, 17.6 and 26.8, in agreement with the known windows. The curl form of the equation keeps \nabla\cdot\mathbf{B} at machine precision (\sim 10^{-16}).
Results: report, section E3. Interactive diagram: ABC dynamo.

Result files
| File | Contents |
|---|---|
results/digest.md |
Numerical tables of all the experiments (generated). |
results/e1_gissinger.json |
E1: configuration, data statistics, evaluation per variant and per \Gamma (mean and standard deviation across seeds), fine grid, noise floors. |
results/e2_mhd2d.json, e2_mhd2d_s1.json to e2_mhd2d_s4.json |
E2, seeds 0 to 4: configuration, evaluation per variant and per \eta, “distributional” part. |
results/e3_abc.json |
E3: growth rates, resolution convergence, interpolated thresholds. |
results/*.npz |
Generated samples and eigenmodes, for the figures and the widgets. |
The files are in the repository: https://github.com/knoel99/milady-2027/tree/main/experiments.