-
Notifications
You must be signed in to change notification settings - Fork 23
1522 Improve DynamicNPI structure through harmonization across models and more options #1523
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
Open
mknaranja
wants to merge
20
commits into
main
Choose a base branch
from
1522-improve-dynamicnpis-structure
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
a88648f
[ci skip] interval removed (partially), new options started
mknaranja b9f7192
[ci skip] Continuation, examples, python + minimal tests
mknaranja da73e77
replace directive_end and delay parameter from model through NPI
mknaranja 4d6970b
resolve compilation errors
mknaranja b1d2816
Fixed dynamicNPI tests
mknaranja 7b3e4d9
tests for directive begin and end in secir
mknaranja a23f791
order dynamicNPIs and advance changed
mknaranja d78d25a
Some documentation + assert in setters in dynamic_npis.h
HenrZu 6327b88
[ci skip] some doc fixes in metapop instant
HenrZu 0ac1fff
base advance if no dynamic npis used, secirts test for dynamic npis
HenrZu b919146
new h5 file for secirvvs stability test
HenrZu 44980e8
Merge branch 'main' into 1522-improve-dynamicnpis-structure
HenrZu 6fa50e9
benchmark to quantify overhead of specific to generic advance
HenrZu 86136fd
adapt dynamic npi structure in benchmark
HenrZu 7e8e4e1
missing test for secirvvs
HenrZu b05d080
update python test, rm t_next_damp comment
HenrZu 7f36b26
+1 time offset for dynamic npis
HenrZu 470a7e7
backward consistency test
HenrZu 67e70b9
add is_expiry_renewal to avoid dips if dynamic npis is extended
HenrZu f6b5751
updated testdata
HenrZu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| /* | ||
| * Copyright (C) 2020-2026 MEmilio | ||
| * | ||
| * Authors: Henrik Zunker | ||
| * | ||
| * Contact: Martin J. Kuehn <[email protected]> | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| /** | ||
| * Benchmark comparing the overhead of the model-specific osecirvvs::Simulation::advance() | ||
| * (which uses substeps and calls apply_vaccination / apply_variant / dynamic NPI checks) | ||
| * versus the generic mio::Simulation::advance() (a single integrator call for the entire range). | ||
| */ | ||
|
|
||
| #include "ode_secirvvs/model.h" | ||
| #include "memilio/compartments/simulation.h" | ||
| #include "memilio/utils/logging.h" | ||
| #include "benchmark/benchmark.h" | ||
|
|
||
| using FP = double; | ||
| using Model = mio::osecirvvs::Model<FP>; | ||
|
|
||
| static Model make_model(bool with_npis = false) | ||
| { | ||
| constexpr int tmax = 10; | ||
| Model model(1); | ||
| model.populations[{mio::AgeGroup(0), mio::osecirvvs::InfectionState::InfectedSymptomsNaive}] = 100.0; | ||
| model.populations.set_difference_from_total({mio::AgeGroup(0), mio::osecirvvs::InfectionState::SusceptibleNaive}, | ||
| 10000.0); | ||
| model.parameters.get<mio::osecirvvs::DailyPartialVaccinations<FP>>().resize(mio::SimulationDay(size_t(tmax + 1))); | ||
| model.parameters.get<mio::osecirvvs::DailyFullVaccinations<FP>>().resize(mio::SimulationDay(size_t(tmax + 1))); | ||
| if (with_npis) { | ||
| auto& npis = model.parameters.get<mio::osecirvvs::DynamicNPIsInfectedSymptoms<FP>>(); | ||
| npis.set_threshold(0.01 * 100'000, {mio::DampingSampling<FP>{1.0, | ||
| mio::DampingLevel(0), | ||
| mio::DampingType(0), | ||
| mio::SimulationTime<FP>(0), | ||
| {0}, | ||
| Eigen::VectorXd::Ones(1)}}); | ||
| npis.set_duration(mio::SimulationTime<FP>(14.0)); | ||
| npis.set_base_value(100'000); | ||
| } | ||
| return model; | ||
| } | ||
|
|
||
| // Generic advance: single integrator call for the full [t0, tmax] range. | ||
| static void BM_generic(benchmark::State& state) | ||
| { | ||
| mio::set_log_level(mio::LogLevel::off); | ||
| auto model = make_model(); | ||
| for (auto _ : state) { | ||
| mio::simulate<FP, Model>(0., 10., 0.1, model); | ||
| } | ||
| } | ||
|
|
||
| // Model-specific advance without dynamic NPIs: 1-day loop with apply_vaccination + apply_variant, | ||
| // dynamic NPI threshold check is skipped (thresholds empty). | ||
| static void BM_secirvvs_no_npis(benchmark::State& state) | ||
| { | ||
| mio::set_log_level(mio::LogLevel::off); | ||
| auto model = make_model(/*with_npis=*/false); | ||
| for (auto _ : state) { | ||
| mio::osecirvvs::simulate<FP>(0., 10., 0.1, model); | ||
| } | ||
| } | ||
|
|
||
| // Model-specific advance with dynamic NPIs: same as above plus get_infections_relative + | ||
| // threshold comparison on every day step. | ||
| static void BM_secirvvs_with_npis(benchmark::State& state) | ||
| { | ||
| mio::set_log_level(mio::LogLevel::off); | ||
| auto model = make_model(/*with_npis=*/true); | ||
| for (auto _ : state) { | ||
| mio::osecirvvs::simulate<FP>(0., 10., 0.1, model); | ||
| } | ||
| } | ||
|
|
||
| BENCHMARK(BM_generic)->Name("SECIRVVS generic advance"); | ||
| BENCHMARK(BM_secirvvs_no_npis)->Name("SECIRVVS model-specific advance (no dynamic NPIs)"); | ||
| BENCHMARK(BM_secirvvs_with_npis)->Name("SECIRVVS model-specific advance (with dynamic NPIs)"); | ||
| BENCHMARK_MAIN(); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
why is this a single integrator call? Not sure to understand it...
If there is an adaptive scheme behind, it makes different numbers of steps if the contact rate changes --> this already leads to different timings.
A fixed-time-step scheme would be better suited I think.