Skip to content
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

Add initial checkpoint and restore functionality. #178

Merged
merged 7 commits into from
Jan 11, 2024
Merged

Add initial checkpoint and restore functionality. #178

merged 7 commits into from
Jan 11, 2024

Conversation

plietar
Copy link
Member

@plietar plietar commented Jan 8, 2024

This allows a user to run a simulation for a number of time steps and save the state of the simulation. The state can then be restored to continue the simulation.

This is,for example, useful to compare the impact of an intervention based on different parameters. The simulation can be run up to the point of an intervention, when the parameters' value don't matter. The simulation can then be resumed multiple times but with different intervention parameters each time.

For now, only variables are supported. Events will be added next.

Copy link

codecov bot commented Jan 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (3800945) 96.28% compared to head (a329052) 96.37%.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #178      +/-   ##
==========================================
+ Coverage   96.28%   96.37%   +0.08%     
==========================================
  Files          36       36              
  Lines        1722     1764      +42     
==========================================
+ Hits         1658     1700      +42     
  Misses         64       64              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@plietar
Copy link
Member Author

plietar commented Jan 8, 2024

I still need to add some unit tests to make sure the checkpoint/restore works correctly DONE, but I'm interested in getting some feedback in the meantime.

The long term goal is to support mrc-ide/malariasimulation#196. There's obviously still a long way to go for this, especially since malariasimulation maintains quite a lot of state that isn't visible to individual, but this is the first step in that direction.

This allows a user to run a simulation for a number of time steps and
save the state of the simulation. The state can then be restored to
continue the simulation.

This is,for example, useful to compare the impact of an intervention
based on different parameters. The simulation can be run up to the point
of an intervention, when the parameters' value don't matter. The
simulation can then be resumed multiple times but with different
intervention parameters each time.

For now, only variables are supported. Events will be added next.
@plietar plietar requested a review from giovannic January 9, 2024 13:51
@giovannic giovannic changed the base branch from master to dev January 10, 2024 09:45
Copy link
Member

@giovannic giovannic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very minor suggestions, I love the way this is done.

I'm curious about whether users would want to restore_state themselves, instead of simulation_loop doing it for them. That way users can do their own (re-)initialisations based on the restored variables. e.g. in malariasimulation, they may want to calculate an FOIM based on restored variables so that they can initialise their differential equation solver.

I'm sure those issues could be worked around by saving more state. My guess is that saving more state would be the most concise approach. But it's something to bear in mind.

Thanks so much!

R/simulation.R Outdated Show resolved Hide resolved
tests/testthat/test-raggeddouble.R Outdated Show resolved Hide resolved
tests/testthat/test-raggeddouble.R Outdated Show resolved Hide resolved
@plietar
Copy link
Member Author

plietar commented Jan 11, 2024

Thanks for the review, I've applied the suggestions.

I think it would be much simpler to have malariasimulation save and restore its state buffers than re-creating them from the Variables (I'm not sure that would even be possible). It should be able to do that before/after calling simulation_loop, and let simulation_loop call restore_state to save the events and variables.

Another option would be to add an argument to simulation_loop for custom checkpoint-able objects, and have restore_state call checkpoint/restore on these automatically. Then the caller only has to define a pair of methods on each object but not worry about calling them.

Copy link
Member

@giovannic giovannic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me, the former option seems like a good place to start. Looking forward to it!

@plietar plietar merged commit d823c90 into dev Jan 11, 2024
7 checks passed
@giovannic giovannic deleted the checkpoint1 branch January 12, 2024 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants