User-owned dynamics
Write one simulate_fn for a single experiment. The library applies batching, JIT compilation, and differentiation around it.
A JAX library for combining user-written differential equations with trainable predictors, bounded physical quantities, and irregular time-series data.
From a repository checkout:
uv sync --extra examples
uv run python examples/pendulum/train_harmonic.pyIt fits the frequency of a harmonic oscillator and predicts with the fitted model. Getting started walks through the same code, and Examples lists the larger hybrid models.
You write the ODE solve for one experiment. The library batches it over irregular data, differentiates through it, and trains the predictors.
| Part | Responsibility |
|---|---|
predictors | A PyTree of trainable values and networks. |
simulate_fn | Integrates one experiment and returns the full state. |
state_to_output | Selects the observed channels from the full state. |
SolverConfig | Stores the Diffrax solver and its settings. |
Dataset | Stores bucketed observations and masks. |
HybridModel binds the first four; the data is passed per call, as a list of experiments or a Dataset:
import jaxhybridmodels as hm
model = hm.HybridModel(
predictors=predictors,
simulate_fn=simulate_fn,
state_to_output=state_to_output,
output_channel_names=("conc",),
)
result = model.fit(experiments, hm.OptaxTrainingConfig(steps=500, lr=1e-2), key=key)
predictions = result.model.predict(experiments)
hm.print_metrics(predictions)Getting started defines every variable here. Concepts explains the data and model interfaces.
| If you want to... | Start here | Main API |
|---|---|---|
| Build irregular experiments and datasets | Data and buckets | make_experiment, experiments_from_dataframe |
| Write the ODE and observation map | Model interface | HybridModel |
| Choose parameters, networks and bounds | Predictors and bounds | Parameter, BoundedPredictor |
| Train with gradients or population search | Training | Objective, OptaxTrainingConfig, EvosaxTrainingConfig |
| Add time-varying inputs or schedules | Profiles and schedules | ramp_profile, annealing_schedule |
| Save, evaluate, or ensemble models | Saving and loading, Ensembles | save, compute_metrics |
Python 3.11 or newer:
uv add jax-hybridmodels==0.2.0b1The 0.2.0b1 release predates HybridModel, Parameter and Constant. Until the next release, use a checkout and uv sync --extra examples.