Open r-ash opened 2 years ago
This package has the proposed pattern for interfacing with TMB: https://github.com/mrc-ide/ccmpp.tmb It also has an attempt at a class-structured simulation model.
Idea for this is to have templated C++ code packages as a header only library. The templating means we can use it with TMB. It will be class structured and have methods for each step of the model like
model_fit
+ demography_projection
+ adult_art
+ mortality
+ births
etc. and then each time step will run each of these functions (demography_projection, adult_art, etc.).
Avenir will want to extend this to e.g. include TB values in the model, they will do this by calling the functions that they want to run and then running some additional code they write themselves to simulate the rest of the model they want to add. They will then loop over this for however number of time steps.
For researchers to extend this they will fork the code, make additions and then we can integrate them into the code as a PR. The base model will need to still be runnable without any extensions so we need feature switches. We could manage this by having a runner which defines different types of model run. Where each one calls different functions from the class. e.g. a
base_model <- function() {
fit = new model_fit()
for each time step {
fit$demography()
fit$adult_art()
fit$mortality()
...
}
}
paediatric_model <- function() {
fit = new model_fit()
for each time step {
fit$demography()
fit$adult_art()
fit$child_art()
fit$mortality()
...
}
}
We could alternatively have switches. run_model(include_paediatric = TRUE)
but might get complicated with a large amount of switches.
The R wrapper will use Rcpp or cpp11.
Jeff is keen that we modify the memory in place. So the model will take pointers to the data, the model fit will modify that data in place and then Avenir's extensions will also modify the data in place.
Different models and steps
MVP
EPPASM Adds
shiny90 Adds
CSAVR
Spectrum/AIM (will be implemented by Spectrum)
Avenir also want to be able to run 1 year and then see the output. They will run 1 year, run some further process on the data. Then run next year in the projection and run some other process etc.
Avenir will want the model as is with Maggie's fertility work
Would be helpful if we can make a diagram of what the model does
Avenir requirements
Avenir will write their own C++ wrapper which will do the mapping from python types in C++. They want to be able to run it like
// ...initialize inputs and outputs…
calc_baseyear_events(); // calculate births and deaths in the first year of the projection
for year in years:
project_pop_one_year(year); // do demographic calculations for one year
project_hiv_one_year(year); // do HIV dynamics calculations for one year
calc_net_migration(year, has_aim); // do end-year net migration calculations. “has_aim” flag is used to toggle use of HIV+ net migrant inputs
adjust_population(year); // apply population adjustment file if used
postyear_hiv_calcs(year); // tally results (this currently calculates the ultimate need for ART in children and adults
Leapfrog is an extensible implementation of HIV EPP-ASM model which will act as a common code base for R, Spectrum and any other applications which want to use the model
Requirements
Qs