babylon.engine.simulation_engine
Simulation engine for the Babylon game loop.
ADR032: Materialist Causality System Order
The step() function is the core of Phase 2. It takes a WorldState and SimulationConfig and returns a new WorldState representing one tick of simulation time.
The step function is: - Pure: No side effects, no mutation of inputs - Deterministic: Same inputs always produce same outputs - Transparent: Order of operations encodes historical materialism
Turn Order (materialist causality - base before superstructure): 1. Vitality - Biological cost + death (dead entities don’t work) 2. Territory - Land state updates (land conditions affect production) 3. Production - Value creation (value must exist before extraction) 4. Solidarity - Organization (affects bargaining power) 5. Imperial Rent - Value extraction (landlord eats after harvest) 6. Decomposition - LA decomposes on super-wage crisis (Terminal Crisis) 7. Control Ratio - Guard:prisoner ratio + terminal decision (Terminal Crisis) 8. Metabolism - Environmental degradation (ecological residue of production) 9. Survival - Risk assessment (P(S|A), P(S|R) from material state) 10. Struggle - Action/Revolt (agency responds to survival odds) 11. Consciousness - Ideological drift (ideology responds to material) 12. Contradiction - Tension aggregation (final systemic accounting)
Phase 2.1: Refactored to modular System architecture. Phase 4a: Refactored to use ServiceContainer for dependency injection. ADR032: Reordered systems for materialist causality.
Functions
|
Advance simulation by one tick using the modular engine. |
Classes
|
Modular engine that advances the simulation by iterating through Systems. |
- class babylon.engine.simulation_engine.SimulationEngine(systems, *, auditor=None)[source]
Bases:
objectModular engine that advances the simulation by iterating through Systems.
The engine holds a list of systems and executes them in sequence. Order encodes materialist causality (ADR032): 1. Vitality (death check) 2. Territory (land state) 3. Production (value creation) 4. Solidarity (organization) 5. Imperial Rent (extraction) 6. Decomposition (LA crisis) 7. Control Ratio (terminal decision) 8. Metabolism (ecology) 9. Survival (risk assessment) 10. Struggle (agency) 11. Consciousness (ideology) 12. Contradiction (tension) 13. ContradictionField (field computation) - Feature 002 14. FieldDerivative (derivatives + principal) - Feature 002 15. EdgeTransition (predicates + state machine) - Feature 002
- __init__(systems, *, auditor=None)[source]
Initialize the engine with a list of systems.
- Parameters:
systems (
list[System]) – Ordered list of systems to execute each tick. Order matters! Economic systems must run before ideology.auditor (
Any) – Optional Spec 062 ConservationAuditor. When provided, runs at end-of-tick (after all systems) and emits any alarm-severity audit rows onto the event bus per FR-047. When None, audit step is skipped — preserves backward compatibility with pre-spec-062 callers.
- Return type:
None
- property per_system_ms: dict[str, float]
Cumulative wallclock (ms) per system class name.
Spec-065 T074. Reset via
reset_per_system_ms()between runs if the same engine instance is reused.
- run_tick(graph, services, context)[source]
Execute all systems in order for one tick.
All logs emitted during this method are automatically tagged with tick number and a unique correlation_id (UUID) for tracing.
Spec 062, T068: when
self._auditoris set, theConservationAuditorruns after every system completes. Alarm-severity rows are published asConservationAlarmEventinstances onto the event bus.- Parameters:
graph (
BabylonGraph) – NetworkX graph (mutated in place by systems)services (
ServicesProtocol) – ServicesProtocol with config, formulas, event_bus, database, metricscontext (
Union[dict[str,Any],TickContext]) – TickContext or dict passed to all systems
- Return type:
Spec 008: Logs within run_tick() include tick and correlation_id.
- babylon.engine.simulation_engine.step(state, config, persistent_context=None, defines=None, calculator_overrides=None)[source]
Advance simulation by one tick using the modular engine.
This is the heart of Phase 2. It transforms a WorldState through one tick of simulated time by applying the MLM-TW formulas.
- Parameters:
state (
WorldState) – Current world state (immutable)config (
SimulationConfig) – Simulation configuration with formula coefficientspersistent_context (
dict[str,Any] |None) – Optional context dict that persists across ticks. Used by systems that need to track state between ticks (e.g., ConsciousnessSystem’s previous_wages for bifurcation mechanic).defines (
GameDefines|None) – Optional custom GameDefines. If None, loads from default defines.yaml location. Use this for scenario-specific calibration.calculator_overrides (
dict[str,Any] |None) – Optional dict of calculator instances to inject into ServiceContainer (e.g., melt_calculator, tensor_registry).
- Return type:
- Returns:
New WorldState at tick + 1
- Order encodes historical materialism:
Economic base (value extraction)
Consciousness (responds to material conditions)
Survival calculus (probability updates)
Contradictions (tension from all above)
Event capture (log significant changes)