From 4e0b250918cb03f2ed63e295733b1c99cdd2b6bd Mon Sep 17 00:00:00 2001 From: Guido Espana Date: Mon, 23 Dec 2024 18:54:50 +0000 Subject: [PATCH 1/6] Update runner from ixa to not use custom arguments --- src/main.rs | 103 ++++++++++++++++++++++------------------------------ 1 file changed, 43 insertions(+), 60 deletions(-) diff --git a/src/main.rs b/src/main.rs index 55bf1c0..5f04d44 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,77 +3,60 @@ mod parameters; mod population_loader; mod transmission_manager; -use clap::Args; -use ixa::runner::run_with_custom_args; +use ixa::runner::run_with_args; use ixa::{ - Context, ContextGlobalPropertiesExt, ContextPeopleExt, ContextRandomExt, ContextReportExt, - IxaError, + ContextGlobalPropertiesExt, ContextPeopleExt, ContextRandomExt, + ContextReportExt, }; -use std::path::PathBuf; use transmission_manager::InfectiousStatus; use crate::parameters::Parameters; use crate::population_loader::{Age, CensusTract}; -#[derive(Args, Debug)] -struct CustomArgs { - ///Whether force overwrite of output files if they already exist - #[arg(short = 'f', long)] - force_overwrite: bool, -} - -fn initialize() -> Result { - let mut context = run_with_custom_args(|context, args, custom_args: Option| { +fn main() { + + run_with_args(|context, args, _| { // Read the global properties. - let custom_args = custom_args.unwrap(); // Set the output directory and whether to overwrite the existing file. context .report_options() - .directory(PathBuf::from(&args.output_dir)) - .overwrite(custom_args.force_overwrite); + .directory(args.output_dir.unwrap()) + .overwrite(args.force_overwrite); + + let parameters = context + .get_global_property_value(Parameters) + .unwrap() + .clone(); + + // Set the random seed. + context.init_random(parameters.seed); + + // Report the number of people by age, census tract, and infectious status + // every report_period. + context.add_periodic_report( + "person_property_count", + parameters.report_period, + (Age, CensusTract, InfectiousStatus), + )?; + + // Load the synthetic population from the `synthetic_population_file` + // specified in input.json. + population_loader::init(context)?; + context.index_property(Age); + context.index_property(CensusTract); + + // Initialize the person-to-person transmission workflow. + transmission_manager::init(context); + + // Add a plan to shut down the simulation after `max_time`, regardless of + // what else is happening in the model. + context.add_plan(parameters.max_time, |context| { + context.shutdown(); + }); + + // Print out the parameters for debugging purposes for the user. + println!("{parameters:?}"); Ok(()) - }) - .unwrap(); - - let parameters = context - .get_global_property_value(Parameters) - .unwrap() - .clone(); - - // Set the random seed. - context.init_random(parameters.seed); - - // Report the number of people by age, census tract, and infectious status - // every report_period. - context.add_periodic_report( - "person_property_count", - parameters.report_period, - (Age, CensusTract, InfectiousStatus), - )?; - - // Load the synthetic population from the `synthetic_population_file` - // specified in input.json. - population_loader::init(&mut context)?; - context.index_property(Age); - context.index_property(CensusTract); - - // Initialize the person-to-person transmission workflow. - transmission_manager::init(&mut context); - - // Add a plan to shut down the simulation after `max_time`, regardless of - // what else is happening in the model. - context.add_plan(parameters.max_time, |context| { - context.shutdown(); - }); - - // Print out the parameters for debugging purposes for the user. - println!("{parameters:?}"); - - // Return context for execution. - Ok(context) + }).unwrap(); } -fn main() { - let mut context = initialize().expect("Error initializing."); - context.execute(); -} From d2133a49844551b0a4e3ca6c6a8a57089f1ea98e Mon Sep 17 00:00:00 2001 From: Guido Espana Date: Mon, 23 Dec 2024 18:56:04 +0000 Subject: [PATCH 2/6] Pre-commit fixes --- src/main.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index 5f04d44..e77c1ab 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,17 +4,13 @@ mod population_loader; mod transmission_manager; use ixa::runner::run_with_args; -use ixa::{ - ContextGlobalPropertiesExt, ContextPeopleExt, ContextRandomExt, - ContextReportExt, -}; +use ixa::{ContextGlobalPropertiesExt, ContextPeopleExt, ContextRandomExt, ContextReportExt}; use transmission_manager::InfectiousStatus; use crate::parameters::Parameters; use crate::population_loader::{Age, CensusTract}; fn main() { - run_with_args(|context, args, _| { // Read the global properties. // Set the output directory and whether to overwrite the existing file. @@ -57,6 +53,6 @@ fn main() { // Print out the parameters for debugging purposes for the user. println!("{parameters:?}"); Ok(()) - }).unwrap(); + }) + .unwrap(); } - From 638eccdbbe1edd38c6563be502203948bb9d0004 Mon Sep 17 00:00:00 2001 From: Guido Espana Date: Fri, 27 Dec 2024 21:30:19 +0000 Subject: [PATCH 3/6] remove unnecessary options --- src/main.rs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index e77c1ab..39b51ed 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,14 +11,8 @@ use crate::parameters::Parameters; use crate::population_loader::{Age, CensusTract}; fn main() { - run_with_args(|context, args, _| { + run_with_args(|context, _, _| { // Read the global properties. - // Set the output directory and whether to overwrite the existing file. - context - .report_options() - .directory(args.output_dir.unwrap()) - .overwrite(args.force_overwrite); - let parameters = context .get_global_property_value(Parameters) .unwrap() From ceec69c5bb1dabed1b3e77dda67cacc232e7719f Mon Sep 17 00:00:00 2001 From: Guido Espana Date: Fri, 27 Dec 2024 21:40:29 +0000 Subject: [PATCH 4/6] remove unused import --- src/transmission_manager.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/transmission_manager.rs b/src/transmission_manager.rs index 3d7a52e..3b57d6e 100644 --- a/src/transmission_manager.rs +++ b/src/transmission_manager.rs @@ -1,5 +1,5 @@ use ixa::{ - define_person_property, define_person_property_with_default, define_rng, Context, + define_person_property_with_default, define_rng, Context, ContextGlobalPropertiesExt, ContextPeopleExt, ContextRandomExt, IxaError, PersonId, PersonPropertyChangeEvent, }; From 3cb1a304c1244815a3ccc962ad31ea10ab462600 Mon Sep 17 00:00:00 2001 From: Guido Espana Date: Fri, 27 Dec 2024 21:56:00 +0000 Subject: [PATCH 5/6] updating ixa --- src/transmission_manager.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/transmission_manager.rs b/src/transmission_manager.rs index 3b57d6e..07bf755 100644 --- a/src/transmission_manager.rs +++ b/src/transmission_manager.rs @@ -1,7 +1,7 @@ use ixa::{ - define_person_property_with_default, define_rng, Context, - ContextGlobalPropertiesExt, ContextPeopleExt, ContextRandomExt, IxaError, PersonId, - PersonPropertyChangeEvent, + define_person_property_with_default, define_rng, + Context, ContextGlobalPropertiesExt, + ContextPeopleExt, ContextRandomExt, IxaError, PersonId, PersonPropertyChangeEvent, }; use statrs::distribution::{ContinuousCDF, Exp, Poisson}; From f6a74d9d18414736c98d96220c0b32921675c075 Mon Sep 17 00:00:00 2001 From: Guido Espana Date: Fri, 27 Dec 2024 21:59:38 +0000 Subject: [PATCH 6/6] pre-commit fixes --- src/transmission_manager.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/transmission_manager.rs b/src/transmission_manager.rs index 07bf755..2c18221 100644 --- a/src/transmission_manager.rs +++ b/src/transmission_manager.rs @@ -1,6 +1,5 @@ use ixa::{ - define_person_property_with_default, define_rng, - Context, ContextGlobalPropertiesExt, + define_person_property_with_default, define_rng, Context, ContextGlobalPropertiesExt, ContextPeopleExt, ContextRandomExt, IxaError, PersonId, PersonPropertyChangeEvent, }; use statrs::distribution::{ContinuousCDF, Exp, Poisson};