Gymnasium¶
GymnaxToGymWrapper ¶
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.
observation_space
property
¶
Gymnasium observation space for the current parameters.
step ¶
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 emptyinfodictionary.
render ¶
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_observation_space
property
¶
Gymnasium observation space of a single environment.
observation_space
property
¶
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 emptyinfodictionary.
step ¶
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 the first environment if the environment defines render.
Returns None otherwise. mode is accepted for compatibility and ignored.