babylon.models.types
Constrained value types for the Babylon simulation.
These Annotated type aliases provide runtime validation for numeric values. Using Pydantic v2’s Annotated pattern allows these types to be used directly in any BaseModel field.
- Types defined:
Probability: [0.0, 1.0] - for P(S|A), P(S|R), tension Ideology: [-1.0, 1.0] - revolutionary to reactionary spectrum Currency: [0.0, inf) - wealth, wages, rent, GDP Intensity: [0.0, 1.0] - contradiction intensity Coefficient: [0.0, 1.0] - formula parameters (alpha, lambda, k) Ratio: (0.0, inf) - wage ratios, exchange ratios EntityProtocol: Protocol for entities with lifecycle state (Sprint 1.X D2)
- Usage:
from babylon.models.types import Probability, Currency
- class SurvivalState(BaseModel):
p_acquiescence: Probability # Automatically validated [0, 1] wealth: Currency # Automatically validated [0, inf)
All types serialize to plain floats in JSON for compatibility with the Ledger (SQLite) and NetworkX graph storage.
- Epoch 0 Physics Hardening (Gatekeeper Pattern):
All constrained types apply SnapToGrid quantization via AfterValidator. Values are snapped to a 10^-5 grid (0.00001 resolution) to prevent floating-point drift accumulation over long simulations.
Module Attributes
[0.0, 1.0] |
|
[-1.0, 1.0] |
|
[0.0, inf) |
|
[0.0, 1.0] |
|
[0.0, 1.0] |
|
(0.0, inf) |
|
[0.0, inf) |
|
(-inf, +inf) |
|
[0.0, 1.0] |
Classes
|
Protocol for entities with lifecycle state. |
- babylon.models.types.Probability
[0.0, 1.0]
A probability represents the likelihood of an event occurring. Used for: - P(S|A): Probability of survival through acquiescence - P(S|R): Probability of survival through revolution - tension: Contradiction tension level
Boundary values: - 0.0 = impossible event - 1.0 = certain event
Note: Values are quantized to 10^-5 precision via SnapToGrid.
- Type:
Probability
alias of
Annotated[float, FieldInfo(annotation=NoneType, required=True, description=’Value in range [0.0, 1.0] representing likelihood’, metadata=[Ge(ge=0.0), Le(le=1.0)]),AfterValidator(func=quantize)]
- babylon.models.types.Ideology
[-1.0, 1.0]
A class’s ideological position on the revolutionary-reactionary spectrum. Based on consciousness drift formula: dPsi_c/dt = k(1 - Wc/Vc) - lambda*Psi_c
Boundary values: - -1.0 = fully revolutionary (class conscious, anti-capitalist) - +1.0 = fully reactionary (false consciousness, pro-status-quo) - 0.0 = neutral/apolitical
Note: Values are quantized to 10^-5 precision via SnapToGrid.
- Type:
Ideology
alias of
Annotated[float, FieldInfo(annotation=NoneType, required=True, description=’Ideological position from revolutionary (-1) to reactionary (+1)’, metadata=[Ge(ge=-1.0), Le(le=1.0)]),AfterValidator(func=quantize)]
- babylon.models.types.Currency
[0.0, inf)
Economic value that cannot be negative. Used for: - wealth: Accumulated resources - wages: Payment for labor - rent: Imperial rent (Phi) - GDP: Aggregate output
Note: Debt is not modeled as negative currency but as a separate relationship/obligation between entities.
Note: Values are quantized to 10^-5 precision via SnapToGrid.
- Type:
Currency
alias of
Annotated[float, FieldInfo(annotation=NoneType, required=True, description=’Non-negative economic value (wealth, wages, rent, GDP)’, metadata=[Ge(ge=0.0)]),AfterValidator(func=quantize)]
- babylon.models.types.Intensity
[0.0, 1.0]
The intensity of a dialectical contradiction. When intensity reaches 1.0, the contradiction triggers a phase transition (synthesis, rupture, or suppression).
Boundary values: - 0.0 = dormant (contradiction exists but not manifest) - 1.0 = rupture threshold (phase transition imminent)
Note: Values are quantized to 10^-5 precision via SnapToGrid.
- Type:
Intensity
alias of
Annotated[float, FieldInfo(annotation=NoneType, required=True, description=’Contradiction intensity from dormant (0) to rupture (1)’, metadata=[Ge(ge=0.0), Le(le=1.0)]),AfterValidator(func=quantize)]
- babylon.models.types.Coefficient
[0.0, 1.0]
A parameter that modifies the strength of an effect in formulas. Used for: - alpha: Extraction efficiency in imperial rent - lambda: Decay rate in consciousness drift - k: Sensitivity coefficient in survival calculus
Boundary values: - 0.0 = no effect - 1.0 = maximum effect
Note: Values are quantized to 10^-5 precision via SnapToGrid.
- Type:
Coefficient
alias of
Annotated[float, FieldInfo(annotation=NoneType, required=True, description=’Formula parameter in range [0, 1]’, metadata=[Ge(ge=0.0), Le(le=1.0)]),AfterValidator(func=quantize)]
- babylon.models.types.Ratio
(0.0, inf)
A ratio comparing two quantities. Zero is invalid because ratios typically represent division results.
Used for: - Wc/Vc: Labor aristocracy ratio (wages to value produced) - epsilon: Exchange ratio in unequal exchange
Interpretation: - Ratio = 1.0: Equal exchange / fair wages - Ratio > 1.0: Core receives more than it gives (exploitation) - Ratio < 1.0: Core receives less than it gives
Note: Values are quantized to 10^-5 precision via SnapToGrid.
- Type:
Ratio
alias of
Annotated[float, FieldInfo(annotation=NoneType, required=True, description=’Positive ratio comparing two quantities’, metadata=[Gt(gt=0.0)]),AfterValidator(func=quantize)]
- babylon.models.types.LaborHours
[0.0, inf)
Labor-time measurement in hours. Used for the fundamental tensor primitive where all economic values are expressed in labor-time, not monetary units.
Used for: - Primitive tensor cells (c, v, s components) - Aggregated labor-time values - SNLT-converted wage data
The distinction from Currency is semantic: Currency represents monetary value, LaborHours represents socially necessary labor time (SNLT).
Note: Values are quantized to 10^-6 precision via SnapToGrid.
- Type:
LaborHours
alias of
Annotated[float, FieldInfo(annotation=NoneType, required=True, description=’Non-negative labor-time measurement in hours’, metadata=[Ge(ge=0.0)]),AfterValidator(func=quantize)]
- babylon.models.types.SignedLaborHours
(-inf, +inf)
Labor-time measurement that can be negative. Used for derived tensors where negative values have economic meaning.
Used for: - Imperial rent (Φ): Positive = core (receiving rent), Negative = periphery (donating rent) - Net value flows between territories - Derived economic calculations
Unlike LaborHours, this type permits negative values because: - Negative imperial rent indicates periphery status (donating more value than receiving) - Net flows can be negative (outflow > inflow)
Note: Values are quantized to 10^-6 precision via SnapToGrid.
- Type:
SignedLaborHours
alias of
Annotated[float, FieldInfo(annotation=NoneType, required=True, description=’Labor-time measurement allowing negative values’),AfterValidator(func=quantize)]
- babylon.models.types.Gini
[0.0, 1.0]
Intra-class inequality coefficient (Mass Line Refactor). Determines what fraction of wealth the marginal worker (bottom 40%) receives.
Used for: - inequality: Intra-class wealth distribution within a demographic block
Boundary values: - 0.0 = Perfect equality (mean = median, everyone gets equal share) - 1.0 = Maximum tyranny (Pareto extreme: bottom majority has nothing)
- The Grinding Attrition Formula uses this to calculate marginal wealth:
marginal_wealth = per_capita_wealth × (1 - gini)
At gini=0: marginal_wealth = average (all survive if average suffices) At gini=1: marginal_wealth = 0 (marginal workers always starve)
Note: Values are quantized to 10^-5 precision via SnapToGrid.
- Type:
Gini
alias of
Annotated[float, FieldInfo(annotation=NoneType, required=True, description=’Gini coefficient measuring intra-class inequality’, metadata=[Ge(ge=0.0), Le(le=1.0)]),AfterValidator(func=quantize)]
- class babylon.models.types.EntityProtocol(*args, **kwargs)[source]
Bases:
ProtocolProtocol for entities with lifecycle state.
Any object implementing this protocol can be checked for death using is_dead() or similar lifecycle functions. This prevents type errors where floats, dicts, or other non-entity types are accidentally passed to lifecycle functions.
- Implementors:
SocialClass: Has active field (True = alive, False = dead)
Sprint 1.X D2 Pain Point #3: Loose typing allowed bugs like is_dead(float) instead of is_dead(Entity).
Example
>>> from babylon.models.types import EntityProtocol >>> from babylon.models import SocialClass >>> >>> worker = SocialClass(id="C001", name="Worker", ...) >>> isinstance(worker, EntityProtocol) # True >>> is_dead(worker) # Works >>> >>> is_dead(0.5) # TypeError: expected EntityProtocol
- __init__(*args, **kwargs)