the odin-monty toolkit

MRC Centre for Global Infectious Disease Analysis, Imperial College London

Rich FitzJohn, Marc Baguelin, Ed Knock

2025-02-13

Interactive session

github.com/mrc-ide/odin-monty-hpru-2025

odin - the beginnings (2016-2019)

  • odin created to integrate ODEs (e.g. for compartmental models) in R with a domain-specific language (DSL)
  • Limited support for difference (discrete-time) equations
  • Automatic translation to C/C++/JavaScript; efficient solutions in little code
  • Used in models of malaria, HIV, ebola and other diseases
  • No support for inference

COVID-19 response

  • mcstate and dust emerged during the COVID-19 pandemic
  • Collaborative work by the UK real-time modelling & research software engineers teams at Imperial College
  • Tailored to handle and fit complex state-space models at scale (e.g. Knock et al. 2021)

Challenges addressed by dust and mcstate

  • Efficient (marginal) likelihood computation for large stochastic models via particle filters
  • Exploit parallelism (OpenMP & across chains)
  • Limited toolkit for inference for models created in odin

Recent developments

  • Design of a new architecture, rewiring data, model and parameters

    • rewrite from ground up, keeping best ideas and discarding some baggage
  • Design of a new interface

    • new small BUGS-inspired DSL for priors
    • modular approach to inference
    • inverts the dependency stack
  • Development of automatic differentiation algorithms

Key components

  • monty models can be built from
    • odin and data
    • custom DSL
    • by composition
  • MCMC samplers work on any monty model
  • Concept of “packer”

Introducing monty

  • monty: A framework to handle statistical models (defined by their domain and density)
  • Aims to offers multiple sampling solutions
  • Modular approach so that odin and monty “collaborate” but remain independent

Different samplers

HMC

PT

Introducing automatic differentiation

dt <- 1.0 / freq
p_IR <- 1 - exp(-(gamma) * dt)
S0 <- 1000
freq <- user(4)

N <- S + I + R
p_inf <- beta * I / N * dt
p_SI <- 1 - exp(-(p_inf))
n_SI <- S * p_SI
n_IR <- I * p_IR

update(time) <- (step + 1) * dt
update(S) <- S - n_SI
update(I) <- I + n_SI - n_IR
update(R) <- R + n_IR
update(cases_cumul) <- cases_cumul + n_SI
update(cases_inc) <- if (step %% freq == 0) n_SI else cases_inc + n_SI

initial(time) <- 0
initial(S) <- S0
initial(R) <- 0
initial(I) <- I0
initial(cases_cumul) <- 0
initial(cases_inc) <- 0

beta <- user(0.2)
gamma <- user(0.1)
I0 <- user(10)

Introducing automatic differentiation

  • odin DSL is small
  • Ladder shaped computation graph
  • Regular parameter inputting (red)
  • Regular state outputting (green)

Reverse automatic differentiation

Goal: a large class of odin models and the DSL monty models can autodifferentiate

The odin-monty vision

  • Provide a modern modeling ecosystem:
    1. Powerful DSL (odin2+monty)
    2. Streamlined parallel simulation & filtering engine (dust2)
    3. User-friendly statistical integration platform (monty)
  • Empower researchers to build robust models quickly, accelerating scientific insights

In action!

(switch to RStudio and Ed here)

github.com/mrc-ide/odin-monty-hpru-2025

Toward the future

2025 Roadmap

  • Finish development of automatic differentiation
  • NUTS and HMC algorithms
  • GPU acceleration via CUDA graph API
  • MPI-based backend for many-node
  • Restore missing features from mcstate/dust and original odin

Resources

odin-monty Workshop

📅 24–25 March 2025 📍 White City, Imperial College London

Hybrid participation availableTravel grants availableLightning talk slots!

🔗 Register now here!

⚠️ Deadline: 19/02 – Don’t miss out!