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

646 Use graph model with abms #1065

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f272d9c
add ABM simulation node and edge
jubicker Jun 7, 2024
1f29e1c
graph abm implementation
jubicker Jul 11, 2024
5e91137
remove warning surpression for boost
jubicker Jul 11, 2024
22a2a60
merge main
jubicker Jul 11, 2024
4368cb5
add CMakeList
jubicker Jul 12, 2024
81df1a8
CMake List Bug fix
jubicker Jul 12, 2024
5b2c64a
fix include
jubicker Jul 12, 2024
414c3f4
bug fix
jubicker Jul 12, 2024
4e2a733
test
jubicker Jul 15, 2024
8f1d7cb
test apply_mobility
jubicker Jul 15, 2024
7400802
extend apply_mobility test
jubicker Jul 16, 2024
b314715
error in abm_minimal example
jubicker Jul 16, 2024
dbbd068
test for apply mobility
jubicker Jul 17, 2024
196275f
finx clang bug
jubicker Jul 18, 2024
a5a4e88
abm minimal bug fix
jubicker Jul 18, 2024
3367fa6
Merge branch '646-use-graph-model-with-abms-v2' of https://github.com…
jubicker Jul 18, 2024
8cce390
graph_abm example
jubicker Jul 18, 2024
2fc9026
graph abm example
jubicker Jul 19, 2024
ef4c0b1
merge main
jubicker Jul 22, 2024
0ece6be
fix merge conflicts
jubicker Jul 23, 2024
b773193
fix test
jubicker Jul 23, 2024
b4d44d5
graph abm example
jubicker Jul 25, 2024
ae95301
remove unnecessary comment
jubicker Jul 25, 2024
5ebd62f
Merge branch '646-use-graph-model-with-abms-v2' of https://github.com…
jubicker Jul 25, 2024
e22009b
fix bug
jubicker Jul 25, 2024
11c3ae8
delete dbugging comments
jubicker Jul 26, 2024
1f85548
Merge branch '646-use-graph-model-with-abms-v2' of https://github.com…
jubicker Jul 26, 2024
fdad4da
benchmark inactive persons
jubicker Jul 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ if(MEMILIO_BUILD_MODELS)
add_subdirectory(models/ode_sir)
add_subdirectory(models/sde_sir)
add_subdirectory(models/sde_sirs)
add_subdirectory(models/graph_abm)
endif()

if(MEMILIO_BUILD_EXAMPLES)
Expand Down
63 changes: 63 additions & 0 deletions cpp/benchmarks/abm.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "abm/simulation.h"

#include "benchmark/benchmark.h"
#include <cstddef>

mio::abm::Simulation make_simulation(size_t num_persons, std::initializer_list<uint32_t> seeds)
{
Expand Down Expand Up @@ -144,6 +145,38 @@ void abm_benchmark(benchmark::State& state, size_t num_persons, std::initializer
}
}

void abm_inactive_persons_benchmark(benchmark::State& state, size_t num_persons, size_t num_inactive_persons,
std::initializer_list<uint32_t> seeds)
{
mio::set_log_level(mio::LogLevel::warn);
for (auto&& _ : state) {
state.PauseTiming(); //exclude the setup from the benchmark
auto sim = make_simulation(num_persons + num_inactive_persons, seeds);
//deactivate num_inactive_persons
for (size_t p_id = 0; p_id < num_inactive_persons; ++p_id) {
sim.get_world().set_activeness(mio::abm::PersonId(p_id));
}
state.ResumeTiming();

//simulated time should be long enough to have full infection runs and migration to every location
auto final_time = sim.get_time() + mio::abm::days(10);
sim.advance(final_time);

//debug output can be enabled to check for unexpected results (e.g. infections dieing out)
//normally should have no significant effect on runtime
const bool monitor_infection_activity = false;
if constexpr (monitor_infection_activity) {
std::cout << "num_persons = " << num_persons << "\n";
for (auto inf_state = 0; inf_state < (int)mio::abm::InfectionState::Count; inf_state++) {
std::cout << "inf_state = " << inf_state << ", sum = "
<< sim.get_world().get_subpopulation_combined(sim.get_time(),
mio::abm::InfectionState(inf_state))
<< "\n";
}
}
}
}

