epiverse-trace / epidemics

A library of published compartmental epidemic models, and classes to represent demographic structure, non-pharmaceutical interventions, and vaccination regimes, to compose epidemic scenarios.
https://epiverse-trace.github.io/epidemics/
Other
8 stars 2 forks source link

Linking compiled {odin} code with {epidemics} #223

Open pratikunterwegs opened 2 months ago

pratikunterwegs commented 2 months ago

Questions come from @LloydChapman:

  • IIRC, nothing about the package constrains the models used to being deterministic ODE models, but are there any constraints on the format of the models in terms of the model C++ code? It sounded like it’s currently set up mainly to handle deterministic ODE models in terms of the BOOST ODE integration?
  • I’m wondering how easily {epidemics} could handle e.g. a stochastic discrete-time model written in odin and compiled to work with dust using odin.dust, with some wrapping? Here’s an example of what the compiled C++ code for an SIR model looks like: https://github.com/LloydChapman/seir/blob/main/src/sir.cpp

Obviously I’m not cognisant of all the details, but it sounded like it might be possible for {epidemics} to take odin models as an input, especially if they’re planning to completely decouple odin and mcstate.

pratikunterwegs commented 2 months ago

Thanks @LloydChapman for the questions, I've tried to answer them here, but happy to have another go if something isn't clear. Also cc-ing @adamkucharski.

IIRC, nothing about the package constrains the models used to being deterministic ODE models

Indeed - we have a stochastic Ebola model that's in R, and we did have R versions of the ODE models as well (the ODE systems in R are still available in the repo).

but are there any constraints on the format of the models in terms of the model C++ code? It sounded like it’s currently set up mainly to handle deterministic ODE models in terms of the BOOST ODE integration?

Our ODE models use Boost odeint, but that doesn't restrict what other types of C++ models could be included, if I've understood the question correctly. Each model stands alone - so the ODE integration happens within each model function. The model functions also have two levels, a user-facing top level, and an internal lower level, so we can swap out the internals while (making sure that) the output of the user-facing functions doesn't change.

I’m wondering how easily {epidemics} could handle e.g. a stochastic discrete-time model written in odin and compiled to work with dust using odin.dust, with some wrapping? Here’s an example of what the compiled C++ code for an SIR model looks like: https://github.com/LloydChapman/seir/blob/main/src/sir.cpp

I think it should definitely be possible to include it in the package itself, but did you mean how well Boost would handle it? I'm not actually sure! Here's a minimal example from Epirecipes of how the underlying C++ code is structured. I think the first argument to integrate is required to be a function with requirements on arguments, so potentially any C++ function would do.

...it might be possible for {epidemics} to take odin models as an input, especially if they’re planning to completely decouple odin and mcstate.

The {epidemics} models have pretty tight vertical integration (which makes them standalone), so there isn't a general integrator function per se to pass any compiled code (i.e., not a replacement for deSolve::lsoda()).