babylon.engine.context

Context models for simulation tick execution.

This module provides typed context objects that replace raw dict[str, Any] for passing tick-level information between Systems during simulation.

The TickContext maintains backward compatibility with dict-style access while providing type safety for known keys.

Classes

TickContext(**data)

Typed context for a single simulation tick.

class babylon.engine.context.TickContext(**data)[source]

Bases: BaseModel

Typed context for a single simulation tick.

Provides type-safe access to tick-level information while maintaining backward compatibility with dict-style access via __getitem__.

Parameters:
tick

Current simulation tick number.

persistent_data

Data that persists across ticks (e.g., previous_wages for the bifurcation mechanic in ConsciousnessSystem).

displacement_mode

Optional override for territory displacement routing in TerritorySystem.

Example:

>>> ctx = TickContext(tick=5)
>>> ctx.tick
5
>>> ctx["tick"]  # Backward compatible dict access
5
>>> ctx.get("tick", 0)  # Dict-style get with default
5
>>> ctx.persistent_data["previous_wages"] = {"worker": 100.0}
>>> "previous_wages" in ctx
True
model_config: ClassVar[ConfigDict] = {'extra': 'allow'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

tick: int
persistent_data: dict[str, Any]
displacement_mode: DisplacementPriorityMode | None
__getitem__(key)[source]

Enable dict-style read access for backward compatibility.

Parameters:

key (str) – Attribute name to access.

Return type:

Any

Returns:

Attribute value, or value from persistent_data if not a direct attribute.

Raises:

KeyError – If key not found in attributes or persistent_data.

__setitem__(key, value)[source]

Enable dict-style write access for backward compatibility.

Parameters:
  • key (str) – Attribute name to set.

  • value (Any) – Value to assign.

Return type:

None

__contains__(key)[source]

Check if key exists in context.

Parameters:

key (object) – Key to check for existence.

Return type:

bool

Returns:

True if key is a known attribute or in persistent_data.

get(key, default=None)[source]

Dict-compatible get method with default value.

Parameters:
  • key (str) – Key to look up.

  • default (Any) – Value to return if key not found.

Return type:

Any

Returns:

Value for key, or default if not found.