Simulation#
Main simulation facade for BAM Engine.
This module provides the Simulation class, the primary interface for running BAM (Bottom-Up Adaptive Macroeconomics) simulations. The Simulation class manages the economy state, agent roles, event pipeline, and provides methods for stepping through periods.
Key Features#
Three-tier configuration precedence (defaults → user config → kwargs)
Deterministic random number generation with seed control
Event pipeline with explicit ordering and YAML configuration
Getter methods for roles, events, and relationships (case-insensitive)
In-place state mutation for memory efficiency
Built-in logging configuration at global and per-event levels
Classes#
- Simulation
Main simulation facade for initializing and running BAM simulations.
See also
Examples
Basic simulation with default configuration:
>>> import bamengine as bam
>>> sim = bam.Simulation.init(seed=42)
>>> sim.run(n_periods=100)
>>> unemployment = np.mean(~sim.wrk.employed)
Custom configuration via YAML file:
>>> sim = bam.Simulation.init(config="my_config.yml", seed=42)
>>> sim.run(n_periods=100)
Override specific parameters via kwargs:
>>> sim = bam.Simulation.init(n_firms=200, n_households=1000, seed=42)
>>> sim.run(n_periods=100)
Step-by-step execution with intermediate analysis:
>>> sim = bam.Simulation.init(seed=42)
>>> for period in range(100):
... sim.step()
... if period % 10 == 0:
... print(f"Period {period}: Unemployment = {np.mean(~sim.wrk.employed):.2%}")
The bamengine.simulation module provides the main interface for running
BAM simulations.
Classes#
Main simulation facade for BAM Engine. |
|
Container for simulation results with convenient data access methods. |
Key Methods#
Simulation Methods
Create a new Simulation instance with validated configuration. |
|
Run the simulation for multiple periods. |
|
Execute one simulation period through the event pipeline. |
|
Get role instance by name. |
|
Get event instance from pipeline by name. |
|
Get relationship instance by name. |
|
Apply an extension bundle to the simulation. |
|
Instantiate and attach a custom role to the simulation. |
|
Register a custom relationship class. |
|
Apply event hooks to the simulation pipeline. |
|
Apply extension default configuration. |
Results Methods
Export results to a pandas DataFrame. |
|
Get data for a specific role as a DataFrame. |
|
Deprecated: use |
|
Unified access to all data (roles + economy + relationships). |
|
Get data for a specific relationship as a DataFrame. |
|
Get economy-wide metrics as a DataFrame. |
|
Get summary statistics for key metrics. |