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:

  1. Hello World: The simplest possible BAM Engine example - initialize, run, and visualize

  2. Configuration: Customize simulation parameters using keyword arguments

  3. YAML Configuration: Configure simulations using YAML files

  4. Logging: Configure logging levels globally and per-event

  5. BAM Operations: Comprehensive guide to the ops module for NumPy-free array operations

  6. Type System: Using Float, Int, Bool, Agent type aliases for custom roles

  7. Simulation Results: Comprehensive guide to SimulationResults for data collection

  8. 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

Hello BAM Engine

Hello BAM Engine

Configuring Your Simulation

Configuring Your Simulation

YAML Configuration

YAML Configuration

Logging

Logging

BAM Operations

BAM Operations

Type System

Type System

Simulation Results

Simulation Results

BAM Baseline Scenario

BAM Baseline Scenario

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:

  1. Custom Roles: Define new agent components with the @role decorator

  2. Custom Events: Create custom events with the @event decorator

  3. Custom Relationships: Define many-to-many relationships with edge data

  4. Custom Pipeline: Customize the event execution pipeline via YAML

  5. 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)

Custom Roles

Custom Roles

Custom Events

Custom Events

Custom Relationships

Custom Relationships

Custom Pipeline

Custom Pipeline

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

Growth+ Model Extension

Growth+ Model Extension

Buffer-Stock Consumption Extension

Buffer-Stock Consumption Extension

Robustness Analysis

Robustness Analysis

Gallery generated by Sphinx-Gallery