Skip to content

Commit

Permalink
511 Compute inflow and outflow of models (#574)
Browse files Browse the repository at this point in the history
Co-authored-by: reneSchm <49305466+reneSchm@users.noreply.github.com>
Co-authored-by: Martin J. Kühn <62713180+mknaranja@users.noreply.github.com>
Co-authored-by: dabele <daniel.abele@dlr.de>

- Compute and Integrate Flows between the Compartments of the ODE model
  - Backwards compatibility with old design (see FlowModel::get_derivatives)
- New FlowModel extending the existing Compartmentalmodel
  - New FlowSimulation extending current Simulation which also calculates flows
  - Converted all ODE models (except ode_sir) to use the FlowModel/FlowSimulation
- Adding Plot table feature for the time series
- Some Performance/Design gains for the Integrator/Simulation
- Removed TotalInfections compartment. This can now easily be computed using the flows
- Added a TypeList with metaprogramming utilities:
  - type_at_index
  - index_of_type
  - is_type_in_list
- Added function extend_index and reduce_index
- And some benchmarks ... :)
  • Loading branch information
HenrZu authored Nov 14, 2023
1 parent e24b555 commit e664729
Show file tree
Hide file tree
Showing 46 changed files with 4,123 additions and 553 deletions.
13 changes: 9 additions & 4 deletions cpp/benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,16 @@ endif()

set_target_properties(benchmark PROPERTIES FOLDER "Extern")

add_executable(simulation_benchmark simulation.cpp)
target_link_libraries(simulation_benchmark PRIVATE memilio ode_secir benchmark::benchmark)

add_executable(integrator_step_benchmark integrator_step.cpp)
target_link_libraries(integrator_step_benchmark PRIVATE memilio ode_secir benchmark::benchmark)

add_executable(flow_simulation_ode_secirvvs_benchmark flow_simulation_ode_secirvvs.cpp)
target_link_libraries(flow_simulation_ode_secirvvs_benchmark PRIVATE memilio ode_secirvvs benchmark::benchmark)

add_executable(flow_simulation_ode_seir_benchmark flow_simulation_ode_seir.cpp)
target_link_libraries(flow_simulation_ode_seir_benchmark PRIVATE memilio ode_seir benchmark::benchmark)

add_executable(simulation_benchmark simulation.cpp)
target_link_libraries(simulation_benchmark PRIVATE memilio ode_secir benchmark::benchmark)
add_executable(graph_simulation_benchmark graph_simulation.cpp)
target_link_libraries(graph_simulation_benchmark PRIVATE memilio ode_secirvvs benchmark::benchmark)
target_link_libraries(graph_simulation_benchmark PRIVATE memilio ode_secirvvs benchmark::benchmark)
116 changes: 116 additions & 0 deletions cpp/benchmarks/flow_simulation_ode_secirvvs.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
* Copyright (C) 2020-2023 German Aerospace Center (DLR-SC)
*
* Authors: Rene Schmieding, Daniel Abele, Martin J. Kuehn
*
* Contact: Martin J. Kuehn <Martin.Kuehn@DLR.de>
*
* 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.
*/
#include "benchmarks/simulation.h"
#include "benchmarks/flow_simulation_ode_secirvvs.h"
#include "memilio/compartments/flow_simulation.h"
#include "memilio/compartments/simulation.h"
#include "ode_secirvvs/model.h"
#include <string>

const std::string config_path = "../../benchmarks/simulation.config";

// simulation without flows (not in Model definition and not calculated by Simulation)
void flowless_sim(::benchmark::State& state)
{
using Model = mio::benchmark::FlowlessModel;
// suppress non-critical messages
mio::set_log_level(mio::LogLevel::critical);
// load config
auto cfg = mio::benchmark::SimulationConfig::initialize(config_path);
// create model
Model model(cfg.num_agegroups);
mio::benchmark::setup_model(model);
// create simulation
std::shared_ptr<mio::IntegratorCore> I =
std::make_shared<mio::ControlledStepperWrapper<boost::numeric::odeint::runge_kutta_cash_karp54>>(
cfg.abs_tol, cfg.rel_tol, cfg.dt_min, cfg.dt_max);
// run benchmark
for (auto _ : state) {
// This code gets timed
mio::benchmark::Simulation<mio::Simulation<Model>> sim(model, cfg.t0, cfg.dt);
sim.set_integrator(I);
// run sim
sim.advance(cfg.t_max);
}
}

// simulation with flows (in Model definition, but NOT calculated by Simulation)
void flow_sim_comp_only(::benchmark::State& state)
{
using Model = mio::benchmark::FlowModel;
// suppress non-critical messages
mio::set_log_level(mio::LogLevel::critical);
// load config
auto cfg = mio::benchmark::SimulationConfig::initialize(config_path);
// create model
Model model(cfg.num_agegroups);
mio::benchmark::setup_model(model);
// create simulation
std::shared_ptr<mio::IntegratorCore> I =
std::make_shared<mio::ControlledStepperWrapper<boost::numeric::odeint::runge_kutta_cash_karp54>>(
cfg.abs_tol, cfg.rel_tol, cfg.dt_min, cfg.dt_max);
// run benchmark
for (auto _ : state) {
// This code gets timed
mio::osecirvvs::Simulation<mio::Simulation<Model>> sim(model, cfg.t0, cfg.dt);
sim.set_integrator(I);
// run sim
sim.advance(cfg.t_max);
}
}

// simulation with flows (in Model definition and calculated by Simulation)
void flow_sim(::benchmark::State& state)
{
using Model = mio::benchmark::FlowModel;
// suppress non-critical messages
mio::set_log_level(mio::LogLevel::critical);
// load config
auto cfg = mio::benchmark::SimulationConfig::initialize(config_path);
// create model
Model model(cfg.num_agegroups);
mio::benchmark::setup_model(model);
// create simulation
std::shared_ptr<mio::IntegratorCore> I =
std::make_shared<mio::ControlledStepperWrapper<boost::numeric::odeint::runge_kutta_cash_karp54>>(
cfg.abs_tol, cfg.rel_tol, cfg.dt_min, cfg.dt_max);
// run benchmark
for (auto _ : state) {
// This code gets timed
mio::osecirvvs::Simulation<mio::FlowSimulation<Model>> sim(model, cfg.t0, cfg.dt);
sim.set_integrator(I);
// run sim
sim.advance(cfg.t_max);
}
}

// register functions as a benchmarks and set a name
// mitigate influence of cpu scaling
BENCHMARK(flowless_sim)->Name("Dummy 1/3");
BENCHMARK(flowless_sim)->Name("Dummy 2/3");
BENCHMARK(flowless_sim)->Name("Dummy 3/3");
// actual benchmarks
BENCHMARK(flowless_sim)
->Name(
"osecirvvs::Simulation<mio::Simulation> on osecirvvs::Model (osecirvvs::* from pre 511 branch) without flows");
BENCHMARK(flow_sim_comp_only)->Name("osecirvvs::Simulation<mio::Simulation> on osecirvvs::Model with flows");
BENCHMARK(flow_sim)->Name("osecirvvs::Simulation<mio::FlowSimulation> on osecirvvs::Model with flows");
// run all benchmarks
BENCHMARK_MAIN();
Loading

0 comments on commit e664729

Please sign in to comment.