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

mrc-4339: Add a state saver object to configure returned years #12

Merged
merged 7 commits into from
Jun 29, 2023
Merged

Conversation

r-ash
Copy link
Contributor

@r-ash r-ash commented Jun 22, 2023

This PR will enable callers to save output from more than 1 timestep. The interface I've gone for here is users setup a vector of indices they want to output e.g. 0:60 for all years. You initialise the StateSaver with this setup then that handles allocating the memory and copying output after every time step into output. I wonder if that controlling of whether to save a particular year should move into the controlling process, I think it might be a bit more obvious what it is doing if we move it there.

@codecov
Copy link

codecov bot commented Jun 22, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.30 🎉

Comparison is base (22e80e9) 98.11% compared to head (bf0a5b9) 98.41%.

❗ Current head bf0a5b9 differs from pull request most recent head 98d53b9. Consider uploading reports for the commit 98d53b9 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #12      +/-   ##
==========================================
+ Coverage   98.11%   98.41%   +0.30%     
==========================================
  Files           9       10       +1     
  Lines         688      757      +69     
==========================================
+ Hits          675      745      +70     
+ Misses         13       12       -1     
Impacted Files Coverage Δ
inst/include/types.hpp 100.00% <ø> (ø)
inst/include/frogger.hpp 100.00% <100.00%> (ø)
inst/include/state_saver.hpp 100.00% <100.00%> (ø)
src/frogger.cpp 100.00% <100.00%> (+0.75%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@r-ash r-ash marked this pull request as ready for review June 22, 2023 14:44
@r-ash r-ash requested review from richfitz and jeffeaton June 22, 2023 14:44
Tensor4<real_type> art_initiation;
Tensor3<real_type> hiv_deaths;

OutputState(int age_groups_pop,
Copy link
Member

Choose a reason for hiding this comment

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

most these values, defining the dimensions, are probably subsets of the model parameters? do you want to pass in the parameters object here, or create some sub-struct within the object so that this call signature does not grow unmanageably, and also that a state saver and its underlying model run are always compatible?

Do we imagine that all of these are always wanted?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes they are, so these are all the dimensions of our state-space. We've started thinking about splitting this out in https://github.com/mrc-ide/frogger/pull/11/files#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R51 as part of that PR I will update the names and also create some sub-struct for the parameters. If it looks ok I would wait until that PR is pinned down and use whatever struct comes from that. I'll add a TODO note here into the README

}
}

OutputState get_full_state() const {
Copy link
Member

Choose a reason for hiding this comment

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

consider returning const OututState& here

src/frogger.cpp Outdated
@@ -54,13 +54,19 @@ leapfrog::TensorMap1<int> get_age_groups_hiv_span(const Rcpp::List projection_pa
return age_groups_hiv_span;
}

std::vector<int> parse_output_steps(Rcpp::NumericVector output_steps, int proj_years) {
Copy link
Member

Choose a reason for hiding this comment

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

what is being parsed here? why is proj_years an input that is not used? should you also verify that these are (strictly) increasing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't need proj_years - good catch. I think that was just some old code left around as I originally had this interface take a time step and was then building output_steps from the time step and proj_years. By parsing here I just really mean converting from R type to C++ type. I've tried updating that name, this is now transform_output_steps and I've updated the other functions similar to this one which are also converting from R type to C++ type, possibly doing some validation on the way.

I can check they are increasing but I think this will work atm even if they aren't. If someone passed in seq(60, 0, -1) it would return with time backwards if someone really wanted. I can explicitly disallow if you think it makes interface tidier

@r-ash r-ash merged commit f8b33dd into main Jun 29, 2023
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