evorl.envs.gymnasium¶
Module Contents¶
Classes¶
Adapter for Gymnasium to support Gymnasium environments. |
|
Vectorized one-episode wrapper for evaluation. |
Functions¶
Create a gym env based on Gymnasium. |
|
API¶
- class evorl.envs.gymnasium.GymnasiumAdapter(env_name: str, max_episode_steps: int, num_envs: int, record_ori_obs: bool = False, discount: float | None = None, vecenv_kwargs: dict | None = None, **env_kwargs)[source]¶
Bases:
evorl.envs.env.EnvAdapterAdapter for Gymnasium to support Gymnasium environments.
This env already is a vectorized environment and has experimental supports. It is not recommended to direcly replace other jax-based envs with this env in EvoRL’s existing workflows. Users should carefully check the compatibility and modify the corresponding code to avoid the side-effects and other undefined behaviors.
Caution
This env breaks the rule of pure functions. Its env state is maintained inside the gymnasium. Thesefore, users should use it with caution. Unlike other jax-based envs, this env has following limitations:
No support for recovering from previous env state.
In other word, you can’t rewind after calling
env.step.For example, you can’t resume the training from a checkpoint exactly as before; Similarly,
evorl.rollout.eval_rollout_episodewill also result in undefined behavior.
We use gymnasium’s
AsyncVectorEnv, which uses python’smultiprocessingpackage for parallelism. This may cause performance issues, especially when the number of parallel environments is large.We recommend that the total number of parallel environments does not exceed the number of CPU logic cores.
- property action_space: evorl.envs.space.Space¶
- property obs_space: evorl.envs.space.Space¶
- reset(key: chex.PRNGKey) evorl.envs.env.EnvState[source]¶
- step(state: evorl.envs.env.EnvState, action: evorl.types.Action) evorl.envs.env.EnvState[source]¶
- class evorl.envs.gymnasium.OneEpisodeWrapper(env: evorl.envs.env.Env)[source]¶
Bases:
evorl.envs.wrappers.WrapperVectorized one-episode wrapper for evaluation.
- step(state: evorl.envs.env.EnvState, action: evorl.types.Action) evorl.envs.env.EnvState[source]¶
- evorl.envs.gymnasium.create_gymnasium_env(env_name, episode_length: int = 1000, parallel: int = 1, autoreset_mode: evorl.envs.wrappers.AutoresetMode = AutoresetMode.ENVPOOL, discount: float | None = 1.0, record_ori_obs: bool = False, **kwargs) evorl.envs.gymnasium.GymnasiumAdapter[source]¶
Create a gym env based on Gymnasium.
Unlike other jax-based env, most wrappers are handled inside the gymnasium.
- evorl.envs.gymnasium.gymnasium_space_to_evorl_space(space: gymnasium.Space) evorl.envs.space.Space[source]¶