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