babylon.engine.hydration
Hydration package for initializing simulation state from reference data.
- class babylon.engine.hydration.CountyInfo(county_id, fips, county_name)[source]
Bases:
objectCounty metadata from dim_county.
- __init__(county_id, fips, county_name)
- class babylon.engine.hydration.StubBEASource[source]
Bases:
objectStub BEA source that returns None, letting DepartmentMapper provide defaults.
The MarxianHydrator falls back to sector-level ratios from DepartmentMapper when the BEA source returns None.
- babylon.engine.hydration.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.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.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.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.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.
- babylon.engine.hydration.query_hex_claims(county_ids, session=None)[source]
Fetch H3 cells from bridge_county_h3 for given counties.
Modules
MVP Simulation Engine hydrator for SQLite reference data. |