babylon.engine.simdb
Simulation database module (ephemeral per-run state).
The simulation database stores ephemeral state during simulation runs: - Agent state snapshots per tick - Production events (c/v/s tensor) - Network graph edges - Territorial control and heat dynamics - Aggregate metrics per tick
This database is separate from the reference database (immutable federal statistical data) and is created fresh for each simulation run.
Implements ADR030 (Unified SQLite Runtime Architecture) - uses SQLite instead of the previous DuckDB implementation.
- Usage:
from babylon.engine.simdb import SimulationDB
# In-memory for testing with SimulationDB(in_memory=True) as sim:
sim.record_tick_summary(tick=0, total_c=100, total_v=50, …)
# File-based for production (persists to data/runs/) with SimulationDB(run_id=”experiment_001”) as sim:
# Record simulation state sim.con.execute(“INSERT INTO agent_state VALUES (…)”)
- Architecture:
- Reference DB (SQLite) ── Immutable federal data (3NF)
(census, QCEW, geography)
- Simulation DB (SQLite) ── Ephemeral per-run state
Created fresh, discarded after analysis
- class babylon.engine.simdb.SimulationDB(run_id=None, in_memory=False, attach_reference=True)[source]
Bases:
objectEphemeral SQLite database for simulation state.
Each simulation run creates a fresh database (or uses in-memory). Implements ADR030 (Unified SQLite Runtime) and ADR031 (Tick-Keyed Temporal Tables).
- run_id
Unique identifier for this simulation run.
- db_path
Path to the SQLite file (None for in-memory).
- con
sqlite3 connection handle.
- __exit__(exc_type, exc_val, exc_tb)[source]
Context manager exit.
- Return type:
- Parameters:
exc_type (type[BaseException] | None)
exc_val (BaseException | None)
exc_tb (object)
- __init__(run_id=None, in_memory=False, attach_reference=True)[source]
Initialize simulation database.
- Parameters:
- Return type:
None
- record_tick_summary(tick, total_c, total_v, total_s, avg_consciousness, uprising_count)[source]
Record aggregate metrics for a simulation tick.
- Parameters:
tick (
int) – Simulation tick number.total_c (
float) – Total constant capital (c).total_v (
float) – Total variable capital/wages (v).total_s (
float) – Total surplus value (s).avg_consciousness (
float) – Average class consciousness [0,1].uprising_count (
int) – Number of uprising events this tick.
- Return type:
Modules
Simulation database (ephemeral SQLite per-run). |
|
Simulation database schema (ephemeral per-run state). |