Skip to content

Gymnasium

GymnaxToGymWrapper

GymnaxToGymWrapper(env: Environment, params: EnvParams | None = None, seed: int | None = None)

Bases: Env[ObsType, ActType]

Wrap a Gymnax environment as a stateful gymnasium.Env.

The wrapper stores the environment state, parameters and PRNG key, so step only takes an action. The wrapped environment still resets automatically when an episode ends.

Parameters:

  • env (Environment) –

    Gymnax environment to wrap.

  • params (EnvParams | None, default: None ) –

    Environment parameters. Defaults to env.default_params.

  • seed (int | None, default: None ) –

    Seed for the PRNG key. Defaults to 0.

action_space property

action_space

Gymnasium action space for the current parameters.

observation_space property

observation_space

Gymnasium observation space for the current parameters.

step

step(action: ActType) -> tuple[core.ObsType, float, bool, bool, dict[Any, Any]]

Take one step and update the stored state.

Parameters:

  • action (ActType) –

    Action to take.

Returns:

  • tuple[ObsType, float, bool, bool, dict[Any, Any]] –

    A tuple (obs, reward, terminated, truncated, info).

reset

reset(*, seed: int | None = None, return_info: bool = False, options: Any | None = None) -> tuple[core.ObsType, Any]

Start a new episode.

Parameters:

  • seed (int | None, default: None ) –

    If given, reseeds the PRNG key before resetting.

  • return_info (bool, default: False ) –

    Accepted for compatibility and ignored.

  • options (Any | None, default: None ) –

    If it contains the key "env_params", its value replaces the stored environment parameters.

Returns:

  • tuple[ObsType, Any] –

    A tuple (obs, info) with an empty info dictionary.

render

render(mode='human') -> core.RenderFrame | list[core.RenderFrame] | None

Render the current state if the environment defines render.

Returns None otherwise. mode is accepted for compatibility and ignored.

GymnaxToVectorGymWrapper

GymnaxToVectorGymWrapper(env: Environment, num_envs: int = 1, params: EnvParams | None = None, seed: int | None = None)

Bases: VectorEnv

Wrap a Gymnax environment as a stateful gymnasium.vector.VectorEnv.

Runs num_envs copies of the environment in parallel with jax.vmap. All copies share the same parameters and each has its own PRNG key.

Parameters:

  • env (Environment) –

    Gymnax environment to wrap.

  • num_envs (int, default: 1 ) –

    Number of environments to run in parallel.

  • params (EnvParams | None, default: None ) –

    Environment parameters. Defaults to env.default_params.

  • seed (int | None, default: None ) –

    Seed for the PRNG keys. Defaults to 0.

single_action_space property

single_action_space

Gymnasium action space of a single environment.

single_observation_space property

single_observation_space

Gymnasium observation space of a single environment.

action_space property

action_space

Batched Gymnasium action space of all environments.

observation_space property

observation_space

Batched Gymnasium observation space of all environments.

reset

reset(*, seed: int | Sequence[int] | None = None, return_info: bool = False, options: Any | None = None)

Reset all environments.

Parameters:

  • seed (int | Sequence[int] | None, default: None ) –

    If given, reseeds the PRNG keys before resetting. An integer is split into one key per environment. A sequence of integers (list, tuple or array) seeds each environment independently and must have length num_envs.

  • return_info (bool, default: False ) –

    Accepted for compatibility and ignored.

  • options (Any | None, default: None ) –

    If it contains the key "env_params", its value replaces the stored environment parameters.

Returns:

  • tuple –

    A tuple (obs, info) with batched observations and an empty info dictionary.

step

step(action)

Step all environments and update the stored states.

Parameters:

  • action (Array) –

    Batch of actions, one per environment.

Returns:

  • tuple –

    A tuple (obs, reward, terminated, truncated, info) of batched arrays.

render

render(mode='human') -> core.RenderFrame | list[core.RenderFrame] | None

Render the first environment if the environment defines render.

Returns None otherwise. mode is accepted for compatibility and ignored.