The kairos-pylib crate provides Python bindings for the Kairos engine via PyO3 and maturin . The resulting kairos_engine Python module exposes the simulation engine for batch experiments, trace analysis, and integration testing.
# Development install (editable, linked to source)
# Build wheel for distribution
pip install target/wheels/kairos_engine- * .whl
Requires Python 3.9+. No runtime dependencies beyond the compiled extension module.
from kairos_engine import EngineConfig
Parameter Default Description columns25Grid width rows17Grid height lambda_0.65Lambda parameter (trailing underscore avoids Python keyword conflict) gamma0.1Gamma parameter enable_ghost_tracesTrueEnable ghost trace computation
Properties: config.columns, config.rows.
from kairos_engine import Engine, EngineConfig
engine = Engine ( EngineConfig () , start_x = 0.0 , start_y = 0.0 )
Method Description set_seed(seed: int)Set RNG seed get_seed() -> intGet current seed set_lambda(v: float)Set λ \lambda λ parameter get_lambda() -> floatGet λ \lambda λ parameter set_gamma(v: float)Set γ \gamma γ parameter get_gamma() -> floatGet γ \gamma γ parameter set_grid_size(columns: int, rows: int)Override grid dimensions
Method Returns Description get_state()dictCurrent engine state (t, b, lastMove, marker) get_warning()dictWarning signal (active, level, kind, metrics)
Method Returns Description decide_next_move()strPolicy-decided move: "left", "stay", or "right" decide_all_moves()dictMapping of agent IDs to moves run_tick(move: str)dictExecute single tick with the given move run_tick_multi(moves: dict)dictExecute multi-agent tick
Method Returns Description start_recording(scenario_id=None)None Begin trace recording stop_recording()dict or NoneEnd recording and return trace export_trace(steps: int, scenario_id=None)dictConvenience: record N auto-decided ticks and return trace
Method Description load_scenario(scenario)Load from dict or JSON string load_event_script(events)Load EDMS event script
from kairos_engine import load_trace_file, save_trace_file, diff_traces_py
trace = load_trace_file ( " trace.json " )
save_trace_file ( trace , " output.json " )
result = diff_traces_py ( trace_a , trace_b , epsilon = 1e-6 )
All complex data (state, warnings, traces) crosses the Python/Rust boundary as Python dicts via JSON round-trip serialization. The overhead is negligible for typical workloads.
from kairos_engine import Engine, EngineConfig, save_trace_file
config = EngineConfig ( columns = 25 , rows = 17 )
for seed in range ( 1000 , 2000 ):
trace = engine. export_trace ( steps = 500 , scenario_id = " standard " )
save_trace_file ( trace , f "traces/standard_ {seed} .json" )
from kairos_engine import Engine, EngineConfig, diff_traces_py
engine_a = Engine ( config )
trace_a = engine_a. export_trace ( steps = 200 , scenario_id = " standard " )
engine_b = Engine ( config )
trace_b = engine_b. export_trace ( steps = 200 , scenario_id = " standard " )
result = diff_traces_py ( trace_a , trace_b , epsilon = 1e-6 )
assert result[ " identical " ], " Traces should be identical for the same seed "
Each Engine instance is not thread-safe — do not share a single instance across threads. Multiple independent engines on separate threads are supported.