Skip to content

Commit

Permalink
1204 Reduce unnecessary logs and prints when running the examples (#1205
Browse files Browse the repository at this point in the history
)

- Remove unnecessary logs/prints in the examples

Co-authored-by: reneSchm <49305466+reneSchm@users.noreply.github.com>
  • Loading branch information
HenrZu and reneSchm authored Feb 17, 2025
1 parent 040d985 commit cc6ed9d
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 28 deletions.
3 changes: 2 additions & 1 deletion cpp/examples/abm_history_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ void write_log_to_file(const T& history)

int main()
{
mio::set_log_level(mio::LogLevel::warn);
// This is a minimal example with children and adults < 60y.
// We divided them into 4 different age groups, which are defined as follows:
const size_t num_age_groups = 4;
Expand Down Expand Up @@ -133,7 +134,7 @@ int main()
auto test_parameters = model.parameters.get<mio::abm::TestData>()[test_type];
auto testing_criteria_work = mio::abm::TestingCriteria();
auto testing_scheme_work = mio::abm::TestingScheme(testing_criteria_work, validity_period, start_date, end_date,
test_parameters, probability);
test_parameters, probability);
model.get_testing_strategy().add_testing_scheme(mio::abm::LocationType::Work, testing_scheme_work);

// Assign infection state to each person.
Expand Down
3 changes: 2 additions & 1 deletion cpp/examples/abm_minimal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ int main()
{
// This is a minimal example with children and adults < 60 year old.
// We divided them into 4 different age groups, which are defined as follows:
mio::set_log_level(mio::LogLevel::warn);
size_t num_age_groups = 4;
const auto age_group_0_to_4 = mio::AgeGroup(0);
const auto age_group_5_to_14 = mio::AgeGroup(1);
Expand Down Expand Up @@ -112,7 +113,7 @@ int main()
auto test_parameters = model.parameters.get<mio::abm::TestData>()[test_type];
auto testing_criteria_work = mio::abm::TestingCriteria();
auto testing_scheme_work = mio::abm::TestingScheme(testing_criteria_work, validity_period, start_date, end_date,
test_parameters, probability);
test_parameters, probability);
model.get_testing_strategy().add_testing_scheme(mio::abm::LocationType::Work, testing_scheme_work);

