Skip to content

Commit cc6ed9d

Browse files
HenrZureneSchm
andauthored
1204 Reduce unnecessary logs and prints when running the examples (#1205)
- Remove unnecessary logs/prints in the examples Co-authored-by: reneSchm <49305466+reneSchm@users.noreply.github.com>
1 parent 040d985 commit cc6ed9d

File tree

10 files changed

+40
-28
lines changed

10 files changed

+40
-28
lines changed

cpp/examples/abm_history_object.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ void write_log_to_file(const T& history)
5858

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

139140
// Assign infection state to each person.

cpp/examples/abm_minimal.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ int main()
2828
{
2929
// This is a minimal example with children and adults < 60 year old.
3030
// We divided them into 4 different age groups, which are defined as follows:
31+
mio::set_log_level(mio::LogLevel::warn);
3132
size_t num_age_groups = 4;
3233
const auto age_group_0_to_4 = mio::AgeGroup(0);
3334
const auto age_group_5_to_14 = mio::AgeGroup(1);
@@ -112,7 +113,7 @@ int main()
112113
auto test_parameters = model.parameters.get<mio::abm::TestData>()[test_type];
113114
auto testing_criteria_work = mio::abm::TestingCriteria();
114115
auto testing_scheme_work = mio::abm::TestingScheme(testing_criteria_work, validity_period, start_date, end_date,
115-
test_parameters, probability);
116+
test_parameters, probability);
116117
model.get_testing_strategy().add_testing_scheme(mio::abm::LocationType::Work, testing_scheme_work);
117118

118119
// Assign infection state to each person.

cpp/examples/graph_abm.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ struct Logger : mio::LogAlways {
6767

6868
int main()
6969
{
70+
mio::set_log_level(mio::LogLevel::warn);
7071
// This is an example with three age groups representing children, adults and seniors.
7172
size_t num_age_groups = 3;
7273
const auto age_group_children = mio::AgeGroup(0);

cpp/examples/ode_secir_graph.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
int main()
3030
{
31+
mio::set_log_level(mio::LogLevel::warn);
3132
const auto t0 = 0.;
3233
const auto tmax = 30.;
3334
const auto dt = 0.5; //time step of Mobility, daily Mobility every second step

cpp/examples/ode_secir_read_graph.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ std::string setup(int argc, char** argv, const std::string data_dir)
3939
mio::log_warning("No arguments given.");
4040
}
4141
std::cout << "Using default file twitter_scaled_1252 in data/mobility." << std::endl;
42-
std::cout << "Usage: read_graph MOBILITY_FILE" << "\n\n";
42+
std::cout << "Usage: read_graph MOBILITY_FILE"
43+
<< "\n\n";
4344
std::cout << "This example performs a simulation based on twitter "
4445
"mobility data."
4546
<< std::endl;
@@ -49,6 +50,7 @@ std::string setup(int argc, char** argv, const std::string data_dir)
4950

5051
int main(int argc, char** argv)
5152
{
53+
mio::set_log_level(mio::LogLevel::critical);
5254
std::string data_dir = DATA_DIR;
5355
std::string filename = setup(argc, argv, data_dir);
5456

cpp/examples/ode_secirts.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ int main()
2828
// This example demonstrates how to simulate a SECIRTS model.
2929
// The SECIRTS model is an extension of the SECIRVVS model that includes waning and temporary immunity.
3030
// After the simulation, the aggregated size of the temporary immunity states are printed.
31-
mio::set_log_level(mio::LogLevel::debug);
31+
mio::set_log_level(mio::LogLevel::warn);
3232

3333
double t0 = 0;
34-
double tmax = 100;
34+
double tmax = 30;
3535
double dt = 0.1;
3636

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

cpp/examples/ode_secirvvs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
int main()
2525
{
26-
mio::set_log_level(mio::LogLevel::debug);
26+
mio::set_log_level(mio::LogLevel::warn);
2727

2828
double t0 = 0;
2929
double tmax = 30;

cpp/examples/ode_sir.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* See the License for the specific language governing permissions and
1818
* limitations under the License.
1919
*/
20-
20+
#include "memilio/data/analyze_result.h"
2121
#include "memilio/compartments/simulation.h"
2222
#include "memilio/config.h"
2323
#include "memilio/math/euler.h"
@@ -60,6 +60,9 @@ int main()
6060
std::make_shared<mio::EulerIntegratorCore<ScalarType>>();
6161
auto sir = simulate(t0, tmax, dt, model, integrator);
6262

63-
sir.print_table({"S", "I", "R"});
64-
std::cout << "\nnumber total: " << sir.get_last_value().sum() << "\n";
63+
// interpolate results
64+
auto interpolated_results = mio::interpolate_simulation_result(sir);
65+
66+
interpolated_results.print_table({"S", "I", "R"});
67+
std::cout << "\nPopulation total: " << sir.get_last_value().sum() << "\n";
6568
}

cpp/examples/sde_seirvv.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,27 @@ int main()
2929
mio::set_log_level(mio::LogLevel::debug);
3030

3131
ScalarType t0 = 0.;
32-
ScalarType tmid = 100.;
33-
ScalarType tmax = 400.;
32+
ScalarType tmid = 1.;
33+
ScalarType tmax = 3.;
3434
ScalarType dt = 0.1;
3535

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

3838
mio::sseirvv::Model model;
39-
39+
4040
ScalarType total_population = 180000;
4141

42-
model.populations[{mio::sseirvv::InfectionState::ExposedV1}] = 0;
43-
model.populations[{mio::sseirvv::InfectionState::ExposedV2}] = 0;
44-
model.populations[{mio::sseirvv::InfectionState::InfectedV1}] = 7200;
45-
model.populations[{mio::sseirvv::InfectionState::InfectedV2}] = 0;
46-
model.populations[{mio::sseirvv::InfectionState::RecoveredV1}] = 0;
47-
model.populations[{mio::sseirvv::InfectionState::RecoveredV2}] = 0;
48-
model.populations[{mio::sseirvv::InfectionState::ExposedV1V2}] = 0;
42+
model.populations[{mio::sseirvv::InfectionState::ExposedV1}] = 0;
43+
model.populations[{mio::sseirvv::InfectionState::ExposedV2}] = 0;
44+
model.populations[{mio::sseirvv::InfectionState::InfectedV1}] = 7200;
45+
model.populations[{mio::sseirvv::InfectionState::InfectedV2}] = 0;
46+
model.populations[{mio::sseirvv::InfectionState::RecoveredV1}] = 0;
47+
model.populations[{mio::sseirvv::InfectionState::RecoveredV2}] = 0;
48+
model.populations[{mio::sseirvv::InfectionState::ExposedV1V2}] = 0;
4949
model.populations[{mio::sseirvv::InfectionState::InfectedV1V2}] = 0;
5050
model.populations[{mio::sseirvv::InfectionState::RecoveredV1V2}] = 0;
5151
model.populations[{mio::sseirvv::InfectionState::Susceptible}] =
52-
total_population -
53-
model.populations[{mio::sseirvv::InfectionState::ExposedV1}] -
52+
total_population - model.populations[{mio::sseirvv::InfectionState::ExposedV1}] -
5453
model.populations[{mio::sseirvv::InfectionState::ExposedV2}] -
5554
model.populations[{mio::sseirvv::InfectionState::InfectedV1}] -
5655
model.populations[{mio::sseirvv::InfectionState::InfectedV2}] -
@@ -60,14 +59,14 @@ int main()
6059
model.populations[{mio::sseirvv::InfectionState::InfectedV1V2}] -
6160
model.populations[{mio::sseirvv::InfectionState::RecoveredV1V2}];
6261

63-
// It is assumed that both variants have the same transmission probability
62+
// It is assumed that both variants have the same transmission probability
6463
// on contact and the same time exposed. The time infected is scaled by
6564
// 1.35 for the second variant.
6665
model.parameters.get<mio::sseirvv::ContactPatterns>().get_baseline()(0, 0) = 1;
6766
model.parameters.set<mio::sseirvv::TransmissionProbabilityOnContactV1>(0.076);
6867
model.parameters.set<mio::sseirvv::TransmissionProbabilityOnContactV2>(0.076);
6968
model.parameters.set<mio::sseirvv::TimeExposedV1>(5.33);
70-
model.parameters.set<mio::sseirvv::TimeExposedV2>(5.33);
69+
model.parameters.set<mio::sseirvv::TimeExposedV2>(5.33);
7170
model.parameters.set<mio::sseirvv::TimeInfectedV1>(17.2);
7271
model.parameters.set<mio::sseirvv::TimeInfectedV2>(17.2 * 1.35);
7372

@@ -81,7 +80,8 @@ int main()
8180
model.populations[{mio::sseirvv::InfectionState::InfectedV2}] = 100;
8281
// Simulate the model from tmid to tmax, now with both variants.
8382
auto sseirv2 = mio::sseirvv::simulate(tmid, tmax, dt, model);
84-
85-
sseirv.print_table({"Susceptible", "ExposedV1", "InfectedV1", "RecoveredV1", "ExposedV2", "InfectedV2", "RecoveredV2", "ExposedV1V2", "InfectedV1V2", "RecoveredV1V2"});
86-
sseirv2.print_table({"Susceptible", "ExposedV1", "InfectedV1", "RecoveredV1", "ExposedV2", "InfectedV2", "RecoveredV2", "ExposedV1V2", "InfectedV1V2", "RecoveredV1V2"});
83+
sseirv.print_table({"Susceptible", "ExposedV1", "InfectedV1", "RecoveredV1", "ExposedV2", "InfectedV2",
84+
"RecoveredV2", "ExposedV1V2", "InfectedV1V2", "RecoveredV1V2"});
85+
sseirv2.print_table({"Susceptible", "ExposedV1", "InfectedV1", "RecoveredV1", "ExposedV2", "InfectedV2",
86+
"RecoveredV2", "ExposedV1V2", "InfectedV1V2", "RecoveredV1V2"});
8787
}

cpp/examples/sde_sirs.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* See the License for the specific language governing permissions and
1818
* limitations under the License.
1919
*/
20-
20+
#include "memilio/data/analyze_result.h"
2121
#include "memilio/utils/logging.h"
2222
#include "sde_sirs/model.h"
2323
#include "sde_sirs/simulation.h"
@@ -52,5 +52,8 @@ int main()
5252

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

55-
ssirs.print_table({"Susceptible", "Infected", "Recovered"});
55+
// interpolate results
56+
auto interpolated_results = mio::interpolate_simulation_result(ssirs);
57+
58+
interpolated_results.print_table({"Susceptible", "Infected", "Recovered"});
5659
}

0 commit comments

Comments
 (0)