babylon.engine.hydration.reference
MVP Simulation Engine hydrator for SQLite reference data.
This module provides hydration functions to initialize simulation state from the reference database (marxist-data-3NF.sqlite). It bridges the gap between raw federal statistical data and simulation-ready TerritoryState objects.
- Key Functions:
query_counties: Fetch county metadata from dim_county
query_hex_claims: Fetch H3 cells from bridge_county_h3
compute_initial_profit_rate: Calculate profit_rate from QCEW/BEA data
hydrate_territories: Create TerritoryState objects from database
See also
research.md#3. SQLite Reference Database Schema
research.md#4. Economics Hydrator
plan.md#Hydration Flow
Functions
|
Compute initial profit_rate from QCEW/BEA data. |
|
Derive class distribution shares from QCEW employment data. |
|
Derive economy constants from QCEW/BEA data. |
|
Hydrate industry hyperedges from SQLite reference database. |
|
Derive reserve army parameters from QCEW employment data. |
|
Hydrate territories from SQLite reference database. |
|
Fetch county metadata from dim_county. |
|
Fetch H3 cells from bridge_county_h3 for given counties. |
Classes
|
County metadata from dim_county. |
Stub BEA source that returns None, letting DepartmentMapper provide defaults. |
- class babylon.engine.hydration.reference.CountyInfo(county_id, fips, county_name)[source]
Bases:
objectCounty metadata from dim_county.
- babylon.engine.hydration.reference.compute_initial_profit_rate(fips, year)[source]
Compute initial profit_rate from QCEW/BEA data.
Uses MarxianHydrator to compute c, v, s, then derives profit_rate.
profit_rate = s / (c + v)
- Where:
s = surplus value (total across departments) c = constant capital (total across departments) v = variable capital (total across departments)
- Parameters:
- Return type:
- Returns:
Profit rate in range [0.0, 1.0] (clamped if necessary).
- Raises:
ValueError – If QCEW data is missing for the county.
Derive class distribution shares from QCEW employment data.
Uses wage percentile analysis of QCEW data to estimate the class structure for a given county. Falls back to GameDefines defaults if data is unavailable.
- babylon.engine.hydration.reference.hydrate_economy_constants(fips, year)[source]
Derive economy constants from QCEW/BEA data.
Computes extraction_efficiency (s/(c+v)) and related constants from the MarxianHydrator tensor decomposition.
- babylon.engine.hydration.reference.hydrate_industry_hyperedges(fips_codes, year=2022)[source]
Hydrate industry hyperedges from SQLite reference database.
- babylon.engine.hydration.reference.hydrate_reserve_army(fips, year)[source]
Derive reserve army parameters from QCEW employment data.
Uses county-level employment data to estimate the baseline unemployment rate for the sigmoid_r0 parameter.
- babylon.engine.hydration.reference.hydrate_territories(fips_codes, year=2022)[source]
Hydrate territories from SQLite reference database.
This is the main entry point for initializing simulation state from the reference database.
- Parameters:
- Returns:
territories: Dict mapping territory_id (FIPS) to TerritoryState
hexes: Dict mapping h3_index to HexState
- Return type:
Tuple of (territories, hexes)
- Raises:
ValueError – If fips_codes is empty or any county is not found.
- babylon.engine.hydration.reference.query_counties(fips_codes, session=None)[source]
Fetch county metadata from dim_county.
- Parameters:
- Return type:
- Returns:
Dict mapping FIPS code to CountyInfo.
- Raises:
ValueError – If any requested FIPS code is not found.