ixa/lib.rs
1//! A framework for building discrete-event simulations
2//!
3//! Ixa is a framework designed to support the creation of large-scale
4//! discrete event simulations. The primary use case is the construction of
5//! agent-based models for disease transmission, but the approach is applicable
6//! in a wide array of circumstances.
7//!
8//! The central object of an Ixa simulation is the `Context` that is
9//! responsible for managing all the behavior of the simulation. All of the
10//! simulation-specific logic is embedded in modules that rely on the `Context`
11//! for core services such as:
12//! * Maintaining a notion of time for the simulation
13//! * Scheduling events to occur at some point in the future and executing them
14//! at that time
15//! * Holding module-specific data so that the module and other modules can
16//! access it
17//!
18//! In practice, a simulation usually consists of a set of modules that work
19//! together to provide all of the functions of the simulation. For instance,
20//! a simple disease transmission model might consist of the
21//! following modules:
22//! * A population loader that initializes the set of people represented
23//! by the simulation.
24//! * An infection seeder that introduces the pathogen into the population.
25//! * A disease progression manager that transitions infected people through
26//! stages of disease until recovery.
27//! * A transmission manager that models the process of an infected
28//! person trying to infect susceptible people in the population.
29//!
30//! ## Features
31//!
32//! - **`debugger`**: enables the interactive debugger, an interactive console-based REPL
33//! (Read-Eval-Print Loop) that allows you to pause simulation execution, inspect state, and
34//! control simulation flow through commands like breakpoints, population queries, and
35//! step-by-step execution.
36//! - **`web_api`**: enables the web API, an HTTP-based remote control interface that allows
37//! external applications to monitor simulation state, control execution, and query data through
38//! REST endpoints. This feature implies the `debugger` feature.
39
40#![doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/docs/cli-usage.md"))]
41
42pub mod context;
43pub use context::{Context, ContextBase, ExecutionPhase, IxaEvent};
44
45mod plugin_context;
46pub use plugin_context::PluginContext;
47
48mod data_plugin;
49pub use data_plugin::*;
50
51pub mod error;
52pub use error::IxaError;
53
54pub mod global_properties;
55pub use global_properties::{ContextGlobalPropertiesExt, GlobalProperty};
56
57pub mod network;
58pub use network::{ContextNetworkExt, Edge, EdgeType};
59
60pub mod people;
61pub use people::{
62 ContextPeopleExt, PersonCreatedEvent, PersonId, PersonProperty, PersonPropertyChangeEvent,
63};
64
65pub mod plan;
66pub mod random;
67pub use random::{ContextRandomExt, RngId};
68
69pub mod tabulator;
70pub use tabulator::Tabulator;
71
72pub mod report;
73pub use report::{ConfigReportOptions, ContextReportExt, Report};
74
75pub mod runner;
76pub use runner::{run_with_args, run_with_custom_args, BaseArgs};
77
78#[cfg(feature = "debugger")]
79pub mod debugger;
80
81pub mod log;
82pub use log::{
83 debug, disable_logging, enable_logging, error, info, set_log_level, set_module_filter,
84 set_module_filters, trace, warn, LevelFilter,
85};
86
87#[cfg(feature = "progress_bar")]
88pub mod progress;
89
90#[cfg(feature = "debugger")]
91pub mod external_api;
92mod hashing;
93pub mod numeric;
94
95#[cfg(feature = "web_api")]
96pub mod web_api;
97
98// Re-export for macros
99pub use csv;
100pub use ctor;
101pub use paste;
102pub use rand;
103
104// Deterministic hashing data structures
105pub use crate::hashing::{HashMap, HashMapExt, HashSet, HashSetExt};
106
107// Preludes
108pub mod prelude;
109
110pub mod prelude_for_plugins {
111 pub use crate::context::ContextBase;
112 pub use crate::define_data_plugin;
113 pub use crate::error::IxaError;
114 pub use crate::prelude::*;
115 pub use crate::IxaEvent;
116 pub use ixa_derive::IxaEvent;
117}
118
119pub mod execution_stats;
120
121#[cfg(all(target_arch = "wasm32", feature = "debugger"))]
122compile_error!(
123 "Target `wasm32` and feature `debugger` are mutually exclusive — enable at most one."
124);
125
126#[cfg(all(target_arch = "wasm32", feature = "progress_bar"))]
127compile_error!(
128 "Target `wasm32` and feature `progress_bar` are mutually exclusive — enable at most one."
129);
130
131// The following is a workaround for an ICE involving wasm-bindgen:
132// https://github.com/CDCgov/ixa/actions/runs/16283417455/job/45977349528?pr=464
133#[cfg(target_family = "wasm")]
134use wasm_bindgen::prelude::wasm_bindgen;
135
136// See: https://github.com/rustwasm/wasm-bindgen/issues/4446
137#[cfg(target_family = "wasm")]
138mod wasm_workaround {
139 extern "C" {
140 pub(super) fn __wasm_call_ctors();
141 }
142}
143
144// See: https://github.com/rustwasm/wasm-bindgen/issues/4446
145#[cfg(target_family = "wasm")]
146#[wasm_bindgen(start)]
147fn start() {
148 // fix:
149 // Error: Read a negative address value from the stack. Did we run out of memory?
150 #[cfg(target_family = "wasm")]
151 unsafe {
152 wasm_workaround::__wasm_call_ctors()
153 };
154}