Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
087e0cc
Refactor ABM code: Rename EPI to MIO and mobility to movement
xsaschako Dec 21, 2023
580841b
Update migration to movement in code
xsaschako Dec 21, 2023
c579317
also fix in python
xsaschako Dec 21, 2023
9090124
fix
xsaschako Dec 21, 2023
fd98c2e
more changes
xsaschako Dec 21, 2023
30019d3
quick fix
xsaschako Dec 21, 2023
1442e4a
quicker fix
xsaschako Dec 21, 2023
f7cbcd1
Merge with main and rename all migration and abm::World appearances
DavidKerkmann Jul 3, 2024
7e9d1f9
Fix format and one missing replace
DavidKerkmann Jul 3, 2024
255fa01
Fix duplication of one test
DavidKerkmann Jul 4, 2024
92d021b
Merge with main and resolve merge conflicts
DavidKerkmann Jul 20, 2024
680f50a
Changes according to last agreements
DavidKerkmann Jul 20, 2024
7cf55fc
Fix some errors from previous commit
DavidKerkmann Jul 20, 2024
e8ac726
More fixes
DavidKerkmann Jul 20, 2024
1edeca5
more fixes
DavidKerkmann Jul 20, 2024
30670f2
Further changes to naming
DavidKerkmann Jul 25, 2024
241d530
Merge branch 'main' into 842-change-wording-replace-abm-migration-by-…
DavidKerkmann Jul 25, 2024
89ae7a9
More changes
DavidKerkmann Jul 25, 2024
af22c6b
quick fix for one name
DavidKerkmann Jul 25, 2024
f1da846
Apply suggestions from code review
DavidKerkmann Jul 26, 2024
bcfa3b3
Apply more suggestions from code review
DavidKerkmann Jul 26, 2024
9bc8cf3
Apply more requested changes
DavidKerkmann Jul 26, 2024
8ec0430
Merge branch '842-change-wording-replace-abm-migration-by-mobility' o…
DavidKerkmann Jul 26, 2024
6177397
one quick fix
DavidKerkmann Jul 26, 2024
e640733
changes according to review
DavidKerkmann Jul 30, 2024
cb5b3ea
one more fix from review
DavidKerkmann Jul 30, 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
54 changes: 27 additions & 27 deletions cpp/benchmarks/abm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,27 @@ mio::abm::Simulation make_simulation(size_t num_persons, std::initializer_list<u
{
auto rng = mio::RandomNumberGenerator();
rng.seed(seeds);
auto world = mio::abm::World(5);
world.get_rng() = rng;
auto model = mio::abm::Model(5);
model.get_rng() = rng;

//create persons at home
const auto mean_home_size = 5.0;
const auto min_home_size = 1;
auto& home_size_distribution = mio::PoissonDistribution<int>::get_instance();
auto home = world.add_location(mio::abm::LocationType::Home);
auto planned_home_size = home_size_distribution(world.get_rng(), mean_home_size);
auto home = model.add_location(mio::abm::LocationType::Home);
auto planned_home_size = home_size_distribution(model.get_rng(), mean_home_size);
auto home_size = 0;
for (size_t i = 0; i < num_persons; ++i) {
if (home_size >= std::max(min_home_size, planned_home_size)) {
home = world.add_location(mio::abm::LocationType::Home);
planned_home_size = home_size_distribution(world.get_rng(), mean_home_size);
home = model.add_location(mio::abm::LocationType::Home);
planned_home_size = home_size_distribution(model.get_rng(), mean_home_size);
home_size = 0;
}

auto age = mio::AgeGroup(mio::UniformIntDistribution<size_t>::get_instance()(
world.get_rng(), size_t(0), world.parameters.get_num_groups() - 1));
auto person = world.add_person(home, age);
world.assign_location(person, home);
model.get_rng(), size_t(0), model.parameters.get_num_groups() - 1));
auto person = model.add_person(home, age);
model.assign_location(person, home);
home_size++;
}

