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.

Cycle handoff — train an emulator, replace the forward model

Open In Colab

The headline differentiator of pipekit-train vs. a backend-only trainer: the trained model IS the operator that goes into the inference loop. No rewrite, no glue code.

Pattern:

  1. An expensive ForwardModel is what we want to replace.

  2. A SimulationDataset wraps that forward model and yields (state_t, state_{t+dt}) training pairs.

  3. A small neural emulator trains via TrainingLoop to predict state_{t+dt} from state_t.

  4. The trained model wraps into pipekit_cycle.NeuralForward — same protocol as the original forward model — and slots straight into a pipekit_cycle.Cycle for fast forecasting.

Python implementation: CPython
Python version       : 3.12.3
IPython version      : 9.10.0

numpy        : 2.4.4
jax          : 0.10.1
equinox      : 0.13.8
optax        : 0.2.8
pipekit      : 0.0.1
pipekit_cycle: 0.0.1
pipekit_train: 0.0.1

Compiler    : GCC 13.3.0
OS          : Linux
Release     : 6.18.5
Machine     : x86_64
Processor   : x86_64
CPU cores   : 4
Architecture: 64bit

1. The expensive forward model

A 2-D damped harmonic oscillator (stand-in for any expensive physics). In a real workflow this could be a chemistry transport model, a radiative transfer code, or an ocean GCM.

2. SimulationDataset — the bridge from forward model to training

SimulationDataset yields (state_t, state_{t+dt}) pairs. The prior samples initial states; n_samples controls the training set size. Splits (train/val/test) are deterministic via per-sample seeds.

sample shape: state_t=(2,), state_t+dt=(2,)
state_t = [ 0.3047171 -1.0399841]
state_t+dt = [ 0.25271788 -1.0957276 ]
dataset content hash: d608772d2f523bbb…
# samples in train split: 320

3. Train the emulator

Final MSE after 400 steps: 8.832775e-05

4. Drop the trained model into NeuralForward

NeuralForward(model_op=trained_op, dt=expensive.dt) satisfies the pipekit_cycle.ForwardModel Protocol structurally — same step / dt interface as the original. Anything that accepts a ForwardModel (including DACycle, EnsembleCycle, …) now accepts the emulator.

emulator_forward.dt = 0.05
emulator_forward satisfies ForwardModel? True

5. Compare emulator vs. truth on a rollout

<Figure size 1000x350 with 2 Axes>

6. The artifact ties it together

TrainingArtifact records the training pipeline + dataset hash + trained-model hash. Pin it alongside the NeuralForward config and the whole train→serve chain is reproducible from one JSON file.

Backend          : equinox
JAX version      : 0.10.1
Equinox version  : 0.13.8
Final loss       : 8.833e-05
Total seconds    : 2.01

What’s next

  • For real geophysical workflows, attach a pipekit_experiment.LocalModelRegistry (or S3ModelRegistry) via Checkpoint(every_n_steps=…, registry=…) so the trained model is content-addressed.

  • For amortized inference (SBI), supply an obs_op=pipekit_cycle.ObservationOperator(…) to SimulationDataset and train an inverse network — same pattern, different head.

  • The emulator drops into pipekit_cycle.DACycle just as cleanly for ML-augmented data assimilation.