// Assign infection state to each person.
Expand Down
1 change: 1 addition & 0 deletions cpp/examples/graph_abm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ struct Logger : mio::LogAlways {

int main()
{
mio::set_log_level(mio::LogLevel::warn);
// This is an example with three age groups representing children, adults and seniors.
size_t num_age_groups = 3;
const auto age_group_children = mio::AgeGroup(0);
Expand Down
1 change: 1 addition & 0 deletions cpp/examples/ode_secir_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

int main()
{
mio::set_log_level(mio::LogLevel::warn);
const auto t0 = 0.;
const auto tmax = 30.;
const auto dt = 0.5; //time step of Mobility, daily Mobility every second step
Expand Down
4 changes: 3 additions & 1 deletion cpp/examples/ode_secir_read_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ std::string setup(int argc, char** argv, const std::string data_dir)
mio::log_warning("No arguments given.");
}
std::cout << "Using default file twitter_scaled_1252 in data/mobility." << std::endl;
std::cout << "Usage: read_graph MOBILITY_FILE" << "\n\n";
std::cout << "Usage: read_graph MOBILITY_FILE"
<< "\n\n";
std::cout << "This example performs a simulation based on twitter "
"mobility data."
<< std::endl;
Expand All @@ -49,6 +50,7 @@ std::string setup(int argc, char** argv, const std::string data_dir)

int main(int argc, char** argv)
{
mio::set_log_level(mio::LogLevel::critical);
std::string data_dir = DATA_DIR;
std::string filename = setup(argc, argv, data_dir);

Expand Down
4 changes: 2 additions & 2 deletions cpp/examples/ode_secirts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ int main()
// This example demonstrates how to simulate a SECIRTS model.
// The SECIRTS model is an extension of the SECIRVVS model that includes waning and temporary immunity.
// After the simulation, the aggregated size of the temporary immunity states are printed.
mio::set_log_level(mio::LogLevel::debug);
mio::set_log_level(mio::LogLevel::warn);

double t0 = 0;
double tmax = 100;
double tmax = 30;
double dt = 0.1;

mio::log_info("Simulating SECIRTS; t={} ... {} with dt = {}.", t0, tmax, dt);
Expand Down
2 changes: 1 addition & 1 deletion cpp/examples/ode_secirvvs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

int main()
{
mio::set_log_level(mio::LogLevel::debug);
mio::set_log_level(mio::LogLevel::warn);

double t0 = 0;
double tmax = 30;
Expand Down
9 changes: 6 additions & 3 deletions cpp/examples/ode_sir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "memilio/data/analyze_result.h"
#include "memilio/compartments/simulation.h"
#include "memilio/config.h"
#include "memilio/math/euler.h"
Expand Down Expand Up @@ -60,6 +60,9 @@ int main()
std::make_shared<mio::EulerIntegratorCore<ScalarType>>();
auto sir = simulate(t0, tmax, dt, model, integrator);

sir.print_table({"S", "I", "R"});
std::cout << "\nnumber total: " << sir.get_last_value().sum() << "\n";
// interpolate results
auto interpolated_results = mio::interpolate_simulation_result(sir);

interpolated_results.print_table({"S", "I", "R"});
std::cout << "\nPopulation total: " << sir.get_last_value().sum() << "\n";
}
34 changes: 17 additions & 17 deletions cpp/examples/sde_seirvv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,27 @@ int main()
mio::set_log_level(mio::LogLevel::debug);

ScalarType t0 = 0.;
ScalarType tmid = 100.;
ScalarType tmax = 400.;
ScalarType tmid = 1.;
ScalarType tmax = 3.;
ScalarType dt = 0.1;

mio::log_info("Simulating SEIRVV; t={} ... {} with dt = {}.", t0, tmax, dt);

mio::sseirvv::Model model;

ScalarType total_population = 180000;

model.populations[{mio::sseirvv::InfectionState::ExposedV1}] = 0;
model.populations[{mio::sseirvv::InfectionState::ExposedV2}] = 0;
model.populations[{mio::sseirvv::InfectionState::InfectedV1}] = 7200;
model.populations[{mio::sseirvv::InfectionState::InfectedV2}] = 0;
model.populations[{mio::sseirvv::InfectionState::RecoveredV1}] = 0;
model.populations[{mio::sseirvv::InfectionState::RecoveredV2}] = 0;
model.populations[{mio::sseirvv::InfectionState::ExposedV1V2}] = 0;
model.populations[{mio::sseirvv::InfectionState::ExposedV1}] = 0;
model.populations[{mio::sseirvv::InfectionState::ExposedV2}] = 0;
model.populations[{mio::sseirvv::InfectionState::InfectedV1}] = 7200;
model.populations[{mio::sseirvv::InfectionState::InfectedV2}] = 0;
model.populations[{mio::sseirvv::InfectionState::RecoveredV1}] = 0;
model.populations[{mio::sseirvv::InfectionState::RecoveredV2}] = 0;
model.populations[{mio::sseirvv::InfectionState::ExposedV1V2}] = 0;
model.populations[{mio::sseirvv::InfectionState::InfectedV1V2}] = 0;
model.populations[{mio::sseirvv::InfectionState::RecoveredV1V2}] = 0;
model.populations[{mio::sseirvv::InfectionState::Susceptible}] =
total_population -
model.populations[{mio::sseirvv::InfectionState::ExposedV1}] -
total_population - model.populations[{mio::sseirvv::InfectionState::ExposedV1}] -
model.populations[{mio::sseirvv::InfectionState::ExposedV2}] -
model.populations[{mio::sseirvv::InfectionState::InfectedV1}] -
model.populations[{mio::sseirvv::InfectionState::InfectedV2}] -
Expand All @@ -60,14 +59,14 @@ int main()
model.populations[{mio::sseirvv::InfectionState::InfectedV1V2}] -
model.populations[{mio::sseirvv::InfectionState::RecoveredV1V2}];

// It is assumed that both variants have the same transmission probability
// It is assumed that both variants have the same transmission probability
// on contact and the same time exposed. The time infected is scaled by
// 1.35 for the second variant.
model.parameters.get<mio::sseirvv::ContactPatterns>().get_baseline()(0, 0) = 1;
model.parameters.set<mio::sseirvv::TransmissionProbabilityOnContactV1>(0.076);
model.parameters.set<mio::sseirvv::TransmissionProbabilityOnContactV2>(0.076);
model.parameters.set<mio::sseirvv::TimeExposedV1>(5.33);
model.parameters.set<mio::sseirvv::TimeExposedV2>(5.33);
model.parameters.set<mio::sseirvv::TimeExposedV2>(5.33);
model.parameters.set<mio::sseirvv::TimeInfectedV1>(17.2);
model.parameters.set<mio::sseirvv::TimeInfectedV2>(17.2 * 1.35);

Expand All @@ -81,7 +80,8 @@ int main()
model.populations[{mio::sseirvv::InfectionState::InfectedV2}] = 100;
// Simulate the model from tmid to tmax, now with both variants.
auto sseirv2 = mio::sseirvv::simulate(tmid, tmax, dt, model);

sseirv.print_table({"Susceptible", "ExposedV1", "InfectedV1", "RecoveredV1", "ExposedV2", "InfectedV2", "RecoveredV2", "ExposedV1V2", "InfectedV1V2", "RecoveredV1V2"});
sseirv2.print_table({"Susceptible", "ExposedV1", "InfectedV1", "RecoveredV1", "ExposedV2", "InfectedV2", "RecoveredV2", "ExposedV1V2", "InfectedV1V2", "RecoveredV1V2"});
sseirv.print_table({"Susceptible", "ExposedV1", "InfectedV1", "RecoveredV1", "ExposedV2", "InfectedV2",
"RecoveredV2", "ExposedV1V2", "InfectedV1V2", "RecoveredV1V2"});
sseirv2.print_table({"Susceptible", "ExposedV1", "InfectedV1", "RecoveredV1", "ExposedV2", "InfectedV2",
"RecoveredV2", "ExposedV1V2", "InfectedV1V2", "RecoveredV1V2"});
}
7 changes: 5 additions & 2 deletions cpp/examples/sde_sirs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "memilio/data/analyze_result.h"
#include "memilio/utils/logging.h"
#include "sde_sirs/model.h"
#include "sde_sirs/simulation.h"
Expand Down Expand Up @@ -52,5 +52,8 @@ int main()

auto ssirs = mio::ssirs::simulate(t0, tmax, dt, model);

ssirs.print_table({"Susceptible", "Infected", "Recovered"});
// interpolate results
auto interpolated_results = mio::interpolate_simulation_result(ssirs);

interpolated_results.print_table({"Susceptible", "Infected", "Recovered"});
}

0 comments on commit cc6ed9d

Please sign in to comment.