Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions .github/actions/sbml-test/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ runs:
shell: bash
run: |
cd cpp/build
cmake -DCMAKE_BUILD_TYPE=Release -DMEMILIO_ENABLE_SBML=ON -Dsbml_DIR=/usr/lib/x86_64-linux-gnu/cmake ..
cmake -DCMAKE_BUILD_TYPE=Release -DMEMILIO_BUILD_TESTS=OFF -DMEMILIO_ENABLE_SBML=ON -Dsbml_DIR=/usr/lib/x86_64-linux-gnu/cmake ..
cmake --build . -j 4
- name: Run SBML importer
shell: bash
Expand All @@ -49,5 +49,5 @@ runs:
shell: bash
run: |
cd cpp/build
cmake -DCMAKE_BUILD_TYPE=Release -DMEMILIO_ENABLE_SBML=ON -Dsbml_DIR=/usr/lib/x86_64-linux-gnu/cmake ..
cmake -DCMAKE_BUILD_TYPE=Release -DMEMILIO_BUILD_TESTS=OFF -DMEMILIO_ENABLE_SBML=ON -Dsbml_DIR=/usr/lib/x86_64-linux-gnu/cmake ..
cmake --build . -j 4
19 changes: 15 additions & 4 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,21 @@ option(MEMILIO_ENABLE_IPOPT "Enable numerical optimization with Ipopt, requires
option(MEMILIO_ENABLE_PROFILING "Enable runtime performance profiling of memilio." OFF)
option(MEMILIO_ENABLE_LIKWID_MARKER "Enable performance measuring with likwid markers." OFF)

mark_as_advanced(MEMILIO_USE_BUNDLED_SPDLOG MEMILIO_SANITIZE_ADDRESS MEMILIO_SANITIZE_UNDEFINED)
cmake_path(CONVERT "${PROJECT_SOURCE_DIR}/.." TO_CMAKE_PATH_LIST PROJECT_ROOT_NORMALIZED NORMALIZE)
set(MEMILIO_BASE_DIR "${PROJECT_ROOT_NORMALIZED}" CACHE PATH
"Path to the MEmilio project root, used for file I/O. Accessed via mio::base_dir().")
set(MEMILIO_DATA_DIR "${PROJECT_ROOT_NORMALIZED}/data" CACHE PATH
"Path to the MEmilio data directory. Accessed via mio::data_dir().")

mark_as_advanced(
MEMILIO_USE_BUNDLED_SPDLOG
MEMILIO_SANITIZE_ADDRESS
MEMILIO_SANITIZE_UNDEFINED
MEMILIO_BUILD_SHARED_LIBS
MEMILIO_BUILD_STATIC_LIBS
MEMILIO_BASE_DIR
MEMILIO_DATA_DIR
)

# try to treat AppleClang as Clang, but warn about missing support
if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
Expand Down Expand Up @@ -76,9 +90,6 @@ set(CMAKE_PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
set(CMAKE_INSTALL_RPATH "${CMAKE_BINARY_DIR}/lib" "${CMAKE_BINARY_DIR}/bin")

# sets MEMILIO_BASE_DIR to the directory containing cpp (i.e., the root of the git repo)
cmake_path(CONVERT "${PROJECT_SOURCE_DIR}/.." TO_CMAKE_PATH_LIST MEMILIO_BASE_DIR NORMALIZE)

# code coverage analysis
# Note: this only works under linux and with make
# Ninja creates different directory names which do not work together with this scrupt
Expand Down
2 changes: 1 addition & 1 deletion cpp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ The following table lists the dependencies that are used. Most of them are requi

| Library | Version | Required | Bundled | Notes |
|---------|----------|----------|-----------------------|-------|
| spdlog | 1.15.0 | Yes | Yes (git repo) | https://github.com/gabime/spdlog |
| spdlog | 1.17.0 | Yes | Yes (git repo) | https://github.com/gabime/spdlog |
| Eigen | 3.4.0 | Yes | Yes (git repo) | http://gitlab.com/libeigen/eigen |
| Boost | 1.84.0 | Yes | Yes (git repo) | https://github.com/boostorg/boost |
| JsonCpp | 1.9.6 | No | Yes (git repo) | https://github.com/open-source-parsers/jsoncpp |
Expand Down
4 changes: 2 additions & 2 deletions cpp/benchmarks/flow_simulation_ode_secirvvs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
#include "benchmarks/flow_simulation_ode_secirvvs.h"
#include "memilio/compartments/flow_simulation.h"
#include "memilio/compartments/simulation.h"
#include "memilio/utils/base_dir.h"
#include "memilio/io/directories.h"
#include "ode_secirvvs/model.h"
#include <string>

const std::string config_path = mio::base_dir() + "cpp/benchmarks/simulation.config";
const std::string config_path = (mio::base_dir() / "cpp/benchmarks/simulation.config").string();

// simulation without flows (not in Model definition and not calculated by Simulation)
void flowless_sim(::benchmark::State& state)
Expand Down
4 changes: 2 additions & 2 deletions cpp/benchmarks/flow_simulation_ode_seir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
#include "benchmarks/simulation.h"
#include "memilio/compartments/flow_simulation.h"
#include "memilio/compartments/simulation.h"
#include "memilio/utils/base_dir.h"
#include "memilio/io/directories.h"
#include "ode_seir/model.h"

#include <string>

const std::string config_path = mio::base_dir() + "cpp/benchmarks/simulation.config";
const std::string config_path = (mio::base_dir() / "cpp/benchmarks/simulation.config").string();

namespace mio
{
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 @@ -22,11 +22,11 @@
#include "memilio/compartments/simulation.h"
#include "memilio/math/adapt_rk.h"
#include "memilio/mobility/metapopulation_mobility_instant.h"
#include "memilio/utils/base_dir.h"
#include "memilio/io/directories.h"
#include "ode_secirvvs/model.h"
#include <string>

const std::string config_path = mio::base_dir() + "cpp/benchmarks/graph_simulation.config";
const std::string config_path = (mio::base_dir() / "cpp/benchmarks/graph_simulation.config").string();

mio::osecirvvs::Model<ScalarType> create_model(size_t num_agegroups, const ScalarType tmax)
{
Expand Down
6 changes: 3 additions & 3 deletions cpp/benchmarks/integrator_step.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#include "memilio/math/adapt_rk.h"
#include "memilio/math/stepper_wrapper.h"
#include "memilio/utils/base_dir.h"
#include "memilio/io/directories.h"

template <class Integrator>
void integrator_step(::benchmark::State& state)
Expand All @@ -33,8 +33,8 @@ void integrator_step(::benchmark::State& state)
// with "num_agegroups" agegroups, and taking "yt" as the state of the simulation at "t_init"
// NOTE: yt must have #agegroups * #compartments entries
// benchmark setup
auto cfg =
mio::benchmark::IntegratorStepConfig::initialize(mio::base_dir() + "cpp/benchmarks/integrator_step.config");
auto cfg = mio::benchmark::IntegratorStepConfig::initialize(
(mio::base_dir() / "cpp/benchmarks/integrator_step.config").string());
//auto cfg = mio::benchmark::IntegratorStepConfig::initialize();
auto model = mio::benchmark::model::SecirAgeres(cfg.num_agegroups);
// set deriv function and integrator
Expand Down
5 changes: 3 additions & 2 deletions cpp/benchmarks/simulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@

#include "memilio/math/adapt_rk.h"
#include "memilio/math/stepper_wrapper.h"
#include "memilio/utils/base_dir.h"
#include "memilio/io/directories.h"

template <class Integrator>
void simulation(::benchmark::State& state)
{
// suppress non-critical messages
mio::set_log_level(mio::LogLevel::critical);
// setup benchmark parameters
auto cfg = mio::benchmark::SimulationConfig::initialize(mio::base_dir() + "cpp/benchmarks/simulation.config");
auto cfg =
mio::benchmark::SimulationConfig::initialize((mio::base_dir() / "cpp/benchmarks/simulation.config").string());
//auto cfg = mio::benchmark::SimulationConfig::initialize(10);
auto model = mio::benchmark::model::SecirAgeres(cfg.num_agegroups);

Expand Down
26 changes: 11 additions & 15 deletions cpp/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# configure directory that contains the data files used by examples
file(TO_CMAKE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../data" MEMILIO_DATA_DIR)
configure_file(data_dir.h.in data_dir.h)

add_executable(euler_example euler_test.cpp)
target_link_libraries(euler_example PRIVATE memilio)
target_compile_options(euler_example PRIVATE ${MEMILIO_CXX_FLAGS_ENABLE_WARNING_ERRORS})
Expand All @@ -18,17 +14,17 @@ add_executable(adapt_rk_example adapt_rk_test.cpp)
target_link_libraries(adapt_rk_example PRIVATE memilio)
target_compile_options(adapt_rk_example PRIVATE ${MEMILIO_CXX_FLAGS_ENABLE_WARNING_ERRORS})

add_executable(ode_seir_example ode_seir.cpp)
target_link_libraries(ode_seir_example PRIVATE memilio ode_seir)
target_compile_options(ode_seir_example PRIVATE ${MEMILIO_CXX_FLAGS_ENABLE_WARNING_ERRORS})

add_executable(ode_seirdb_example ode_seirdb.cpp)
target_link_libraries(ode_seirdb_example PRIVATE memilio ode_seirdb)
target_compile_options(ode_seirdb_example PRIVATE ${MEMILIO_CXX_FLAGS_ENABLE_WARNING_ERRORS})

add_executable(ode_seir_ageres_example ode_seir_ageres.cpp)
target_link_libraries(ode_seir_ageres_example PRIVATE memilio ode_seir)
target_compile_options(ode_seir_ageres_example PRIVATE ${MEMILIO_CXX_FLAGS_ENABLE_WARNING_ERRORS})
add_executable(ode_seir_example ode_seir.cpp)
target_link_libraries(ode_seir_example PRIVATE memilio ode_seir)
target_compile_options(ode_seir_example PRIVATE ${MEMILIO_CXX_FLAGS_ENABLE_WARNING_ERRORS})
add_executable(ode_seirdb_example ode_seirdb.cpp)
target_link_libraries(ode_seirdb_example PRIVATE memilio ode_seirdb)
target_compile_options(ode_seirdb_example PRIVATE ${MEMILIO_CXX_FLAGS_ENABLE_WARNING_ERRORS})
add_executable(ode_seir_ageres_example ode_seir_ageres.cpp)
target_link_libraries(ode_seir_ageres_example PRIVATE memilio ode_seir)
target_compile_options(ode_seir_ageres_example PRIVATE ${MEMILIO_CXX_FLAGS_ENABLE_WARNING_ERRORS})

add_executable(ode_sir_example ode_sir.cpp)
target_link_libraries(ode_sir_example PRIVATE memilio ode_sir)
Expand Down
5 changes: 4 additions & 1 deletion cpp/examples/abm_history_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
#include "abm/simulation.h"
#include "abm/model.h"
#include "abm/location_type.h"
#include "memilio/io/io.h"
#include "memilio/utils/abstract_parameter_distribution.h"
#include "memilio/io/history.h"
#include "memilio/io/directories.h"
#include "memilio/utils/parameter_distributions.h"

#include <fstream>
Expand All @@ -43,7 +45,8 @@ void write_log_to_file(const T& history)
auto loc_id = std::get<1>(logg);
auto time_points = std::get<0>(logg);
std::string input;
std::ofstream myfile("test_output.txt");
std::ofstream myfile(mio::create_directories_or_exit(mio::example_results_dir("abm_history_object")) /
"test_output.txt");
myfile << "Locations as numbers:\n";
for (auto&& id : loc_id[0]) {
myfile << convert_loc_id_to_string(id) << "\n";
Expand Down
6 changes: 4 additions & 2 deletions cpp/examples/abm_minimal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "abm/lockdown_rules.h"
#include "abm/model.h"
#include "abm/common_abm_loggers.h"
#include "memilio/io/directories.h"

#include <fstream>

Expand Down Expand Up @@ -165,10 +166,11 @@ int main()
// The first column is Time. The other columns correspond to the number of people with a certain infection state at this Time:
// Time = Time in days, S = Susceptible, E = Exposed, I_NS = InfectedNoSymptoms, I_Sy = InfectedSymptoms, I_Sev = InfectedSevere,
// I_Crit = InfectedCritical, R = Recovered, D = Dead
std::ofstream outfile("abm_minimal.txt");
auto outpath = mio::create_directories_or_exit(mio::example_results_dir("abm_minimal")) / "history.txt";
std::ofstream outfile(outpath);
std::get<0>(historyTimeSeries.get_log())
.print_table(outfile, {"S", "E", "I_NS", "I_Sy", "I_Sev", "I_Crit", "R", "D"}, 7, 4);
std::cout << "Results written to abm_minimal.txt" << std::endl;
std::cout << "Results written to " << outpath << std::endl;

return 0;
}
14 changes: 5 additions & 9 deletions cpp/examples/abm_parameter_study.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "memilio/data/analyze_result.h"
#include "memilio/io/io.h"
#include "memilio/io/result_io.h"
#include "memilio/utils/base_dir.h"
#include "memilio/io/directories.h"
#include "memilio/utils/logging.h"
#include "memilio/utils/miompi.h"
#include "memilio/utils/random_number_generator.h"
Expand Down Expand Up @@ -192,11 +192,7 @@ int main()
mio::ParameterStudy study(std::move(model), t0, tmax, mio::abm::TimeSpan(0), num_runs);
study.get_rng() = rng; // use the same RNG as the model

const std::string result_dir = mio::path_join(mio::base_dir(), "example_results");
if (!mio::create_directory(result_dir)) {
mio::log_error("Could not create result directory \"{}\".", result_dir);
return 1;
}
const auto result_dir = mio::create_directories_or_exit(mio::example_results_dir("abm_parameter_study"));

// Run the study
// The first lambda ("create_simulation" argument) sets up the simulation, the second ("process_simulation_result")
Expand All @@ -212,17 +208,17 @@ int main()
},
[&result_dir](auto&& sim, auto&& run_idx) {
auto interpolated_result = mio::interpolate_simulation_result(sim.get_result());
std::string outpath = mio::path_join(result_dir, "abm_minimal_run_" + std::to_string(run_idx) + ".txt");
auto outpath = result_dir / ("abm_minimal_run_" + std::to_string(run_idx) + ".txt");
std::ofstream outfile_run(outpath);
sim.get_result().print_table(outfile_run, {"S", "E", "I_NS", "I_Sy", "I_Sev", "I_Crit", "R", "D"}, 7, 4);
std::cout << "Results written to " << outpath << std::endl;
std::cout << "Results written to " << outpath.string() << std::endl;
return std::vector{interpolated_result};
});

// The study collects all results on the root rank, so we only process the results there
if (mio::mpi::is_root()) {
const auto write_percentile = [&](double p) {
std::ofstream out(mio::path_join(result_dir, fmt::format("Results_p{:0<4.2}.txt", p)));
std::ofstream out(result_dir / fmt::format("Results_p{:0<4.2}.txt", p));
auto ensemble_percentiles = ensemble_percentile(ensemble_results, p);
ensemble_percentiles.front().print_table(out, {"S", "E", "I_NS", "I_Sy", "I_Sev", "I_Crit", "R", "D"}, 7,
4);
Expand Down
25 changes: 0 additions & 25 deletions cpp/examples/data_dir.h.in

This file was deleted.

6 changes: 3 additions & 3 deletions cpp/examples/graph_abm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ struct Logger : mio::LogAlways {
*/
using Type = std::vector<std::tuple<int, mio::abm::LocationType, mio::abm::LocationId, size_t,
std::map<mio::abm::InfectionState, size_t>>>;
static Type log(const mio::abm::Simulation<mio::GraphABModel>& sim)
static Type log(const mio::abm::Simulation<mio::abm::GraphABModel>& sim)
{
Type location_information{};
location_information.reserve(size_t(mio::abm::LocationType::Count));
Expand Down Expand Up @@ -76,7 +76,7 @@ int main()
const auto age_group_adults = mio::AgeGroup(1);
const auto age_group_seniors = mio::AgeGroup(2);

auto model1 = mio::GraphABModel(num_age_groups, 0);
auto model1 = mio::abm::GraphABModel(num_age_groups, 0);

//Set infection parameters
model1.parameters.get<mio::abm::TimeExposedToNoSymptoms>() = mio::ParameterDistributionConstant(4.);
Expand Down Expand Up @@ -134,7 +134,7 @@ int main()
add_household_group_to_model(model1, single_hh_group_m1);
add_household_group_to_model(model1, family_hh_group_m1);

auto model2 = mio::GraphABModel(num_age_groups, 1);
auto model2 = mio::abm::GraphABModel(num_age_groups, 1);

//Set infection parameters
model2.parameters.get<mio::abm::TimeExposedToNoSymptoms>() = mio::ParameterDistributionConstant(4.);
Expand Down
15 changes: 4 additions & 11 deletions cpp/examples/ode_mseirs4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ int main()
// Compute S1 as residual to match N
double assigned = 5000.0 + (300.0 + 150.0 + 80.0 + 70.0) + (200.0 + 100.0 + 50.0 + 50.0) +
(40000.0 + 30000.0 + 20000.0 + 10000.0) + (100000.0 + 50000.0 + 50000.0);
double S1 = N - assigned;
double S1 = N - assigned;
if (S1 < 0)
S1 = 0;
model.populations[{mio::Index<mio::omseirs4::InfectionState>(mio::omseirs4::InfectionState::S1)}] = S1;
Expand All @@ -80,15 +80,8 @@ int main()
double dt = 1.0; // daily output
auto result = mio::simulate(t0, tmax, dt, model);

// print header
std::cout << "t M S1 S2 S3 S4 E1 E2 E3 E4 I1 I2 I3 I4 R1 R2 R3 R4\n";
for (size_t i = 0; i < (size_t)result.get_num_time_points(); ++i) {
std::cout << result.get_time(i);
const auto& y = result.get_value(i);
for (size_t k = 0; k < (size_t)mio::omseirs4::InfectionState::Count; ++k) {
std::cout << ' ' << y[(Eigen::Index)k];
}
std::cout << '\n';
}
// print results
result.print_table(
{"M", "S1", "S2", "S3", "S4", "E1", "E2", "E3", "E4", "I1", "I2", "I3", "I4", "R1", "R2", "R3", "R4"}, 10, 2);
return 0;
}
22 changes: 13 additions & 9 deletions cpp/examples/ode_seair_optimization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

#include "memilio/ad/ad.h"

#include "memilio/io/directories.h"
#include "memilio/io/io.h"
#include "memilio/utils/compiler_diagnostics.h"
#include "ode_seair/model.h"
#include "ode_seair/infection_state.h"
Expand Down Expand Up @@ -512,18 +514,20 @@ void Seair_NLP::finalize_solution(Ipopt::SolverReturn status, Ipopt::Index n, co
}
mio::oseair::Model<FP> model;

const auto result_dir = mio::create_directories_or_exit(mio::example_results_dir("ode_seair_optimization"));

//open files for parameter output
std::ofstream outFileSocialDistancing("SocialDistancing.txt");
std::ofstream outFileQuarantined("Quarantined.txt");
std::ofstream outFileTestingRate("TestingRate.txt");
std::ofstream outFileSocialDistancing(result_dir / "SocialDistancing.txt");
std::ofstream outFileQuarantined(result_dir / "Quarantined.txt");
std::ofstream outFileTestingRate(result_dir / "TestingRate.txt");

//open files for state output
std::ofstream outFileSusceptible("Susceptible.txt");
std::ofstream outFileExposed("Exposed.txt");
std::ofstream outFileAsymptomatic("Asymptomatic.txt");
std::ofstream outFileInfected("Infected.txt");
std::ofstream outFileRecovered("Recovered.txt");
std::ofstream outFileDead("Dead.txt");
std::ofstream outFileSusceptible(result_dir / "Susceptible.txt");
std::ofstream outFileExposed(result_dir / "Exposed.txt");
std::ofstream outFileAsymptomatic(result_dir / "Asymptomatic.txt");
std::ofstream outFileInfected(result_dir / "Infected.txt");
std::ofstream outFileRecovered(result_dir / "Recovered.txt");
std::ofstream outFileDead(result_dir / "Dead.txt");

set_initial_values(model);
int gridindex = 0;
Expand Down
Loading
Loading