babylon.engine.simulation_engine

Simulation engine for the Babylon game loop.

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 (encodes historical materialism): 1. Economic Base - Value extraction (imperial rent) 2. Consciousness - Ideology drift based on material conditions 3. Survival Calculus - P(S|A) and P(S|R) updates 4. Contradiction Tension - Accumulated from wealth gaps 5. Event Logging - Record significant state changes

Phase 2.1: Refactored to modular System architecture. Phase 4a: Refactored to use ServiceContainer for dependency injection.

Functions

step(state, config[, persistent_context, ...])

Advance simulation by one tick using the modular engine.

Classes

SimulationEngine(systems)

Modular engine that advances the simulation by iterating through Systems.

class babylon.engine.simulation_engine.SimulationEngine(systems)[source]

Bases: object

Modular engine that advances the simulation by iterating through Systems.

The engine holds a list of systems and executes them in sequence. Order encodes historical materialism: 1. Economic Base (imperial rent) 2. Consciousness (ideology drift) 3. Survival Calculus (probability updates) 4. Contradiction (tension dynamics)

Parameters:

systems (list[System])

__init__(systems)[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.

Return type:

None

property systems: list[System]

Read-only access to registered systems.

run_tick(graph, services, context)[source]

Execute all systems in order for one tick.

Parameters:
  • graph – NetworkX graph (mutated in place by systems)

  • services – ServiceContainer with config, formulas, event_bus, database

  • context – TickContext or dict passed to all systems

babylon.engine.simulation_engine.step(state, config, persistent_context=None, defines=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 coefficients

  • persistent_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.

Return type:

WorldState

Returns:

New WorldState at tick + 1

Order encodes historical materialism:
  1. Economic base (value extraction)

  2. Consciousness (responds to material conditions)

  3. Survival calculus (probability updates)

  4. Contradictions (tension from all above)

  5. Event capture (log significant changes)