Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gce ixa runner nocustom #34

Merged
merged 6 commits into from
Dec 27, 2024
Merged
Changes from 2 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
101 changes: 40 additions & 61 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,77 +3,56 @@ mod parameters;
mod population_loader;
mod transmission_manager;

use clap::Args;
use ixa::runner::run_with_custom_args;
use ixa::{
Context, ContextGlobalPropertiesExt, ContextPeopleExt, ContextRandomExt, ContextReportExt,
IxaError,
};
use std::path::PathBuf;
use ixa::runner::run_with_args;
use ixa::{ContextGlobalPropertiesExt, ContextPeopleExt, ContextRandomExt, ContextReportExt};
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<Context, IxaError> {
let mut context = run_with_custom_args(|context, args, custom_args: Option<CustomArgs>| {
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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can actually remove this entirely, the options get set automatically


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)
}

fn main() {
let mut context = initialize().expect("Error initializing.");
context.execute();
}
Loading