Repository navigation
Conversation
…rove function structure, and add new plotting capabilities for location types.
… documentation, and improve function argument handling for better usability
…st cases for loading H5 results and plotting functions
…ments for clarity
…th comparison plots
…arguments for better flexibility
…from-paper-to-memilio-plot
…into 1210-abm-paper-logger
There was a problem hiding this comment.
Pull request overview
This PR adds a new ABM (Agent-Based Model) logger for tracking new infections per location type per age group (LogInfectionPerLocationTypePerAgeGroup), integrates it into ResultSimulation via a new history_detailed history and get_result_detailed() method, updates the abm_parameter_study.cpp example to save both standard and detailed results, and introduces a new Python plotting module (plotAbmInfectionStates.py) with tests for visualizing the results.
Changes:
- Added
LogInfectionPerLocationTypePerAgeGroup(and unusedLogInfectionStatePerAgeGroup) logger structs incommon_abm_loggers.h - Added
m_t_prevtracking toSimulationclass and integrated the new detailed logger intoResultSimulation - Updated
abm_parameter_study.cppexample to collect and save both aggregated and detailed results in separate subdirectories - Added new Python plotting module
plotAbmInfectionStates.pywith functions to visualize infection states and infection-by-location-type data, plus unit tests
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 16 comments.
Show a summary per file
| File | Description |
|---|---|
cpp/models/abm/simulation.h |
Adds m_t_prev member and get_prev_time() to track previous simulation time step, needed by new logger |
cpp/models/abm/common_abm_loggers.h |
Introduces two new logger structs for per-age-group data; one is unused |
cpp/models/abm/result_simulation.h |
Adds history_detailed and get_result_detailed() using the new logger; changes get_result() return type |
cpp/examples/abm_parameter_study.cpp |
Updated example to run 10 simulations over 10 days and save both standard and detailed results |
pycode/memilio-plot/memilio/plot/plotAbmInfectionStates.py |
New Python module for loading and plotting ABM infection state and location-type results |
pycode/memilio-plot/tests/test_plot_plotAbmInfectionStates.py |
Unit tests for the new Python plotting module |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1507 +/- ##
==========================================
- Coverage 97.48% 97.47% -0.01%
==========================================
Files 190 190
Lines 16035 16058 +23
==========================================
+ Hits 15632 15653 +21
- Misses 403 405 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
DavidKerkmann
left a comment
There was a problem hiding this comment.
Thanks, I have a few comments which should be discussed/resolved.
Furthermore, I think fixing #1406 here would make a lot of sense.
| mio::History<TimeSeriesWriter, LogInfectionState> history{ | ||
| Eigen::Index(InfectionState::Count)}; ///< History used to create the result TimeSeries. | ||
|
|
||
| mio::History<TimeSeriesWriter, LogInfectionPerLocationTypePerAgeGroup> history_detailed{ | ||
| Eigen::Index(LocationType::Count) * | ||
| this->get_model().parameters.get_num_groups()}; ///< History used to create the detailed result TimeSeries. |
There was a problem hiding this comment.
I find it a bit unclean that we have a hardcoded result_simulation which is tailored to the one example (parameter study) with these particular loggers/histories.
It would be better to have a framework that allows us to do the parameter studies in a way where the make_model and the history(-ies) is/are provided instead.
There was a problem hiding this comment.
Agreed. I reverted ResultSimulation to main and moved the study-specific histories into a small StudySimulation wrapper in the example.
There was a problem hiding this comment.
I think this might be the way to go. We could consider moving the result_simulation to the example as well. I would like to discuss this with @reneSchm (perhaps tomorrow).
…on logger - Revert ResultSimulation and Simulation to main; the parameter study example now uses a small StudySimulation wrapper holding its histories. - LogInfectionPerLocationTypePerAgeGroup keeps its previous log time and location types itself and attributes new infections to the location where the interaction happened, not to where the person moved afterwards. - Gather the detailed results across MPI ranks by returning them from the processing lambda. - Handle the IOResult of save_result instead of discarding it. - LogInfectionState counts in a single pass over all persons (#1406).
| mio::History<TimeSeriesWriter, LogInfectionState> history{ | ||
| Eigen::Index(InfectionState::Count)}; ///< History used to create the result TimeSeries. | ||
|
|
||
| mio::History<TimeSeriesWriter, LogInfectionPerLocationTypePerAgeGroup> history_detailed{ | ||
| Eigen::Index(LocationType::Count) * | ||
| this->get_model().parameters.get_num_groups()}; ///< History used to create the detailed result TimeSeries. |
There was a problem hiding this comment.
Agreed. I reverted ResultSimulation to main and moved the study-specific histories into a small StudySimulation wrapper in the example.
DavidKerkmann
left a comment
There was a problem hiding this comment.
Thank you for the quick changes!
I think we should discuss a few things regarding the logger, otherwise it looks good!
- LogInfectionPerLocationTypePerAgeGroup remembers the InfectionState, LocationType and PersonId of each Person at the previous log, instead of the previous time. This removes the dependence on a start time of 0. - Persons without a previous log, at the first log or added since the previous log, are not counted but tracked from then on. An entry is only used if it belongs to the same PersonId. - Test a Simulation not starting at 0 and a Person added during the Simulation.
Changes and Information
Please briefly list the changes (main added features, changed items, or corrected bugs) made:
If need be, add additional information and what the reviewer should look out for in particular:
Merge Request - Guideline Checklist
Please check our git workflow. Use the draft feature if the Pull Request is not yet ready to review.
Checks by code author
Checks by code reviewer(s)