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//!
40pub mod context;
41pub use context::{Context, ExecutionPhase, IxaEvent, PluginContext};
42
43mod data_plugin;
44pub use data_plugin::*;
45
46pub mod error;
47pub use error::IxaError;
48
49pub mod global_properties;
50pub use global_properties::{ContextGlobalPropertiesExt, GlobalProperty};
51
52pub mod network;
53pub use network::{ContextNetworkExt, Edge, EdgeType};
54
55pub mod people;
56pub use people::{
57 ContextPeopleExt, PersonCreatedEvent, PersonId, PersonProperty, PersonPropertyChangeEvent,
58};
59
60pub mod plan;
61pub mod random;
62pub use random::{ContextRandomExt, RngId};
63
64pub mod tabulator;
65pub use tabulator::Tabulator;
66
67pub mod report;
68pub use report::{ConfigReportOptions, ContextReportExt, Report};
69
70pub mod runner;
71pub use runner::{run_with_args, run_with_custom_args, BaseArgs};
72
73#[cfg(feature = "debugger")]
74pub mod debugger;
75
76pub mod log;
77pub use log::{
78 debug, disable_logging, enable_logging, error, info, set_log_level, set_module_filter,
79 set_module_filters, trace, warn, LevelFilter,
80};
81
82#[cfg(feature = "progress_bar")]
83pub mod progress;
84
85#[cfg(feature = "debugger")]
86pub mod external_api;
87mod hashing;
88pub mod numeric;
89
90#[cfg(feature = "web_api")]
91pub mod web_api;
92
93// Re-export for macros
94pub use csv;
95pub use ctor;
96pub use paste;
97pub use rand;
98
99// Deterministic hashing data structures
100pub use crate::hashing::{HashMap, HashMapExt, HashSet, HashSetExt};
101
102// Preludes
103pub mod prelude;
104
105pub mod prelude_for_plugins {
106 pub use crate::context::PluginContext;
107 pub use crate::define_data_plugin;
108 pub use crate::error::IxaError;
109 pub use crate::prelude::*;
110 pub use crate::IxaEvent;
111 pub use ixa_derive::IxaEvent;
112}
113
114pub mod execution_stats;
115
116#[cfg(all(target_arch = "wasm32", feature = "debugger"))]
117compile_error!(
118 "Target `wasm32` and feature `debugger` are mutually exclusive — enable at most one."
119);
120
121#[cfg(all(target_arch = "wasm32", feature = "progress_bar"))]
122compile_error!(
123 "Target `wasm32` and feature `progress_bar` are mutually exclusive — enable at most one."
124);
125
126// The following is a workaround for an ICE involving wasm-bindgen:
127// https://github.com/CDCgov/ixa/actions/runs/16283417455/job/45977349528?pr=464
128#[cfg(target_family = "wasm")]
129use wasm_bindgen::prelude::wasm_bindgen;
130
131// See: https://github.com/rustwasm/wasm-bindgen/issues/4446
132#[cfg(target_family = "wasm")]
133mod wasm_workaround {
134 extern "C" {
135 pub(super) fn __wasm_call_ctors();
136 }
137}
138
139// See: https://github.com/rustwasm/wasm-bindgen/issues/4446
140#[cfg(target_family = "wasm")]
141#[wasm_bindgen(start)]
142fn start() {
143 // fix:
144 // Error: Read a negative address value from the stack. Did we run out of memory?
145 #[cfg(target_family = "wasm")]
146 unsafe {
147 wasm_workaround::__wasm_call_ctors()
148 };
149}