Skip to content

gds_sim.types

Runtime type aliases, state update blocks, and hooks.

Type definitions for gds-sim.

State = dict[str, Any] module-attribute

Runtime state — plain dict for speed.

Signal = dict[str, Any] module-attribute

Policy output signal dict.

Params = dict[str, Any] module-attribute

Parameter dict for a single subset.

PolicyFn = Callable[..., Signal] module-attribute

Policy function: (state, params, **kw) -> Signal.

SUFn = Callable[..., tuple[str, Any]] module-attribute

State update function: (state, params, signal=, **kw) -> (key, value).

BeforeRunHook = Callable[[State, Params], None] module-attribute

Called before a run starts: (initial_state, params) -> None.

AfterRunHook = Callable[[State, Params], None] module-attribute

Called after a run completes: (final_state, params) -> None.

AfterStepHook = Callable[[State, int], bool | None] module-attribute

Called after each timestep: (state, timestep) -> False to stop early.

HistoryOption = int | Literal['full'] | None module-attribute

State history window: None=off, int=last N, 'full'=all.

StateUpdateBlock

Bases: BaseModel

A partial state update block: policies produce signals, SUFs update state.

Source code in packages/gds-sim/gds_sim/types.py
class StateUpdateBlock(BaseModel):
    """A partial state update block: policies produce signals, SUFs update state."""

    model_config = ConfigDict(arbitrary_types_allowed=True, frozen=True)

    policies: dict[str, PolicyFn] = {}
    variables: dict[str, SUFn]

Hooks

Bases: BaseModel

Lifecycle hooks for a simulation run.

Source code in packages/gds-sim/gds_sim/types.py
class Hooks(BaseModel):
    """Lifecycle hooks for a simulation run."""

    model_config = ConfigDict(arbitrary_types_allowed=True, frozen=True)

    before_run: BeforeRunHook | None = None
    after_run: AfterRunHook | None = None
    after_step: AfterStepHook | None = None