babylon.models.snapshots
Snapshot types for the MVP simulation engine.
These are immutable representations of simulation state at a point in time. They are designed for the GUI interface and differ from internal simulation entities which may be mutable.
Available types: - HexState: Immutable geographic cell (H3 index only for MVP) - EdgeState: Relationship snapshot (source, target, type, weight) - TerritoryState: Territory state at a specific tick - SimulationSnapshot: Complete simulation state container
All types are Pydantic models with validation.
See also
data-model.md: Entity definitions and validation rules
contracts/simulation_state.py: Protocol that returns these types
Classes
|
Relationship snapshot between entities at a specific tick. |
|
Immutable geographic cell snapshot. |
|
Complete simulation state at a specific tick. |
|
Edge types for simulation snapshots. |
|
Territory state snapshot at a specific tick. |
- class babylon.models.snapshots.HexState(**data)[source]
Bases:
BaseModelImmutable geographic cell snapshot.
Hexes are the invariant substrate - they don’t change during simulation. For MVP, HexState contains only the H3 index. Future versions may add physical properties (terrain, resources).
- Parameters:
h3_index (str)
- h3_index
H3 cell index (15-char hex string, resolution 5).
- model_config: ClassVar[ConfigDict] = {'frozen': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- h3_index: str
- class babylon.models.snapshots.EdgeState(**data)[source]
Bases:
BaseModelRelationship snapshot between entities at a specific tick.
- Parameters:
source_id (str)
target_id (str)
edge_type (SnapshotEdgeType)
- source_id
ID of the source entity.
- target_id
ID of the target entity.
- edge_type
Relationship type.
- weight
Edge weight (default 1.0).
- model_config: ClassVar[ConfigDict] = {'frozen': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- source_id: str
- target_id: str
- edge_type: SnapshotEdgeType
- weight: float
- class babylon.models.snapshots.TerritoryState(**data)[source]
Bases:
BaseModelTerritory state snapshot at a specific tick.
This is the GUI-facing representation of a territory.
- Parameters:
- territory_id
Unique identifier (FIPS code for counties).
- controlling_polity
Current controller (equals territory_id for MVP).
- hex_claims
Set of H3 indices this territory claims.
- tick
Tick number when this snapshot was taken.
- profit_rate
Current profit rate, range [0.0, 1.0].
- equilibrium_r
Territory-specific equilibrium (= initial_r at hydration).
- model_config: ClassVar[ConfigDict] = {'frozen': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- territory_id: str
- controlling_polity: str
- hex_claims: frozenset[str]
- tick: int
- profit_rate: float
- equilibrium_r: float
- tensor_year: int | None
- validate_hex_claims_patterns()[source]
Validate all H3 indices in hex_claims match pattern.
- Return type:
- classmethod with_clamped_profit_rate(territory_id, controlling_polity, hex_claims, tick, profit_rate, equilibrium_r, tensor_year=None)[source]
Create TerritoryState with profit_rate clamped to [0.0, 1.0].
If profit_rate is outside valid range, it is clamped and a warning is logged.
- Parameters:
territory_id (
str) – FIPS code.controlling_polity (
str) – Controller ID.tick (
int) – Current tick.profit_rate (
float) – Computed profit rate (may be out of range).equilibrium_r (
float) – Territory-specific equilibrium.tensor_year (
int|None) – Year for tensor lookup (may differ from tick). None if no tensor data.
- Return type:
- Returns:
TerritoryState with clamped profit_rate.
- class babylon.models.snapshots.SimulationSnapshot(**data)[source]
Bases:
BaseModelComplete simulation state at a specific tick.
This is the top-level container returned by get_snapshot().
- Parameters:
- tick
Current tick number.
- territories
Map of territory_id to TerritoryState.
- hexes
Map of h3_index to HexState (invariant substrate).
- edges
List of EdgeState relationships (empty for MVP).
- tensor_registry
Optional reference to TensorRegistry for cached tensor data access without database queries.
- model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'frozen': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- tick: int
- territories: dict[str, TerritoryState]
- hexes: dict[str, HexState]
- edges: list[EdgeState]
- tensor_registry: Any