Examples#
Example scripts demonstrating BAM Engine usage patterns.
The examples are organized into three sections:
Basic: Getting started tutorials for new users
Advanced: Custom components and pipeline modifications
Extensions: Scenarios from the BAM literature
These examples are simplified demonstrations focused on teaching core concepts.
For detailed analysis with validation bounds and statistical annotations, see
the validation package:
# Baseline scenario with full validation
python -m validation.scenarios.baseline
# Growth+ scenario with full validation
python -m validation.scenarios.growth_plus
Basic Examples#
Start here if you’re new to BAM Engine. These examples demonstrate fundamental concepts and basic usage patterns.
Examples in this section:
Hello World: The simplest possible BAM Engine example - initialize, run, and visualize
Configuration: Customize simulation parameters using keyword arguments
YAML Configuration: Configure simulations using YAML files
Logging: Configure logging levels globally and per-event
BAM Operations: Comprehensive guide to the ops module for NumPy-free array operations
Type System: Using Float, Int, Bool, Agent type aliases for custom roles
Simulation Results: Comprehensive guide to SimulationResults for data collection
Baseline Scenario: Simplified baseline scenario from section 3.9.1 of the original BAM book
These examples will teach you:
How to initialize and run a basic simulation
How to configure simulation parameters via kwargs and YAML files
How to collect and visualize simulation results
How to compare different economic scenarios
How to reproduce scenarios from the BAM literature
How to use type aliases for extending BAM Engine
How to configure and use the logging system
Note: The baseline scenario example is a simplified demonstration. For full validation with target bounds and statistical annotations, run:
python -m validation.scenarios.baseline
Advanced Examples#
Examples showing advanced features like custom events, roles, relationships, and pipeline configuration. These examples require familiarity with the basic concepts covered in the basic examples.
Examples in this section:
Custom Roles: Define new agent components with the
@roledecoratorCustom Events: Create custom events with the
@eventdecoratorCustom Relationships: Define many-to-many relationships with edge data
Custom Pipeline: Customize the event execution pipeline via YAML
Ops Module: NumPy-free operations for custom event logic
These examples will teach you:
How to extend the model with custom agent behaviors using roles
How to create custom economic events and policies
How to define relationships between roles with edge-specific data
How to modify the event execution order
How to use the ops module for safe array operations
How to integrate custom components into simulations
Prerequisites#
Before working through these examples, make sure you’re comfortable with:
Basic simulation setup (see basic/example_hello_world.py)
Configuration via kwargs (see basic/example_configuration.py)
Results collection (see basic/example_results_module.py)
Type aliases (see basic/example_typing_module.py)
Extension Examples#
Examples demonstrating extensions from the original BAM model (Delli Gatti et al., 2011).
These examples reproduce research extensions from the BAM book:
Growth+ Model: R&D investment and endogenous productivity growth. Demonstrates how to create custom roles and events to extend BAM Engine.
Consumption and Buffer Shock: Household consumption shocks and savings buffer dynamics
Parameter Space Exploration: Systematic exploration of model sensitivity to key parameters
Preferential Attachment: Preferential attachment in consumption and firm entry mechanisms
Each example includes detailed explanations of the economic mechanisms and comparison with results from the original literature.
Note: The Growth+ example is a simplified demonstration focused on teaching how to create custom extensions. For full validation with target bounds and statistical annotations, run:
python -m validation.scenarios.growth_plus