Expand All @@ -38,25 +38,25 @@ mio::abm::Simulation make_simulation(size_t num_persons, std::initializer_list<u
const auto num_locs = std::max(size_t(1), num_persons / 2'000);
std::vector<mio::abm::LocationId> locs(num_locs);
std::generate(locs.begin(), locs.end(), [&] {
return world.add_location(loc_type);
return model.add_location(loc_type);
});
for (auto& person : world.get_persons()) {
for (auto& person : model.get_persons()) {
auto loc_idx =
mio::UniformIntDistribution<size_t>::get_instance()(world.get_rng(), size_t(0), num_locs - 1);
world.assign_location(person.get_id(), locs[loc_idx]);
mio::UniformIntDistribution<size_t>::get_instance()(model.get_rng(), size_t(0), num_locs - 1);
model.assign_location(person.get_id(), locs[loc_idx]);
}
}

//infections and masks
for (auto& person : world.get_persons()) {
auto prng = mio::abm::PersonalRandomNumberGenerator(world.get_rng(), person);
for (auto& person : model.get_persons()) {
auto prng = mio::abm::PersonalRandomNumberGenerator(model.get_rng(), person);
//some % of people are infected, large enough to have some infection activity without everyone dying
auto pct_infected = 0.05;
if (mio::UniformDistribution<double>::get_instance()(prng, 0.0, 1.0) < pct_infected) {
auto state = mio::abm::InfectionState(
mio::UniformIntDistribution<int>::get_instance()(prng, 1, int(mio::abm::InfectionState::Count) - 1));
auto infection = mio::abm::Infection(prng, mio::abm::VirusVariant::Wildtype, person.get_age(),
world.parameters, mio::abm::TimePoint(0), state);
model.parameters, mio::abm::TimePoint(0), state);
person.add_new_infection(std::move(infection));
}

Expand All @@ -67,22 +67,22 @@ mio::abm::Simulation make_simulation(size_t num_persons, std::initializer_list<u
}

//masks at locations
for (auto& loc : world.get_locations()) {
for (auto& loc : model.get_locations()) {
//some % of locations require masks
//skip homes so persons always have a place to go, simulation might break otherwise
auto pct_require_mask = 0.2;
auto requires_mask = loc.get_type() != mio::abm::LocationType::Home &&
mio::UniformDistribution<double>::get_instance()(world.get_rng()) < pct_require_mask;
mio::UniformDistribution<double>::get_instance()(model.get_rng()) < pct_require_mask;
loc.set_npi_active(requires_mask);
}

//testing schemes
auto sample = [&](auto v, size_t n) { //selects n elements from list v
std::shuffle(v.begin(), v.end(), world.get_rng());
std::shuffle(v.begin(), v.end(), model.get_rng());
return std::vector<typename decltype(v)::value_type>(v.begin(), v.begin() + n);
};
std::vector<mio::AgeGroup> ages;
std::generate_n(std::back_inserter(ages), world.parameters.get_num_groups(), [a = 0]() mutable {
std::generate_n(std::back_inserter(ages), model.parameters.get_num_groups(), [a = 0]() mutable {
return mio::AgeGroup(a++);
});
auto random_criteria = [&]() {
Expand All @@ -91,24 +91,24 @@ mio::abm::Simulation make_simulation(size_t num_persons, std::initializer_list<u
return mio::abm::TestingCriteria(random_ages, random_states);
};

world.get_testing_strategy().add_testing_scheme(
model.get_testing_strategy().add_testing_scheme(
mio::abm::LocationType::School,
mio::abm::TestingScheme(random_criteria(), mio::abm::days(3), mio::abm::TimePoint(0),
mio::abm::TimePoint(0) + mio::abm::days(10), {}, 0.5));
world.get_testing_strategy().add_testing_scheme(
model.get_testing_strategy().add_testing_scheme(
mio::abm::LocationType::Work,
mio::abm::TestingScheme(random_criteria(), mio::abm::days(3), mio::abm::TimePoint(0),
mio::abm::TimePoint(0) + mio::abm::days(10), {}, 0.5));
world.get_testing_strategy().add_testing_scheme(
model.get_testing_strategy().add_testing_scheme(
mio::abm::LocationType::Home,
mio::abm::TestingScheme(random_criteria(), mio::abm::days(3), mio::abm::TimePoint(0),
mio::abm::TimePoint(0) + mio::abm::days(10), {}, 0.5));
world.get_testing_strategy().add_testing_scheme(
model.get_testing_strategy().add_testing_scheme(
mio::abm::LocationType::SocialEvent,
mio::abm::TestingScheme(random_criteria(), mio::abm::days(3), mio::abm::TimePoint(0),
mio::abm::TimePoint(0) + mio::abm::days(10), {}, 0.5));

return mio::abm::Simulation(mio::abm::TimePoint(0), std::move(world));
return mio::abm::Simulation(mio::abm::TimePoint(0), std::move(model));
}

/**
Expand All @@ -125,7 +125,7 @@ void abm_benchmark(benchmark::State& state, size_t num_persons, std::initializer
auto sim = make_simulation(num_persons, seeds);
state.ResumeTiming();

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

Expand All @@ -136,7 +136,7 @@ void abm_benchmark(benchmark::State& state, size_t num_persons, std::initializer
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(),
<< sim.get_model().get_subpopulation_combined(sim.get_time(),
mio::abm::InfectionState(inf_state))
<< "\n";
}
Expand Down
4 changes: 2 additions & 2 deletions cpp/benchmarks/graph_simulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ auto create_simulation()
mio::osecirvvs::Model model = create_model(cfg.num_agegroups, cfg.t_max);

mio::Graph<mio::SimulationNode<mio::Simulation<ScalarType, mio::osecirvvs::Model<ScalarType>>>,
mio::MigrationEdge<ScalarType>>
mio::MobilityEdge<ScalarType>>
g;
for (size_t county_id = 0; county_id < cfg.num_regions; county_id++) {
g.add_node(county_id, model, cfg.t0);
Expand All @@ -136,7 +136,7 @@ auto create_simulation()
}
}

return mio::make_migration_sim(cfg.t0, cfg.dt, std::move(g));
return mio::make_mobility_sim(cfg.t0, cfg.dt, std::move(g));
}

template <class Integrator>
Expand Down
38 changes: 19 additions & 19 deletions cpp/benchmarks/profiling.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ As you can see, the profile contains a lot of functions that are not of interest

USR 39,240 1,635 0.00 0.0 0.28 Json::ValueType?Json::Value::type()?const
...
COM 4,032 168 0.00 0.0 0.63 void?mio::abm::Simulation::evolve_world(mio::abm::TimePoint)
COM 4,032 168 0.00 0.0 2.30 void?mio::abm::World::evolve(mio::abm::TimePoint,?mio::abm::TimeSpan)
COM 4,032 168 0.00 0.0 6.92 void?mio::abm::World::begin_step(mio::abm::TimePoint,?mio::abm::TimeSpan)
COM 4,032 168 0.00 0.0 5.40 void?mio::abm::World::interaction(mio::abm::TimePoint,?mio::abm::TimeSpan)
COM 4,032 168 0.00 0.0 5.10 void?mio::abm::World::migration(mio::abm::TimePoint,?mio::abm::TimeSpan)
COM 4,032 168 0.00 0.0 0.63 void?mio::abm::Simulation::evolve_model(mio::abm::TimePoint)
COM 4,032 168 0.00 0.0 2.30 void?mio::abm::Model::evolve(mio::abm::TimePoint,?mio::abm::TimeSpan)
COM 4,032 168 0.00 0.0 6.92 void?mio::abm::Model::begin_step(mio::abm::TimePoint,?mio::abm::TimeSpan)
COM 4,032 168 0.00 0.0 5.40 void?mio::abm::Model::interaction(mio::abm::TimePoint,?mio::abm::TimeSpan)
COM 4,032 168 0.00 0.0 5.10 void?mio::abm::Model::perform_mobility(mio::abm::TimePoint,?mio::abm::TimeSpan)

The output is much shorter and most functions are filtered.
If the estimated memory requirements exceed 4 GB you need to remove the responsible function from the included functions in the filter. If you added more than one function to the filter, you can check which function is responsible for the increase of required space with the output of ```scorep-score```. The functions at the top of the table are most likely to be responsible. With ```scorep-score -f filter -r scorep-folder/profile.cubex``` you can see the effect of the adjusted filter on the profile without running the experiment.
Expand All @@ -125,22 +125,22 @@ However, there are some functions that still appear in the profile that do not a
COM 20,184 841 0.00 0.0 4.98 COM
SCOREP 41 1 57.83 89.3 57830258.74 SCOREP

OMP 14,280 168 0.00 0.0 0.52 ?$omp?parallel?@world.cpp:68
OMP 14,280 168 0.00 0.0 0.51 ?$omp?parallel?@world.cpp:78
OMP 14,280 168 0.00 0.0 0.56 ?$omp?parallel?@world.cpp:152
OMP 14,280 168 0.00 0.0 0.52 ?$omp?parallel?@model.cpp:68
OMP 14,280 168 0.00 0.0 0.51 ?$omp?parallel?@model.cpp:78
OMP 14,280 168 0.00 0.0 0.56 ?$omp?parallel?@model.cpp:152
OMP 4,056 169 1.78 2.8 10549.08 ?$omp?for?@common_abm_loggers.h:175
OMP 4,056 169 0.00 0.0 1.30 ?$omp?implicit?barrier?@common_abm_loggers.h:180
OMP 4,032 168 1.54 2.4 9152.87 ?$omp?for?@world.cpp:68
OMP 4,032 168 0.00 0.0 2.76 ?$omp?implicit?barrier?@world.cpp:73
OMP 4,032 168 1.61 2.5 9571.18 ?$omp?for?@world.cpp:78
OMP 4,032 168 0.00 0.0 2.75 ?$omp?implicit?barrier?@world.cpp:122
OMP 4,032 168 2.02 3.1 12038.27 ?$omp?for?@world.cpp:152
OMP 4,032 168 0.00 0.0 2.89 ?$omp?implicit?barrier?@world.cpp:156
COM 4,032 168 0.00 0.0 0.70 void?mio::abm::Simulation::evolve_world(mio::abm::TimePoint)
COM 4,032 168 0.00 0.0 2.66 void?mio::abm::World::evolve(mio::abm::TimePoint,?mio::abm::TimeSpan)
COM 4,032 168 0.00 0.0 7.73 void?mio::abm::World::begin_step(mio::abm::TimePoint,?mio::abm::TimeSpan)
COM 4,032 168 0.00 0.0 5.49 void?mio::abm::World::interaction(mio::abm::TimePoint,?mio::abm::TimeSpan)
COM 4,032 168 0.00 0.0 5.17 void?mio::abm::World::migration(mio::abm::TimePoint,?mio::abm::TimeSpan)
OMP 4,032 168 1.54 2.4 9152.87 ?$omp?for?@model.cpp:68
OMP 4,032 168 0.00 0.0 2.76 ?$omp?implicit?barrier?@model.cpp:73
OMP 4,032 168 1.61 2.5 9571.18 ?$omp?for?@model.cpp:78
OMP 4,032 168 0.00 0.0 2.75 ?$omp?implicit?barrier?@model.cpp:122
OMP 4,032 168 2.02 3.1 12038.27 ?$omp?for?@model.cpp:152
OMP 4,032 168 0.00 0.0 2.89 ?$omp?implicit?barrier?@model.cpp:156
COM 4,032 168 0.00 0.0 0.70 void?mio::abm::Simulation::evolve_model(mio::abm::TimePoint)
COM 4,032 168 0.00 0.0 2.66 void?mio::abm::Model::evolve(mio::abm::TimePoint,?mio::abm::TimeSpan)
COM 4,032 168 0.00 0.0 7.73 void?mio::abm::Model::begin_step(mio::abm::TimePoint,?mio::abm::TimeSpan)
COM 4,032 168 0.00 0.0 5.49 void?mio::abm::Model::interaction(mio::abm::TimePoint,?mio::abm::TimeSpan)
COM 4,032 168 0.00 0.0 5.17 void?mio::abm::Model::perform_mobility(mio::abm::TimePoint,?mio::abm::TimeSpan)
SCOREP 41 1 57.83 89.3 57830258.74 abm_simulation
COM 24 1 0.00 0.0 532.58 void?mio::abm::Simulation::advance(mio::abm::TimePoint,?History&?...)??with?History?=?{mio::History<mio::abm::TimeSeriesWriter,?mio::abm::LogInfectionState>}?

Expand Down
6 changes: 3 additions & 3 deletions cpp/benchmarks/scorep-filter-abm
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ SCOREP_FILE_NAMES_END

SCOREP_REGION_NAMES_BEGIN
EXCLUDE *
INCLUDE *World::begin_step* *World::interaction* *World::migration*
INCLUDE *World::evolve*
INCLUDE *Simulation::evolve_world*
INCLUDE *Model::begin_step* *Model::interaction* *Model::perform_mobility*
INCLUDE *Model::evolve*
INCLUDE *Simulation::evolve_model*
INCLUDE *Simulation::advance*
SCOREP_REGION_NAMES_END
9 changes: 6 additions & 3 deletions cpp/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,12 @@ add_executable(abm_history_example abm_history_object.cpp)
target_link_libraries(abm_history_example PRIVATE memilio abm)
target_compile_options(abm_history_example PRIVATE ${MEMILIO_CXX_FLAGS_ENABLE_WARNING_ERRORS})

add_executable(twitter_migration_example twitter_migration.cpp)
target_link_libraries(twitter_migration_example PRIVATE memilio ode_secir)
target_compile_options(twitter_migration_example PRIVATE ${MEMILIO_CXX_FLAGS_ENABLE_WARNING_ERRORS})
add_executable(twitter_mobility_example twitter_mobility.cpp)

target_link_libraries(twitter_mobility_example PRIVATE memilio ode_secir)

target_compile_options(twitter_mobility_example PRIVATE ${MEMILIO_CXX_FLAGS_ENABLE_WARNING_ERRORS})


add_executable(ide_seir_example ide_seir.cpp)
target_link_libraries(ide_seir_example PRIVATE memilio ide_seir)
Expand Down
Loading