Skip to content

Compatibility

sekai.compat bridges sekai and gymnasium, and multi-agent sekai envs and PettingZoo. The bridges need the optional dependencies: pip install "sekai[gymnasium]", or pip install "sekai[pettingzoo]" (which includes gymnasium). See Migrating from gymnasium and Multi-agent.

Functions

to_gymnasium

to_gymnasium(env: Any, renderer: Any = None, render_mode: str | None = None) -> Any

Wrap a sekai Env as a gymnasium.Env (spaces converted, tuples returned).

from_gymnasium

from_gymnasium(env: Any) -> Any

Wrap a gymnasium.Env as a sekai Env (StepResult/ResetResult returned).

space_to_gymnasium

space_to_gymnasium(space: Any) -> Any

Convert a sekai space to the equivalent gymnasium space.

space_from_gymnasium

space_from_gymnasium(space: Any) -> Any

Convert a gymnasium space to the equivalent sekai space.

to_pettingzoo

to_pettingzoo(env: Any) -> Any

Wrap a sekai MultiAgentEnv as a PettingZoo ParallelEnv.

from_pettingzoo

from_pettingzoo(env: Any) -> Any

Wrap a PettingZoo ParallelEnv as a sekai MultiAgentEnv.

Classes

These are importable from sekai.compat (loaded on first access).

SekaiToGymnasium

SekaiToGymnasium(env: Env[Any, Any], renderer: Any = None, render_mode: str | None = None)

Bases: Env[Any, Any]

Exposes a sekai Env through the gymnasium API.

Use it to train sekai environments with gymnasium-based libraries (Stable-Baselines3, CleanRL, RLlib, ...). Pass a renderer to support render(): render_mode defaults to "rgb_array"; pass render_mode="ansi" explicitly for a renderer that returns text. "human" is not supported, as sekai renderers return frames instead of opening a window; wrap the result in gymnasium.wrappers.HumanRendering to display "rgb_array" frames.

GymnasiumToSekai

GymnasiumToSekai(env: Env[Any, Any])

Bases: Env[Any, Any]

Exposes a gymnasium Env through the sekai API.

The gymnasium env keeps its own RNG; seeds passed to reset() go straight to it, and self.rng is the gymnasium env's np_random. A NumPy integer seed is passed on as an int; a Generator becomes the gymnasium env's np_random (gymnasium's reset() itself only takes int seeds).

GymnasiumRenderer

A sekai Renderer that calls a wrapped gymnasium env's own render().

SekaiToPettingZoo

SekaiToPettingZoo(env: MultiAgentEnv[Any, Any, Any])

Bases: ParallelEnv

Exposes a sekai MultiAgentEnv through PettingZoo's Parallel API.

Spaces are converted to gymnasium spaces; results become the usual (observations, rewards, terminations, truncations, infos) dicts. Event-driven sekai envs (e.g. LimitOrderBookMarket) return observations only for the agents that act next, which a strict Parallel-API consumer may not expect; their rewards and flags still cover every agent.

PettingZooToSekai

PettingZooToSekai(env: Any)

Bases: MultiAgentEnv[Any, Any, Any]

Exposes a PettingZoo ParallelEnv through the sekai MultiAgentEnv API.

The PettingZoo env keeps its own randomness; seeds passed to reset() go straight to it (a NumPy integer as an int). PettingZoo has no standard way to hand an env a Generator, so a Generator seed raises TypeError.