-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow simulation to be restored with new interventions. #286
Conversation
a601b59
to
dfc82a6
Compare
709fae3
to
627a709
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lovely!
Perhaps a test case for setting correlation? Since it seems an important use case that you spent some time resolving.
#' two phases. Between the two phases, the simulation state is saved and | ||
#' restored. Optionally, the initial warmup phase can use a different set of | ||
#' parameters, by specifying a value for warmup_parameters. | ||
test_resume <- function( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really handy
expect_equal(data[data$n_pev_mass_dose_3 > 0, "timestep"], c(115, 190)) | ||
}) | ||
|
||
test_that("TBV intervention can be added when resuming", { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test seems different from the others, should we name it differently? or remove the TBV parameterisation from the warmup?
test_that("TBV intervention can be added when resuming", { | |
test_that("TBV intervention parameters can be changed when resuming", { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does both. There's a first call to test_resume
with warmup_parameters = base
and a second call with a TBV intervention during the warmup. The point is to make sure we can both add an intervention that didn't exist at all, or we can also add new instances of the same intervention.
I had done the same for PEV and bednets. MDA was actually the odd one out for which I hadn't done this, I'll add it now.
I could break each of those tests into two functions, but then I'd have to move the set_default_XXX
helper functions to the global scope, so this seemed simpler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tweaked the layout of the test a little bit which should make it easier to spot the two parts of it.
Setting correlation doesn't work in this PR yet. I'll have a follow up soon that adds it with some test cases. EDIT: the correlations follow-up is at #293 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please merge in #293 first. Thanks!
This uses a few of individual's new features that make restoring more flexible. It also fixes a bug when restoring the mosquitto solvers, by correctly restoring the timestep, which is needed to model seasonality. The intervention events use the new `restore = FALSE` flag to make sure their schedule can be modified when resuming. Instead of having the events re-schedule themselves everytime they fire, we setup the entire schedule upfront when initialising the simulation. It adds end-to-end testing of this feature, across a range of scenarios. For each scenario, the outcomes of the simulation with and without restoring are compared and we make sure they are equivalent.
When resuming a simulation, it is possible to add new intervention. The correlation of the new intervention may need configuring, both relative to itself and to existing interventions. The correlation parameters work by sampling, at the start of the simulation, relative weights for each individual and intervention. The weight are later used to select which individuals are targeted by the a given intervention. There weights are drawn from a multivariate normal distribution, whose variance-covariance matrix depends on the configured correlation. When adding interventions, new corresponding columns need to be added to the weights matrix. A fresh mvnorm distribution cannot be used, since it would override the already drawn weigths for the existing interventions. The solution instead is to use a conditional mvnorm distribution on the new columns, using the existing values as the conditions. This yields new weigths which follow the determined variance-covariance matrix while preserving the existing values.
3f69bf5
to
ac3703b
Compare
This uses a few of individual's new features that make restoring more flexible. It also fixes a bug when restoring the mosquitto solvers, by correctly restoring the timestep, which is needed to model seasonality. The intervention events use the new `restore = FALSE` flag to make sure their schedule can be modified when resuming. Instead of having the events re-schedule themselves everytime they fire, we setup the entire schedule upfront when initialising the simulation. It adds end-to-end testing of this feature, across a range of scenarios. For each scenario, the outcomes of the simulation with and without restoring are compared and we make sure they are equivalent.
This uses a few of individual's new features that make restoring more flexible. It also fixes a bug when restoring the mosquitto solvers, by correctly restoring the timestep, which is needed to model seasonality.
The intervention events use the new
restore = FALSE
flag to make sure their schedule can be modified when resuming. Instead of having the events re-schedule themselves everytime they fire, we setup the entire schedule upfront when initialising the simulation.It adds end-to-end testing of this feature, across a range of scenarios. For each scenario, the outcomes of the simulation with and without restoring are compared and we make sure they are equivalent.