//Measure ABM simulation run time with different sizes and different seeds.
//Fixed RNG seeds to make runs comparable. When there are code changes, the simulation will still
//run differently due to different sequence of random numbers being drawn. But for large enough sizes
Expand All @@ -156,4 +189,34 @@ BENCHMARK_CAPTURE(abm_benchmark, abm_benchmark_50k, 50000, {14159265u, 35897932u
BENCHMARK_CAPTURE(abm_benchmark, abm_benchmark_100k, 100000, {38462643u, 38327950u})->Unit(benchmark::kMillisecond);
BENCHMARK_CAPTURE(abm_benchmark, abm_benchmark_200k, 200000, {28841971u, 69399375u})->Unit(benchmark::kMillisecond);

BENCHMARK_CAPTURE(abm_inactive_persons_benchmark, abm_inactive_persons_benchmark_50k, 50000, 50000,
{14159265u, 35897932u})
->Unit(benchmark::kMillisecond);
BENCHMARK_CAPTURE(abm_inactive_persons_benchmark, abm_inactive_persons_benchmark_100k, 100000, 100000,
{38462643u, 38327950u})
->Unit(benchmark::kMillisecond);
BENCHMARK_CAPTURE(abm_inactive_persons_benchmark, abm_inactive_persons_benchmark_200k, 200000, 200000,
{28841971u, 69399375u})
->Unit(benchmark::kMillisecond);

BENCHMARK_CAPTURE(abm_inactive_persons_benchmark, abm_inactive_persons_benchmark_50k_2, 50000, 100000,
{14159265u, 35897932u})
->Unit(benchmark::kMillisecond);
BENCHMARK_CAPTURE(abm_inactive_persons_benchmark, abm_inactive_persons_benchmark_100k_2, 100000, 200000,
{38462643u, 38327950u})
->Unit(benchmark::kMillisecond);
BENCHMARK_CAPTURE(abm_inactive_persons_benchmark, abm_inactive_persons_benchmark_200k_2, 200000, 400000,
{28841971u, 69399375u})
->Unit(benchmark::kMillisecond);

BENCHMARK_CAPTURE(abm_inactive_persons_benchmark, abm_inactive_persons_benchmark_50k_3, 50000, 150000,
{14159265u, 35897932u})
->Unit(benchmark::kMillisecond);
BENCHMARK_CAPTURE(abm_inactive_persons_benchmark, abm_inactive_persons_benchmark_100k_3, 100000, 300000,
{38462643u, 38327950u})
->Unit(benchmark::kMillisecond);
BENCHMARK_CAPTURE(abm_inactive_persons_benchmark, abm_inactive_persons_benchmark_200k_3, 200000, 600000,
{28841971u, 69399375u})
->Unit(benchmark::kMillisecond);

BENCHMARK_MAIN();
10 changes: 7 additions & 3 deletions cpp/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ add_executable(history_example history.cpp)
target_link_libraries(history_example PRIVATE memilio)
target_compile_options(history_example PRIVATE ${MEMILIO_CXX_FLAGS_ENABLE_WARNING_ERRORS})

add_executable(graph_abm_example graph_abm.cpp)
target_link_libraries(graph_abm_example PRIVATE memilio graph_abm abm)
target_compile_options(abm_minimal_example PRIVATE ${MEMILIO_CXX_FLAGS_ENABLE_WARNING_ERRORS})

if(MEMILIO_HAS_JSONCPP)
add_executable(ode_secir_read_graph_example ode_secir_read_graph.cpp)
target_link_libraries(ode_secir_read_graph_example PRIVATE memilio ode_secir)
Expand Down Expand Up @@ -144,7 +148,7 @@ if(MEMILIO_HAS_HDF5)
endif()

if(MEMILIO_HAS_JSONCPP)
add_executable(ide_initialization_example ide_initialization.cpp)
target_link_libraries(ide_initialization_example PRIVATE memilio ide_secir)
target_compile_options(ide_initialization_example PRIVATE ${MEMILIO_CXX_FLAGS_ENABLE_WARNING_ERRORS})
add_executable(ide_initialization_example ide_initialization.cpp)
target_link_libraries(ide_initialization_example PRIVATE memilio ide_secir)
target_compile_options(ide_initialization_example PRIVATE ${MEMILIO_CXX_FLAGS_ENABLE_WARNING_ERRORS})
endif()
6 changes: 3 additions & 3 deletions cpp/examples/abm_minimal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ int main()
world.parameters.get<mio::abm::IncubationPeriod>() = 4.;

// Set the age group the can go to school is AgeGroup(1) (i.e. 5-14)
world.parameters.get<mio::abm::AgeGroupGotoSchool>() = false;
world.parameters.get<mio::abm::AgeGroupGotoSchool>() = false;
world.parameters.get<mio::abm::AgeGroupGotoSchool>()[age_group_5_to_14] = true;
// Set the age group the can go to work is AgeGroup(2) and AgeGroup(3) (i.e. 15-34 and 35-59)
world.parameters.get<mio::abm::AgeGroupGotoWork>().set_multiple({age_group_15_to_34, age_group_35_to_59}, true);
Expand All @@ -55,7 +55,7 @@ int main()
// For more than 1 family households we need families. These are parents and children and randoms (which are distributed like the data we have for these households).
auto child = mio::abm::HouseholdMember(num_age_groups); // A child is 50/50% 0-4 or 5-14.
child.set_age_weight(age_group_0_to_4, 1);
child.set_age_weight(age_group_0_to_4, 1);
child.set_age_weight(age_group_5_to_14, 1);

auto parent = mio::abm::HouseholdMember(num_age_groups); // A parent is 50/50% 15-34 or 35-59.
parent.set_age_weight(age_group_15_to_34, 1);
Expand Down Expand Up @@ -138,7 +138,7 @@ int main()
world.assign_location(id, hospital);
world.assign_location(id, icu);
//assign work/school to people depending on their age
if (person.get_age() == age_group_0_to_4) {
if (person.get_age() == age_group_5_to_14) {
world.assign_location(id, school);
}
if (person.get_age() == age_group_15_to_34 || person.get_age() == age_group_35_to_59) {
Expand Down
Loading