NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
PyPI · #2080 most downloaded on PyPI
A standard API for reinforcement learning and a diverse set of reference environments (formerly Gym).
Last release 5 months ago
22 Apr 2026
Ships fairly regularly
a new release about every 3 months
Nearly every release is documented
notes for 17 of 17 stable releases
1 version withdrawn
withdrawn after publishing
5 years old
20 releases · first in 2021
One column per quarter.
This release brings a new Taxi environment version, a new RepeatAction wrapper, and a range of bug fixes across vector environments and wrappers.
This release brings a new Taxi environment version, a new RepeatAction wrapper, and a range of bug fixes across vector environments and wrappers.
Taxi environment has been updated to v4 to correct the is_rainy implementation, which previously did not behave as documented by @pseudo-rnd-thoughts (#1561)pygame has been replaced with pygame-ce, unlocking Python 3.14 compatibility. The drop-in replacement preserves the existing rendering behaviour by @mwydmuch (#1512)RepeatAction wrapper that repeats a given action for a fixed number of steps, useful for frame-skipping and coarser control loops by @Lidang-Jiang (#1553)Box.__init__ to reduce overhead through lazy evaluation of variables by @pseudo-rnd-thoughts (#1529)RecordVideo wrapper to remove memory leaks across episodes by @JonahFSD (#1527)NormalizeReward wrapper to work identically as the non-vectorized version by @JonahFSD (#1526)VectorEnv destructor, which was causing VectorEnv.close() to be called unintentionally by @TimSchneider42 (#1522)NormalizeObservation vectorized wrapper to override the observation_space and a float32 cast by @JonahFSD (#1528)RenderFrame's typing by @jorenham (#1560)10 new community environments have been added to the third-party environments list, including a new Cybersecurity environments section.
Full Changelog: v1.2.3...v1.3.0
This is a minor release with the most significant being changing the dependency for "gymnasium[box2d]" from box2d-py to box2d . See #1474 for more det
This is a minor release with the most significant being changing the dependency for "gymnasium[box2d]" from box2d-py to box2d. See #1474 for more detail.
Additionally, we're fixed several typos and added a couple of third-party projects. Lastly, we fixed the create an environment tutorial to use NumPy [row, col] in #1490
Full Changelog: v1.2.2...v1.2.3
This is a minor update just to add Discrete.dtype and improve DictInfoToList
This is a minor update just to add Discrete.dtype and improve DictInfoToList
These additional changes were made
Discrete.dtype parameter by @VadimBim in https://github.com/Farama-Foundation/Gymnasium/pull/1467MultiDiscrete.dtype by @pseudo-rnd-thoughts in https://github.com/Farama-Foundation/Gymnasium/pull/1469DictInfoToList to support vector info with missing binary key by @pseudo-rnd-thoughts in https://github.com/Farama-Foundation/Gymnasium/pull/1466Thanks to Wispr for their support of the project
Full Changelog: https://github.com/Farama-Foundation/Gymnasium/compare/v1.2.1...v1.2.2
This is a minor update just to add Discrete.dtype and improve DictInfoToList
These additional changes were made
Discrete.dtype parameter by @VadimBim in #1467MultiDiscrete.dtype by @pseudo-rnd-thoughts in #1469DictInfoToList to support vector info with missing binary key by @pseudo-rnd-thoughts in #1466Thanks to Wispr for their support of the project
Full Changelog: v1.2.1...v1.2.2
Minor update that adds new wrappers, optimizes several environment functions and fixes several bugs.
Minor update that adds new wrappers, optimizes several environment functions and fixes several bugs.
gymnasium.wrappers.DiscretizeObservation and gymnasium.wrappers.DiscretizeAction) by @sparisi (#1411)RecordVideo wrapper that allows recording all sub-environments at the same time by @sparisi (#1418)AsyncVectorEnv.step from hanging forever by @matinmoezzi (#1419)Thank you to all the contributors
Full Changelog: v1.2.0...v1.2.1
In Gym v0.24 , v4 MuJoCo environments were added that used a different simulator (mujoco, not mujoco-py). Having been 3 years since v0.24 and with muj
In Gym v0.24, v4 MuJoCo environments were added that used a different simulator (mujoco, not mujoco-py).
Having been 3 years since v0.24 and with mujoco-py being unmaintained, it is limiting our ability to support Python 3.13.
Therefore, in this release, we have moved the MuJoCo v2 and v3 to the Gymnasium-Robotics project, meaning the users who cannot upgrade to the v4 or v5 MuJoCo environments should update their code to:
import gymnasium as gym
import gymnasium_robotics # `pip install "gymnasium-robotics[mujoco-py]"`
gym.register_envs(gymnasium_robotics) # optional
env = gym.make("Humanoid-v3")In addition, we have added support for Python 3.13 (and dropped Python 3.8 and 3.9 following NumPy and other projects).
AddWhiteNoise and ObstructView wrappers that add noise to RGB renderings either across the whole image or sections by @sparisi (#1243)wrappers.ArrayConversion, a generic conversion wrapper between Array API compatible frameworks (like NumPy, Torch, Jax, etc) by @amacati (#1333)noop_max>0 by @pseudo-rnd-thoughts (#1393)In addition, this release includes numerous updates to the documentation, most importantly to the introductory pages, with an aim to make them easier for new users of Gymnasium or RL to understand.
Full Changelog: v1.1.1...v1.2.0
Remove assert on metadata render modes for MuJoCo-based environments in mujoco_env.py
mujoco_env.py (https://github.com/Farama-Foundation/Gymnasium/pull/1328)wrappers.vector.NumpyToTorch to refer to numpy instead of jax by @pkuderov in https://github.com/Farama-Foundation/Gymnasium/pull/1319Full Changelog: https://github.com/Farama-Foundation/Gymnasium/compare/v1.1.0...v1.1.1
mujoco_env.py (#1328)wrappers.vector.NumpyToTorch to refer to numpy instead of jax by @pkuderov in #1319Full Changelog: v1.1.0...v1.1.1
In this release, we fix several bugs with Gymnasium v1.0 along with new features to improve the changes made.
In this release, we fix several bugs with Gymnasium v1.0 along with new features to improve the changes made.
With the release of Gymnasium v1.0, one of the major changes we made was to the vector environment implementation, improving how users interface with it and extend it. Some users noted that they required backward compatibility with how vector environments automatically reset sub-environments when they terminated or truncated, referred to as the autoreset mode or API. As a result, in v1.1, we have added support to the implemented vector environments (SyncVectorEnv and AsyncVectorEnv) and wrappers for all three possible modes: next-step, same-step and disabled. To know the type of autoreset mode used, it should be specified in the vector environment metadata, metadata["autoreset_mode"] as a gymnasium.vectors.AutoresetMode enum. For more information on the differences between the autoreset modes and how to use them, read https://farama.org/Vector-Autoreset-Mode.
In addition, we've added several helpful features
space.sample(mask=...), to logically mask out possible samples from spaces. #1310 adds probability masking for each space with space.sample(probability=...) to specify the probability of each sample, which is helpful for RL policies that output a probability distribution of actions.jax, torch and numpy with JaxToTorch, JaxToNumpy, NumpyToTorch, etc. In v1.1, we've improved the wrappers to work with rendering and to be compatible with the full dlpack API.JaxToNumpy, JaxToTorch and NumpyToTorch by @amacati (#1306)wrappers.vector.TransformObs/Action support for a single obs/action space argument by @howardh (#1288)AtariPreprocessing to support non-square observations by @li-plus (#1312)Wrapper and VectorWrapper error checking by @pseudo-rnd-thoughts (#1260)get_wrapper_attr / set_wrapper_attr for edge case by @duburcqa (#1293)rgb_array that is upside down by @pseudo-rnd-thoughts (#1264)OrderedDict key ordering in Dict space by @pseudo-rnd-thoughts (#1291)wrappers.vector.NumpyToTorch doesn't require jax to work by @pseudo-rnd-thoughts (#1308)env_spec_kwargs in make_vec by @TimSchneider42 (#1304)TimeAwareObservation support for environments without a spec by @pseudo-rnd-thoughts (#1289)env.close by @a-ayesh (#1283)Thanks to the 31 new contributors that contributed to this release with the Full Changelog: v1.0.0...v1.1.0
…with the additional new features, bug fixes, deprecation and documentation changes included.
Over the last few years, the volunteer team behind Gym and Gymnasium has worked to fix bugs, improve the documentation, add new features, and change the API where appropriate so that the benefits outweigh the costs. This is the complete release of v1.0.0, which will be the end of this road to change the project's central API (Env, Space, VectorEnv). In addition, the release has included over 200 PRs since 0.29.1, with many bug fixes, new features, and improved documentation. So, thank you to all the volunteers for their hard work that has made this possible. For the rest of these release notes, we include sections of core API changes, ending with the additional new features, bug fixes, deprecation and documentation changes included.
Finally, we have published a paper on Gymnasium, discussing its overall design decisions and more at https://arxiv.org/abs/2407.17032, which can be cited using the following:
@misc{towers2024gymnasium,
title={Gymnasium: A Standard Interface for Reinforcement Learning Environments},
author={Mark Towers and Ariel Kwiatkowski and Jordan Terry and John U. Balis and Gianluca De Cola and Tristan Deleu and Manuel Goulão and Andreas Kallinteris and Markus Krimmel and Arjun KG and Rodrigo Perez-Vicente and Andrea Pierré and Sander Schulhoff and Jun Jet Tai and Hannah Tan and Omar G. Younis},
year={2024},
eprint={2407.17032},
archivePrefix={arXiv},
primaryClass={cs.LG},
url={https://arxiv.org/abs/2407.17032},
}
Within Gym v0.23+ and Gymnasium v0.26 to v0.29, an undocumented feature for registering external environments behind the scenes has been removed. For users of Atari (ALE), Minigrid or HighwayEnv, then users could previously use the following code:
import gymnasium as gym
env = gym.make("ALE/Pong-v5")Despite Atari never being imported (i.e., import ale_py), users can still create an Atari environment. This feature has been removed in v1.0.0, which will require users to update to
import gymnasium as gym
import ale_py
gym.register_envs(ale_py) # optional, helpful for IDEs or pre-commit
env = gym.make("ALE/Pong-v5")Alternatively, users can use the following structure, module_name:env_id, ' so that the module is imported first before the environment is created. e.g., ale_py:ALE/Pong-v5`.
import gymnasium as gym
env = gym.make("ale_py:ALE/Pong-v5")To help users with IDEs (e.g., VSCode, PyCharm), when importing modules to register environments (e.g., import ale_py) this can cause the IDE (and pre-commit isort / black / flake8) to believe that the import is pointless and should be removed. Therefore, we have introduced gymnasium.register_envs as a no-op function (the function literally does nothing) to make the IDE believe that something is happening and the import statement is required.
To increase the sample speed of an environment, vectorizing is one of the easiest ways to sample multiple instances of the same environment simultaneously. Gym and Gymnasium provide the VectorEnv as a base class for this, but one of its issues has been that it inherited Env. This can cause particular issues with type checking (the return type of step is different for Env and VectorEnv), testing the environment type (isinstance(env, Env) can be true for vector environments despite the two acting differently) and finally wrappers (some Gym and Gymnasium wrappers supported Vector environments, but there are no clear or consistent API for determining which do or don't). Therefore, we have separated out Env and VectorEnv to not inherit from each other.
In implementing the new separate VectorEnv class, we have tried to minimize the difference between code using Env and VectorEnv along with making it more generic in places. The class contains the same attributes and methods as Env in addition to the attributes num_envs: int, single_action_space: gymnasium.Space and single_observation_space: gymnasium.Space. Further, we have removed several functions from VectorEnv that are not needed for all vector implementations: step_async, step_wait, reset_async, reset_wait, call_async and call_wait. This change now allows users to write their own custom vector environments, v1.0.0 includes an example vector cartpole environment that runs thousands of times faster written solely with NumPy than using Gymnasium's Sync vector environment.
To allow users to create vectorized environments easily, we provide gymnasium.make_vec as a vectorized equivalent of gymnasium.make. As there are multiple different vectorization options ("sync", "async", and a custom class referred to as "vector_entry_point"), the argument vectorization_mode selects how the environment is vectorized. This defaults to None such that if the environment has a vector entry point for a custom vector environment implementation, this will be utilized first (currently, Cartpole is the only environment with a vector entry point built into Gymnasium). Otherwise, the synchronous vectorizer is used (previously, the Gym and Gymnasium vector.make used asynchronous vectorizer as default). For more information, see the function docstring. We are excited to see other projects utilize this option to make creating their environments easier.
env = gym.make("CartPole-v1")
env = gym.wrappers.ClipReward(env, min_reward=-1, max_reward=3)
envs = gym.make_vec("CartPole-v1", num_envs=3)
envs = gym.wrappers.vector.ClipReward(envs, min_reward=-1, max_reward=3)Due to this split of Env and VectorEnv, there are now Env only wrappers and VectorEnv only wrappers in gymnasium.wrappers and gymnasium.wrappers.vector respectively. Furthermore, we updated the names of the base vector wrappers from VectorEnvWrapper to VectorWrapper and added VectorObservationWrapper, VectorRewardWrapper and VectorActionWrapper classes. See the vector wrapper page for new information.
To increase the efficiency of vector environments, autoreset is a common feature that allows sub-environments to reset without requiring all sub-environments to finish before resetting them all. Previously in Gym and Gymnasium, auto-resetting was done on the same step as the environment episode ends, such that the final observation and info would be stored in the step's info, i.e., info["final_observation"] and info[“final_info”] and standard obs and info containing the sub-environment's reset observation and info. Thus, accurately sampling observations from a vector environment required the following code (note the need to extract the infos["next_obs"][j] if the sub-environment was terminated or truncated). Additionally, for on-policy algorithms that use rollout would require an additional forward pass to compute the correct next observation (this is often not done as an optimization assuming that environments only terminate, not truncate).
replay_buffer = []
obs, _ = envs.reset()
for _ in range(total_timesteps):
next_obs, rewards, terminations, truncations, infos = envs.step(envs.action_space.sample())
for j in range(envs.num_envs):
if not (terminations[j] or truncations[j]):
replay_buffer.append((
obs[j], rewards[j], terminations[j], truncations[j], next_obs[j]
))
else:
replay_buffer.append((
obs[j], rewards[j], terminations[j], truncations[j], infos["next_obs"][j]
))
obs = next_obsHowever, over time, the development team has recognized the inefficiency of this approach (primarily due to the extensive use of a Python dictionary) and the annoyance of having to extract the final observation to train agents correctly, for example. Therefore, in v1.0.0, we are modifying autoreset to align with specialized vector-only projects like EnvPool and SampleFactory where the sub-environment's doesn't reset until the next step. As a result, the following changes are required when sampling:
replay_buffer = []
obs, _ = envs.reset()
autoreset = np.zeros(envs.num_envs)
for _ in range(total_timesteps):
next_obs, rewards, terminations, truncations, _ = envs.step(envs.action_space.sample())
for j in range(envs.num_envs):
if not autoreset[j]:
replay_buffer.append((
obs[j], rewards[j], terminations[j], truncations[j], next_obs[j]
))
obs = next_obs
autoreset = np.logical_or(terminations, truncations)For on-policy rollout, to account for the autoreset requires masking the error for the first observation in a new episode (done[t+1]) to prevent computing the error between the last and first observations of episodes.
Finally, we have improved AsyncVectorEnv.set_attr and SyncVectorEnv.set_attr functions to use the Wrapper.set_wrapper_attr to allow users to set variables anywhere in the environment stack if it already exists. Previously, this was not possible and users could only modify the variable in the "top" wrapper on the environment stack, importantly not the actual environment itself.
Previously, some wrappers could support both environment and vector environments, however, this was not standardized, and was unclear which wrapper did and didn't support vector environments. For v1.0.0, with separating Env and VectorEnv to no longer inherit from each other (read more in the vector section), the wrappers in gymnasium.wrappers will only support standard environments and wrappers in gymnasium.wrappers.vector contains the provided specialized vector wrappers (most but not all wrappers are supported, please raise a feature request if you require it).
In v0.29, we deprecated the Wrapper.__getattr__ function to be replaced by Wrapper.get_wrapper_attr, providing access to variables anywhere in the environment stack. In v1.0.0, we have added Wrapper.set_wrapper_attr as an equivalent function for setting a variable anywhere in the environment stack if it already exists; otherwise the variable is assigned to the top wrapper.
Most significantly, we have removed, renamed, and added several wrappers listed below.
monitoring.VideoRecorder - The replacement wrapper is RecordVideoStepAPICompatibility - We expect all Gymnasium environments to use the terminated / truncated step API, therefore, users shouldn't need the StepAPICompatibility wrapper. Shimmy includes a compatibility environment to convert gym-api environments for gymnasium.AutoResetWrapper -> AutoresetFrameStack -> FrameStackObservationPixelObservationWrapper -> AddRenderObservationgymnasium.wrappers.vector)
VectorListInfo -> vector.DictInfoToListDelayObservation - Adds a delay to the next observation and rewardDtypeObservation - Modifies the dtype of an environment's observation spaceMaxAndSkipObservation - Will skip n observations and will max over the last 2 observations, inspired by the Atari environment heuristic for other environmentsStickyAction - Random repeats actions with a probability for a step returning the final observation and sum of rewards over steps. Inspired by Atari environment heuristicsJaxToNumpy - Converts a Jax-based environment to use Numpy-based input and output data for reset, step, etcJaxToTorch - Converts a Jax-based environment to use PyTorch-based input and output data for reset, step, etcNumpyToTorch - Converts a Numpy-based environment to use PyTorch-based input and output data for reset, step, etcFor all wrappers, we have added example code documentation and a changelog to help future researchers understand any changes made. See the following page for an example.
One of the substantial advantages of Gymnasium's Env is it generally requires minimal information about the underlying environment specifications; however, this can make applying such environments to planning, search algorithms, and theoretical investigations more difficult. We are proposing FuncEnv as an alternative definition to Env which is closer to a Markov Decision Process definition, exposing more functions to the user, including the observation, reward, and termination functions along with the environment's raw state as a single object.
from typing import Any
import gymnasium as gym
from gymnasium.functional import StateType, ObsType, ActType, RewardType, TerminalType, Params
class ExampleFuncEnv(gym.functional.FuncEnv):
def initial(self, rng: Any, params: Params | None = None) -> StateType:
...
def transition(self, state: StateType, action: ActType, rng: Any, params: Params | None = None) -> StateType:
...
def observation(self, state: StateType, rng: Any, params: Params | None = None) -> ObsType:
...
def reward(
self, state: StateType, action: ActType, next_state: StateType, rng: Any, params: Params | None = None
) -> RewardType:
...
def terminal(self, state: StateType, rng: Any, params: Params | None = None) -> TerminalType:
...FuncEnv requires that initial and transition functions return a new state given its inputs as a partial implementation of Env.step and Env.reset. As a result, users can sample (and save) the next state for a range of inputs to use with planning, searching, etc. Given a state, observation, reward, and terminal provide users explicit definitions to understand how each can affect the environment's output.
It was possible to seed with both environments and spaces with None to use a random initial seed value, however it wouldn't be possible to know what these initial seed values were. We have addressed this for Space.seed and reset.seed in #1033 and #889. Additionally, for Space.seed, we have changed the return type to be specialized for each space such that the following code will work for all spaces.
seeded_values = space.seed(None)
initial_samples = [space.sample() for _ in range(10)]
reseed_values = space.seed(seeded_values)
reseed_samples = [space.sample() for _ in range(10)]
assert seeded_values == reseed_values
assert initial_samples == reseed_samplesAdditionally, for environments, we have added a new np_random_seed attribute that will store the most recent np_random seed value from reset(seed=seed).
It was discovered recently that the MuJoCo-based Pusher was not compatible with mujoco>= 3 as the model's density for the block that the agent had to push was lighter than air. This obviously began to cause issues for users with mujoco>= 3 and Pusher. Therefore, we are disabled the v4 environment with mujoco>= 3 and updated to the model in MuJoCo v5 that produces more expected behavior like v4 and mujoco< 3 (#1019).
New v5 MuJoCo environments as a follow-up to v4 environments added two years ago, fixing consistencies, adding new features and updating the documentation (#572). Additionally, we have decided to mark the mujoco-py based (v2 and v3) environments as deprecated and plan to remove them from Gymnasium in future (#926).
Lunar Lander version increased from v2 to v3 due to two bug fixes. The first fixes the determinism of the environment such that the world object was not completely destroyed on reset causing non-determinism in particular cases (#979). Second, the wind generation (by default turned off) was not randomly generated by each reset, therefore, we have updated this to gain statistical independence between episodes (#959).
CarRacing version increased from v2 to v3 to change how the environment ends such that when the agent completes the track then the environment will terminate not truncate.
We have remove pip install "gymnasium[accept-rom-license]" as ale-py>=0.9 now comes packaged with the roms meaning that users don't need to install the atari roms separately with autoroms.
spaces.Box would allow low and high values outside the dtype's range, which could result in some very strange edge cases that were very difficult to detect by @pseudo-rnd-thoughts (#774)gymnasium[mujoco-py] due to cython==3 issues by @pseudo-rnd-thoughts (#616)register(kwargs) from **kwargs to kwargs: dict | None = None by @younik (#788)AsyncVectorEnv for custom environments by @RedTachyon (#810)mujoco-py import error for v4+ MuJoCo environments by @MischaPanchTuple and Dict spaces (#941)Multidiscrete.from_jsonable on windows (#932)play rendering normalization (#956)to_torch conversion by @mantasu (#1107)AsyncVectorEnv by @pseudo-rnd-thoughts in #1119NamedTuples in JaxToNumpy, JaxToTorch and NumpyToTorch by @RogerJL (#789) and @pseudo-rnd-thoughts (#811)padding_type parameter to FrameSkipObservation to select the padding observation by @jamartinh (#830)check_environments_match by @Kallinteris-Andreas (#748)OneOf space that provides exclusive unions of spaces by @RedTachyon and @pseudo-rnd-thoughts (#812)Dict.sample to use standard Python dicts rather than OrderedDict due to dropping Python 3.7 support by @pseudo-rnd-thoughts (#977)wrappers.vector.HumanRendering and remove human rendering from CartPoleVectorEnv by @pseudo-rnd-thoughts and @TimSchneider42 (#1013)sutton_barto_reward argument for CartPole that changes the reward function to not return 1 on terminating states by @Kallinteris-Andreas (#958)visual_options rendering argument for MuJoCo environments by @Kallinteris-Andreas (#965)exact argument to utlis.env_checker.data_equivilance by @Kallinteris-Andreas (#924)wrapper.NormalizeObservation observation space and change observation to float32 by @pseudo-rnd-thoughts (#978)env.spec if kwarg is unpickleable by @pseudo-rnd-thoughts (#982)is_slippery option for cliffwalking environment by @CloseChoice (#1087)RescaleAction and RescaleObservation to support np.inf bounds by @TimSchneider42 (#1095)env.reset(seed=42); env.reset() by @qgallouedec (#1086)BaseMujocoEnv class by @Kallinteris-Andreas (#1075)gymnasium.envs.mujoco by @Kallinteris-Andreas (#827)Gymnasium/MuJoCo/Ant-v5 framework by @Kallinteris-Andreas (#838)__init__ and reset arguments by @pseudo-rnd-thoughts (#898)Full Changelog: v0.29.1...v1.0.0
This is our second alpha version which we hope to be the last before the full Gymnasium v1.0.0 release. We summarise the key changes, bug fixes and new features added in this alpha version.
ale-py that provides the Atari environments has been updated in v0.9.0 to use Gymnasium as the API backend. Furthermore, the pip install contains the ROMs so all that should be necessary for installing Atari will be pip install “gymnasium[atari]” (as a result, gymnasium[accept-rom-license] has been removed). A reminder that for Gymnasium v1.0 to register the external environments (e.g., ale-py), you will be required to import ale_py before creating any of the Atari environments.
It was possible to seed with both environments and spaces with None to use a random initial seed value however it wouldn’t be possible to know what these initial seed values were. We have addressed for this Space.seed and reset.seed in #1033 and #889. For Space.seed, we have changed the return type to be specialised for each space such that the following code will work for all spaces.
seeded_values = space.seed(None)
initial_samples = [space.sample() for _ in range(10)]
reseed_values = space.seed(seeded_values)
reseed_samples = [space.sample() for _ in range(10)]
assert seeded_values == reseed_values
assert initial_samples == reseed_samplesAdditionally, for environments, we have added a new np_random_seed attribute that will store the most recent np_random seed value from reset(seed=seed).
>= 3 due to bug fixes that found the model density for a block that the agent had to push was the density of air. This obviously began to cause issues for users with MuJoCo v3+ and Pusher. Therefore, we are disabled the v4 environment with MuJoCo >= 3 and updated to the model in MuJoCo v5 that produces more expected behaviour like v4 and MuJoCo < 3 (#1019).It was discovered that the spaces.Box would allow low and high values outside the dtype’s range (#774) which could result in some very strange edge cases that were very difficult to detect. We hope that these changes improve debugging and detecting invalid inputs to the space, however, let us know if your environment raises issues related to this.
CartPoleVectorEnv for the new autoreset API (#915)wrappers.vector.RecordEpisodeStatistics episode length computation from new autoreset api (#1018)mujoco-py import error for v4+ MuJoCo environments (#934)make_vec(**kwargs) not being passed to vector entry point envs (#952)Tuple and Dict spaces (#941)Multidiscrete.from_jsonable for windows (#932)play rendering normalisation (#956)OneOf space that provides exclusive unions of spaces (#812)Dict.sample to use standard Python dicts rather than OrderedDict due to dropping Python 3.7 support (#977)wrappers.vector.HumanRendering and remove human rendering from CartPoleVectorEnv (#1013)sutton_barto_reward argument for CartPole that changes the reward function to not return 1 on terminating states (#958)visual_options rendering argument for MuJoCo environments (#965)exact argument to utlis.env_checker.data_equivilance (#924)wrapper.NormalizeObservation observation space and change observation to float32 (#978)env.spec if kwarg is unpickleable (#982)make_vec for sync or async when modifying make arguments (#1027)Full Changelog: v1.0.0a1...v1.0.0a2 v0.29.1...v1.0.0a2
Over the last few years, the volunteer team behind Gym and Gymnasium has worked to fix bugs, improve the documentation, add new features, and change the API where appropriate such that the benefits outweigh the costs. This is the first alpha release of v1.0.0, which aims to be the end of this road of changing the project's API along with containing many new features and improved documentation.
To install v1.0.0a1, you must use pip install gymnasium==1.0.0a1 or pip install --pre gymnasium otherwise, v0.29.1 will be installed. Similarly, the website will default to v0.29.1's documentation, which can be changed with the pop-up in the bottom right.
We are really interested in projects testing with these v1.0.0 alphas to find any bugs, missing documentation, or issues with the API changes before we release v1.0 in full.
Within Gym v0.23+ and Gymnasium v0.26 to v0.29, an undocumented feature that has existed for registering external environments behind the scenes has been removed. For users of Atari (ALE), Minigrid or HighwayEnv, then users could use the following code:
import gymnasium as gym
env = gym.make("ALE/Pong-v5")such that despite Atari never being imported (i.e., import ale_py), users can still load an Atari environment. This feature has been removed in v1.0.0, which will require users to update to
import gymnasium as gym
import ale_py
gym.register_envs(ale_py) # optional
env = gym.make("ALE/Pong-v5")Alternatively, users can do the following where the ale_py within the environment id will import the module
import gymnasium as gym
env = gym.make("ale_py:ALE/Pong-v5") # `module_name:env_id`For users with IDEs (i.e., VSCode, PyCharm), then import ale_py can cause the IDE (and pre-commit isort / black / flake8) to believe that the import statement does nothing. Therefore, we have introduced gymnasium.register_envs as a no-op function (the function literally does nothing) to make the IDE believe that something is happening and the import statement is required.
Note: ALE-py, Minigrid, and HighwayEnv must be updated to work with Gymnasium v1.0.0, which we hope to complete for all projects affected by alpha 2.
To increase the sample speed of an environment, vectorizing is one of the easiest ways to sample multiple instances of the same environment simultaneously. Gym and Gymnasium provide the VectorEnv as a base class for this, but one of its issues has been that it inherited Env. This can cause particular issues with type checking (the return type of step is different for Env and VectorEnv), testing the environment type (isinstance(env, Env) can be true for vector environments despite the two actings differently) and finally wrappers (some Gym and Gymnasium wrappers supported Vector environments but there are no clear or consistent API for determining which did or didn’t). Therefore, we have separated out Env and VectorEnv to not inherit from each other.
In implementing the new separate VectorEnv class, we have tried to minimize the difference between code using Env and VectorEnv along with making it more generic in places. The class contains the same attributes and methods as Env along with num_envs: int, single_action_space: gymnasium.Space and single_observation_space: gymnasium.Space. Additionally, we have removed several functions from VectorEnv that are not needed for all vector implementations: step_async, step_wait, reset_async, reset_wait, call_async and call_wait. This change now allows users to write their own custom vector environments, v1.0.0a1 includes an example vector cartpole environment that runs thousands of times faster than using Gymnasium’s Sync vector environment.
To allow users to create vectorized environments easily, we provide gymnasium.make_vec as a vectorized equivalent of gymnasium.make. As there are multiple different vectorization options (“sync”, “async”, and a custom class referred to as “vector_entry_point”), the argument vectorization_mode selects how the environment is vectorized. This defaults to None such that if the environment has a vector entry point for a custom vector environment implementation, this will be utilized first (currently, Cartpole is the only environment with a vector entry point built into Gymnasium). Otherwise, the synchronous vectorizer is used (previously, the Gym and Gymnasium vector.make used asynchronous vectorizer as default). For more information, see the function docstring.
env = gym.make("CartPole-v1")
env = gym.wrappers.ClipReward(env, min_reward=-1, max_reward=3)
envs = gym.make_vec("CartPole-v1", num_envs=3)
envs = gym.wrappers.vector.ClipReward(envs, min_reward=-1, max_reward=3)Due to this split of Env and VectorEnv, there are now Env only wrappers and VectorEnv only wrappers in gymnasium.wrappers and gymnasium.wrappers.vector respectively. Furthermore, we updated the names of the base vector wrappers from VectorEnvWrapper to VectorWrapper and added VectorObservationWrapper, VectorRewardWrapper and VectorActionWrapper classes. See the vector wrapper page for new information.
To increase the efficiency of vector environment, autoreset is a common feature that allows sub-environments to reset without requiring all sub-environments to finish before resetting them all. Previously in Gym and Gymnasium, auto-resetting was done on the same step as the environment episode ends, such that the final observation and info would be stored in the step’s info, i.e., info["final_observation"] and info[“final_info”] and standard obs and info containing the sub-environment’s reset observation and info. This required similar general sampling for vectorized environments.
replay_buffer = []
obs, _ = envs.reset()
for _ in range(total_timesteps):
next_obs, rewards, terminations, truncations, infos = envs.step(envs.action_space.sample())
for j in range(envs.num_envs):
if not (terminations[j] or truncations[j]):
replay_buffer.append((
obs[j], rewards[j], terminations[j], truncations[j], next_obs[j]
))
else:
replay_buffer.append((
obs[j], rewards[j], terminations[j], truncations[j], infos["next_obs"][j]
))
obs = next_obsHowever, over time, the development team has recognized the inefficiency of this approach (primarily due to the extensive use of a Python dictionary) and the annoyance of having to extract the final observation to train agents correctly, for example. Therefore, in v1.0.0, we are modifying autoreset to align with specialized vector-only projects like EnvPool and SampleFactory such that the sub-environment’s doesn’t reset until the next step. As a result, this requires the following changes when sampling. For environments with more complex observation spaces (and action actions) then
replay_buffer = []
obs, _ = envs.reset()
autoreset = np.zeros(envs.num_envs)
for _ in range(total_timesteps):
next_obs, rewards, terminations, truncations, _ = envs.step(envs.action_space.sample())
for j in range(envs.num_envs):
if not autoreset[j]:
replay_buffer.append((
obs[j], rewards[j], terminations[j], truncations[j], next_obs[j]
))
obs = next_obs
autoreset = np.logical_or(terminations, truncations)Finally, we have improved AsyncVectorEnv.set_attr and SyncVectorEnv.set_attr functions to use the Wrapper.set_wrapper_attr to allow users to set variables anywhere in the environment stack if it already exists. Previously, this was not possible and users could only modify the variable in the “top” wrapper on the environment stack, importantly not the actual environment its self.
Previously, some wrappers could support both environment and vector environments, however, this was not standardized, and was unclear which wrapper did and didn't support vector environments. For v1.0.0, with separating Env and VectorEnv to no longer inherit from each other (read more in the vector section), the wrappers in gymnasium.wrappers will only support standard environments and wrappers in gymnasium.wrappers.vector contains the provided specialized vector wrappers (most but not all wrappers are supported, please raise a feature request if you require it).
In v0.29, we deprecated the Wrapper.__getattr__ function to be replaced by Wrapper.get_wrapper_attr, providing access to variables anywhere in the environment stack. In v1.0.0, we have added Wrapper.set_wrapper_attr as an equivalent function for setting a variable anywhere in the environment stack if it already exists; only the variable is set in the top wrapper (or environment).
Most significantly, we have removed, renamed, and added several wrappers listed below.
monitoring.VideoRecorder - The replacement wrapper is RecordVideoStepAPICompatibility - We expect all Gymnasium environments to use the terminated / truncated step API, therefore, user shouldn't need the StepAPICompatibility wrapper. Shimmy includes a compatibility environments to convert gym-api environment's for gymnasium.AutoResetWrapper -> AutoresetFrameStack -> FrameStackObservationPixelObservationWrapper -> AddRenderObservationgymnasium.wrappers.vector)
VectorListInfo -> vector.DictInfoToListDelayObservation - Adds a delay to the next observation and rewardDtypeObservation - Modifies the dtype of an environment’s observation spaceMaxAndSkipObservation - Will skip n observations and will max over the last 2 observations, inspired by the Atari environment heuristic for other environmentsStickyAction - Random repeats actions with a probability for a step returning the final observation and sum of rewards over steps. Inspired by Atari environment heuristicsJaxToNumpy - Converts a Jax-based environment to use Numpy-based input and output data for reset, step, etcJaxToTorch - Converts a Jax-based environment to use PyTorch-based input and output data for reset, step, etcNumpyToTorch - Converts a Numpy-based environment to use PyTorch-based input and output data for reset, step, etcFor all wrappers, we have added example code documentation and a changelog to help future researchers understand any changes made. See the following page for an example.
One of the substantial advantages of Gymnasium's Env is it generally requires minimal information about the underlying environment specifications however, this can make applying such environments to planning, search algorithms, and theoretical investigations more difficult. We are proposing FuncEnv as an alternative definition to Env which is closer to a Markov Decision Process definition, exposing more functions to the user, including the observation, reward, and termination functions along with the environment’s raw state as a single object.
from typing import Any
import gymnasium as gym
from gymnasium.functional import StateType, ObsType, ActType, RewardType, TerminalType, Params
class ExampleFuncEnv(gym.functional.FuncEnv):
def initial(rng: Any, params: Params | None = None) → StateType
…
def transition(state: StateType, action: ActType, rng: Any, params: Params | None = None) → StateType
…
def observation(state: StateType, params: Params | None = None) → ObsType
…
def reward(
state: StateType, action: ActType, next_state: StateType, params: Params | None = None
) → RewardType
…
def terminal(state: StateType, params: Params | None = None) → TerminalType
…FuncEnv requires that initial and transition functions to return a new state given its inputs as a partial implementation of Env.step and Env.reset. As a result, users can sample (and save) the next state for a range of inputs to use with planning, searching, etc. Given a state, observation, reward, and terminal provide users explicit definitions to understand how each can affect the environment's output.
gymnasium[mujoco-py] due to cython==3 issues by @pseudo-rnd-thoughts (#616)MuJoCo environment type issues by @Kallinteris-Andreas (#612)register(kwargs) from **kwargs to kwargs: dict | None = None by @younik (#788)CartPoleVectorEnv step counter to be set back to zero on reset by @TimSchneider42 (#886)NamedTuples in JaxToNumpy, JaxToTorch and NumpyToTorch by @RogerJL (#789) and @pseudo-rnd-thoughts (#811)padding_type parameter to FrameSkipObservation to select the padding observation by @jamartinh (#830)check_environments_match by @Kallinteris-Andreas (#748)gymnasium.envs.mujoco by @Kallinteris-Andreas (#827)Gymnasium/MuJoCo/Ant-v5 framework by @Kallinteris-Andreas (#838)__init__ and reset arguments by @pseudo-rnd-thoughts (#898)Full Changelog: v0.29.0...v1.0.0a1
We have decided to mark the MuJoCo-py (v2 and v3) environments as deprecated and plan to remove them from Gymnasium in future (https://github.com/Fara…
This is our second alpha version which we hope to be the last before the full Gymnasium v1.0.0 release. We summarise the key changes, bug fixes and new features added in this alpha version.
ale-py that provides the Atari environments has been updated in v0.9.0 to use Gymnasium as the API backend. Furthermore, the pip install contains the ROMs so all that should be necessary for installing Atari will be pip install “gymnasium[atari]” (as a result, gymnasium[accept-rom-license] has been removed). A reminder that for Gymnasium v1.0 to register the external environments (e.g., ale-py), you will be required to import ale_py before creating any of the Atari environments.
It was possible to seed with both environments and spaces with None to use a random initial seed value however it wouldn’t be possible to know what these initial seed values were. We have addressed for this Space.seed and reset.seed in https://github.com/Farama-Foundation/Gymnasium/pull/1033 and https://github.com/Farama-Foundation/Gymnasium/pull/889. For Space.seed, we have changed the return type to be specialised for each space such that the following code will work for all spaces.
seeded_values = space.seed(None)
initial_samples = [space.sample() for _ in range(10)]
reseed_values = space.seed(seeded_values)
reseed_samples = [space.sample() for _ in range(10)]
assert seeded_values == reseed_values
assert initial_samples == reseed_samples
Additionally, for environments, we have added a new np_random_seed attribute that will store the most recent np_random seed value from reset(seed=seed).
>= 3 due to bug fixes that found the model density for a block that the agent had to push was the density of air. This obviously began to cause issues for users with MuJoCo v3+ and Pusher. Therefore, we are disabled the v4 environment with MuJoCo >= 3 and updated to the model in MuJoCo v5 that produces more expected behaviour like v4 and MuJoCo < 3 (https://github.com/Farama-Foundation/Gymnasium/pull/1019).It was discovered that the spaces.Box would allow low and high values outside the dtype’s range (https://github.com/Farama-Foundation/Gymnasium/pull/774) which could result in some very strange edge cases that were very difficult to detect. We hope that these changes improve debugging and detecting invalid inputs to the space, however, let us know if your environment raises issues related to this.
CartPoleVectorEnv for the new autoreset API (https://github.com/Farama-Foundation/Gymnasium/pull/915)wrappers.vector.RecordEpisodeStatistics episode length computation from new autoreset api (https://github.com/Farama-Foundation/Gymnasium/pull/1018)mujoco-py import error for v4+ MuJoCo environments (https://github.com/Farama-Foundation/Gymnasium/pull/934)make_vec(**kwargs) not being passed to vector entry point envs (https://github.com/Farama-Foundation/Gymnasium/pull/952)Tuple and Dict spaces (https://github.com/Farama-Foundation/Gymnasium/pull/941)Multidiscrete.from_jsonable for windows (https://github.com/Farama-Foundation/Gymnasium/pull/932)play rendering normalisation (https://github.com/Farama-Foundation/Gymnasium/pull/956)OneOf space that provides exclusive unions of spaces (https://github.com/Farama-Foundation/Gymnasium/pull/812)Dict.sample to use standard Python dicts rather than OrderedDict due to dropping Python 3.7 support (https://github.com/Farama-Foundation/Gymnasium/pull/977)wrappers.vector.HumanRendering and remove human rendering from CartPoleVectorEnv (https://github.com/Farama-Foundation/Gymnasium/pull/1013)sutton_barto_reward argument for CartPole that changes the reward function to not return 1 on terminating states (https://github.com/Farama-Foundation/Gymnasium/pull/958)visual_options rendering argument for MuJoCo environments (https://github.com/Farama-Foundation/Gymnasium/pull/965)exact argument to utlis.env_checker.data_equivilance (https://github.com/Farama-Foundation/Gymnasium/pull/924)wrapper.NormalizeObservation observation space and change observation to float32 (https://github.com/Farama-Foundation/Gymnasium/pull/978)env.spec if kwarg is unpickleable (https://github.com/Farama-Foundation/Gymnasium/pull/982)make_vec for sync or async when modifying make arguments (https://github.com/Farama-Foundation/Gymnasium/pull/1027)Full Changelog: https://github.com/Farama-Foundation/Gymnasium/compare/v1.0.0a1...v1.0.0a2 https://github.com/Farama-Foundation/Gymnasium/compare/v0.29.1...v1.0.0a2
In v0.29, we deprecated the Wrapper.__getattr__ function to be replaced by Wrapper.get_wrapper_attr, providing access to variables anywhere in the env…
Over the last few years, the volunteer team behind Gym and Gymnasium has worked to fix bugs, improve the documentation, add new features, and change the API where appropriate such that the benefits outweigh the costs. This is the first alpha release of v1.0.0, which aims to be the end of this road of changing the project's API along with containing many new features and improved documentation.
To install v1.0.0a1, you must use pip install gymnasium==1.0.0a1 or pip install --pre gymnasium otherwise, v0.29.1 will be installed. Similarly, the website will default to v0.29.1's documentation, which can be changed with the pop-up in the bottom right.
We are really interested in projects testing with these v1.0.0 alphas to find any bugs, missing documentation, or issues with the API changes before we release v1.0 in full.
Within Gym v0.23+ and Gymnasium v0.26 to v0.29, an undocumented feature that has existed for registering external environments behind the scenes has been removed. For users of Atari (ALE), Minigrid or HighwayEnv, then users could use the following code:
import gymnasium as gym
env = gym.make("ALE/Pong-v5")
such that despite Atari never being imported (i.e., import ale_py), users can still load an Atari environment. This feature has been removed in v1.0.0, which will require users to update to
import gymnasium as gym
import ale_py
gym.register_envs(ale_py) # optional
env = gym.make("ALE/Pong-v5")
Alternatively, users can do the following where the ale_py within the environment id will import the module
import gymnasium as gym
env = gym.make("ale_py:ALE/Pong-v5") # `module_name:env_id`
For users with IDEs (i.e., VSCode, PyCharm), then import ale_py can cause the IDE (and pre-commit isort / black / flake8) to believe that the import statement does nothing. Therefore, we have introduced gymnasium.register_envs as a no-op function (the function literally does nothing) to make the IDE believe that something is happening and the import statement is required.
Note: ALE-py, Minigrid, and HighwayEnv must be updated to work with Gymnasium v1.0.0, which we hope to complete for all projects affected by alpha 2.
To increase the sample speed of an environment, vectorizing is one of the easiest ways to sample multiple instances of the same environment simultaneously. Gym and Gymnasium provide the VectorEnv as a base class for this, but one of its issues has been that it inherited Env. This can cause particular issues with type checking (the return type of step is different for Env and VectorEnv), testing the environment type (isinstance(env, Env) can be true for vector environments despite the two actings differently) and finally wrappers (some Gym and Gymnasium wrappers supported Vector environments but there are no clear or consistent API for determining which did or didn’t). Therefore, we have separated out Env and VectorEnv to not inherit from each other.
In implementing the new separate VectorEnv class, we have tried to minimize the difference between code using Env and VectorEnv along with making it more generic in places. The class contains the same attributes and methods as Env along with num_envs: int, single_action_space: gymnasium.Space and single_observation_space: gymnasium.Space. Additionally, we have removed several functions from VectorEnv that are not needed for all vector implementations: step_async, step_wait, reset_async, reset_wait, call_async and call_wait. This change now allows users to write their own custom vector environments, v1.0.0a1 includes an example vector cartpole environment that runs thousands of times faster than using Gymnasium’s Sync vector environment.
To allow users to create vectorized environments easily, we provide gymnasium.make_vec as a vectorized equivalent of gymnasium.make. As there are multiple different vectorization options (“sync”, “async”, and a custom class referred to as “vector_entry_point”), the argument vectorization_mode selects how the environment is vectorized. This defaults to None such that if the environment has a vector entry point for a custom vector environment implementation, this will be utilized first (currently, Cartpole is the only environment with a vector entry point built into Gymnasium). Otherwise, the synchronous vectorizer is used (previously, the Gym and Gymnasium vector.make used asynchronous vectorizer as default). For more information, see the function docstring.
env = gym.make("CartPole-v1")
env = gym.wrappers.ClipReward(env, min_reward=-1, max_reward=3)
envs = gym.make_vec("CartPole-v1", num_envs=3)
envs = gym.wrappers.vector.ClipReward(envs, min_reward=-1, max_reward=3)
Due to this split of Env and VectorEnv, there are now Env only wrappers and VectorEnv only wrappers in gymnasium.wrappers and gymnasium.wrappers.vector respectively. Furthermore, we updated the names of the base vector wrappers from VectorEnvWrapper to VectorWrapper and added VectorObservationWrapper, VectorRewardWrapper and VectorActionWrapper classes. See the vector wrapper page for new information.
To increase the efficiency of vector environment, autoreset is a common feature that allows sub-environments to reset without requiring all sub-environments to finish before resetting them all. Previously in Gym and Gymnasium, auto-resetting was done on the same step as the environment episode ends, such that the final observation and info would be stored in the step’s info, i.e., info["final_observation"] and info[“final_info”] and standard obs and info containing the sub-environment’s reset observation and info. This required similar general sampling for vectorized environments.
replay_buffer = []
obs, _ = envs.reset()
for _ in range(total_timesteps):
next_obs, rewards, terminations, truncations, infos = envs.step(envs.action_space.sample())
for j in range(envs.num_envs):
if not (terminations[j] or truncations[j]):
replay_buffer.append((
obs[j], rewards[j], terminations[j], truncations[j], next_obs[j]
))
else:
replay_buffer.append((
obs[j], rewards[j], terminations[j], truncations[j], infos["next_obs"][j]
))
obs = next_obs
However, over time, the development team has recognized the inefficiency of this approach (primarily due to the extensive use of a Python dictionary) and the annoyance of having to extract the final observation to train agents correctly, for example. Therefore, in v1.0.0, we are modifying autoreset to align with specialized vector-only projects like EnvPool and SampleFactory such that the sub-environment’s doesn’t reset until the next step. As a result, this requires the following changes when sampling. For environments with more complex observation spaces (and action actions) then
replay_buffer = []
obs, _ = envs.reset()
autoreset = np.zeros(envs.num_envs)
for _ in range(total_timesteps):
next_obs, rewards, terminations, truncations, _ = envs.step(envs.action_space.sample())
for j in range(envs.num_envs):
if not autoreset[j]:
replay_buffer.append((
obs[j], rewards[j], terminations[j], truncations[j], next_obs[j]
))
obs = next_obs
autoreset = np.logical_or(terminations, truncations)
Finally, we have improved AsyncVectorEnv.set_attr and SyncVectorEnv.set_attr functions to use the Wrapper.set_wrapper_attr to allow users to set variables anywhere in the environment stack if it already exists. Previously, this was not possible and users could only modify the variable in the “top” wrapper on the environment stack, importantly not the actual environment its self.
Previously, some wrappers could support both environment and vector environments, however, this was not standardized, and was unclear which wrapper did and didn't support vector environments. For v1.0.0, with separating Env and VectorEnv to no longer inherit from each other (read more in the vector section), the wrappers in gymnasium.wrappers will only support standard environments and wrappers in gymnasium.wrappers.vector contains the provided specialized vector wrappers (most but not all wrappers are supported, please raise a feature request if you require it).
In v0.29, we deprecated the Wrapper.__getattr__ function to be replaced by Wrapper.get_wrapper_attr, providing access to variables anywhere in the environment stack. In v1.0.0, we have added Wrapper.set_wrapper_attr as an equivalent function for setting a variable anywhere in the environment stack if it already exists; only the variable is set in the top wrapper (or environment).
Most significantly, we have removed, renamed, and added several wrappers listed below.
monitoring.VideoRecorder - The replacement wrapper is RecordVideoStepAPICompatibility - We expect all Gymnasium environments to use the terminated / truncated step API, therefore, user shouldn't need the StepAPICompatibility wrapper. Shimmy includes a compatibility environments to convert gym-api environment's for gymnasium.AutoResetWrapper -> AutoresetFrameStack -> FrameStackObservationPixelObservationWrapper -> AddRenderObservationgymnasium.wrappers.vector)
VectorListInfo -> vector.DictInfoToListDelayObservation - Adds a delay to the next observation and rewardDtypeObservation - Modifies the dtype of an environment’s observation spaceMaxAndSkipObservation - Will skip n observations and will max over the last 2 observations, inspired by the Atari environment heuristic for other environmentsStickyAction - Random repeats actions with a probability for a step returning the final observation and sum of rewards over steps. Inspired by Atari environment heuristicsJaxToNumpy - Converts a Jax-based environment to use Numpy-based input and output data for reset, step, etcJaxToTorch - Converts a Jax-based environment to use PyTorch-based input and output data for reset, step, etcNumpyToTorch - Converts a Numpy-based environment to use PyTorch-based input and output data for reset, step, etcFor all wrappers, we have added example code documentation and a changelog to help future researchers understand any changes made. See the following page for an example.
One of the substantial advantages of Gymnasium's Env is it generally requires minimal information about the underlying environment specifications however, this can make applying such environments to planning, search algorithms, and theoretical investigations more difficult. We are proposing FuncEnv as an alternative definition to Env which is closer to a Markov Decision Process definition, exposing more functions to the user, including the observation, reward, and termination functions along with the environment’s raw state as a single object.
from typing import Any
import gymnasium as gym
from gymnasium.functional import StateType, ObsType, ActType, RewardType, TerminalType, Params
class ExampleFuncEnv(gym.functional.FuncEnv):
def initial(rng: Any, params: Params | None = None) → StateType
…
def transition(state: StateType, action: ActType, rng: Any, params: Params | None = None) → StateType
…
def observation(state: StateType, params: Params | None = None) → ObsType
…
def reward(
state: StateType, action: ActType, next_state: StateType, params: Params | None = None
) → RewardType
…
def terminal(state: StateType, params: Params | None = None) → TerminalType
…
FuncEnv requires that initial and transition functions to return a new state given its inputs as a partial implementation of Env.step and Env.reset. As a result, users can sample (and save) the next state for a range of inputs to use with planning, searching, etc. Given a state, observation, reward, and terminal provide users explicit definitions to understand how each can affect the environment's output.
gymnasium[mujoco-py] due to cython==3 issues by @pseudo-rnd-thoughts (https://github.com/Farama-Foundation/Gymnasium/pull/616)MuJoCo environment type issues by @Kallinteris-Andreas (https://github.com/Farama-Foundation/Gymnasium/pull/612)register(kwargs) from **kwargs to kwargs: dict | None = None by @younik (https://github.com/Farama-Foundation/Gymnasium/pull/788)CartPoleVectorEnv step counter to be set back to zero on reset by @TimSchneider42 (https://github.com/Farama-Foundation/Gymnasium/pull/886)NamedTuples in JaxToNumpy, JaxToTorch and NumpyToTorch by @RogerJL (https://github.com/Farama-Foundation/Gymnasium/pull/789) and @pseudo-rnd-thoughts (https://github.com/Farama-Foundation/Gymnasium/pull/811)padding_type parameter to FrameSkipObservation to select the padding observation by @jamartinh (https://github.com/Farama-Foundation/Gymnasium/pull/830)check_environments_match by @Kallinteris-Andreas (https://github.com/Farama-Foundation/Gymnasium/pull/748)gymnasium.envs.mujoco by @Kallinteris-Andreas (https://github.com/Farama-Foundation/Gymnasium/pull/827)Gymnasium/MuJoCo/Ant-v5 framework by @Kallinteris-Andreas (https://github.com/Farama-Foundation/Gymnasium/pull/838)__init__ and reset arguments by @pseudo-rnd-thoughts (https://github.com/Farama-Foundation/Gymnasium/pull/898)Full Changelog: https://github.com/Farama-Foundation/Gymnasium/compare/v0.29.0...v1.0.0a1
Add warning to VectorEnvWrapper.__getattr__ to specify that it also is deprecated in v1.0.0
A minimal release that fixes a warning produced by Wrapper.__getattr__.
In particular, this function will be removed in v1.0.0 however the reported solution for this was incorrect and the updated solution still caused the warning to show (due to technical python reasons).
Wrapper.__getattr__ warning reports the incorrect new function, get_attr rather than get_wrapper_attrget_wrapper_attr, the __getattr__ warning is still be raised due to get_wrapper_attr using hasattr which under the hood uses __getattr__. Therefore, updated to remove the unintended warning.VectorEnvWrapper.__getattr__ to specify that it also is deprecated in v1.0.0Full Changelog: https://github.com/Farama-Foundation/Gymnasium/compare/v0.29.0...v0.29.1
Add deprecation warnings to several features which will be removed in v1.0: Wrapper.__get_attr__, gymnasium.make(..., autoreset=True), gymnasium.make(…
We finally have a software citation for Gymnasium with the plan to release an associated paper after v1.0, thank you to all the contributors over the last 3 years who have made helped Gym and Gymnasium (https://github.com/Farama-Foundation/Gymnasium/pull/590)
@misc{towers_gymnasium_2023,
title = {Gymnasium},
url = {https://zenodo.org/record/8127025},
abstract = {An API standard for single-agent reinforcement learning environments, with popular reference environments and related utilities (formerly Gym)},
urldate = {2023-07-08},
publisher = {Zenodo},
author = {Towers, Mark and Terry, Jordan K. and Kwiatkowski, Ariel and Balis, John U. and Cola, Gianluca de and Deleu, Tristan and Goulão, Manuel and Kallinteris, Andreas and KG, Arjun and Krimmel, Markus and Perez-Vicente, Rodrigo and Pierré, Andrea and Schulhoff, Sander and Tai, Jun Jet and Shen, Andrew Tan Jin and Younis, Omar G.},
month = mar,
year = {2023},
doi = {10.5281/zenodo.8127026},
}
Gymnasium has a conda package, conda install gymnasium. Thanks to @ChristofKaufmann for completing this
Wrapper.__get_attr__, gymnasium.make(..., autoreset=True), gymnasium.make(..., apply_api_compatibility=True), Env.reward_range and gymnasium.vector.make. For their proposed replacement, see https://github.com/Farama-Foundation/Gymnasium/pull/535Box bounds of low > high, low == inf and high == -inf by @jjshoots in https://github.com/Farama-Foundation/Gymnasium/pull/495data_equivalence() by @pseudo-rnd-thoughts in https://github.com/Farama-Foundation/Gymnasium/pull/515jax>=0.4 by @charraut in https://github.com/Farama-Foundation/Gymnasium/pull/373pygame>=2.1.3 by @pseudo-rnd-thoughts in https://github.com/Farama-Foundation/Gymnasium/pull/558start parameter to MultiDiscrete space, similar to the Discrete(..., start) parameter by @Rayerdyne in https://github.com/Farama-Foundation/Gymnasium/pull/557check_env that closing a closed environment doesn't raise an error by @pseudo-rnd-thoughts in https://github.com/Farama-Foundation/Gymnasium/pull/564wrapper.RecordVideo throws an error if the environment has an invalid render mode (None, "human", "ansi") by @robertoschiavone in https://github.com/Farama-Foundation/Gymnasium/pull/580MaxAndSkipObservation wrapper by @LucasAlegre in https://github.com/Farama-Foundation/Gymnasium/pull/561check_environments_match function for checking if two environments are identical by @Kallinteris-Andreas in https://github.com/Farama-Foundation/Gymnasium/pull/576utils/performance.py by @Kallinteris-Andreas in https://github.com/Farama-Foundation/Gymnasium/pull/583xml_file arguments by @Kallinteris-Andreas in https://github.com/Farama-Foundation/Gymnasium/pull/536info in reset by @Kallinteris-Andreas in https://github.com/Farama-Foundation/Gymnasium/pull/540metadata["render_fps"], the value is determined on __init__ using dt by @Kallinteris-Andreas in https://github.com/Farama-Foundation/Gymnasium/pull/525gymnasium.experimental.wrappers by @charraut in https://github.com/Farama-Foundation/Gymnasium/pull/341fps argument to RecordVideoV0 for custom fps value that overrides an environment's internal render_fps value by @younik in https://github.com/Farama-Foundation/Gymnasium/pull/503spaces.Dict.keys() as key in keys was False by @pseudo-rnd-thoughts in https://github.com/Farama-Foundation/Gymnasium/pull/608wrappers.RescaleAction based on the bounds by @mmcaulif in https://github.com/Farama-Foundation/Gymnasium/pull/569check_env by @robertoschiavone in https://github.com/Farama-Foundation/Gymnasium/pull/554shimmy[gym] to shimmy[gym-v21] or shimmy[gym-v26] by @elliottower in https://github.com/Farama-Foundation/Gymnasium/pull/433VideoRecorder on reset to empty recorded_frames rather than frames by @voidflight in https://github.com/Farama-Foundation/Gymnasium/pull/518Env.close in VideoRecorder.close by @qgallouedec in https://github.com/Farama-Foundation/Gymnasium/pull/533VideoRecorder and RecordVideoV0 to move import moviepy such that __del__ doesn't raise AttributeErrors by @pseudo-rnd-thoughts in https://github.com/Farama-Foundation/Gymnasium/pull/553nstep in _step_mujoco_simulation function of MujocoEnv by @xuanhien070594 in https://github.com/Farama-Foundation/Gymnasium/pull/424FrozenLake4x4 and FrozenLake8x8 environments by @yaniv-peretz in https://github.com/Farama-Foundation/Gymnasium/pull/459Full Changelog: https://github.com/Farama-Foundation/Gymnasium/compare/v0.28.1...v0.29.0
Small emergency release to fix several issues
Small emergency release to fix several issues
gymnasium.vector as the gymnasium/__init__.py as it isn't imported https://github.com/Farama-Foundation/Gymnasium/pull/403Full Changelog: https://github.com/Farama-Foundation/Gymnasium/compare/v0.28.0...v0.28.1
env.spec and env.unwrapped.spec return different specs) this is a breaking change. See the reproducibility details section for more info. In v0.27, we…
This release introduces improved support for the reproducibility of Gymnasium environments, particularly for offline reinforcement learning. gym.make can now create the entire environment stack, including wrappers, such that training libraries or offline datasets can specify all of the arguments and wrappers used for an environment. For a majority of standard usage (gym.make(”EnvironmentName-v0”)), this will be backwards compatible except for certain fairly uncommon cases (i.e. env.spec and env.unwrapped.spec return different specs) this is a breaking change. See the reproducibility details section for more info.
In v0.27, we added the experimental folder to allow us to develop several new features (wrappers and hardware accelerated environments). We’ve introduced a new experimental VectorEnv class. This class does not inherit from the standard Env class, and will allow for dramatically more efficient parallelization features. We plan to improve the implementation and add vector based wrappers in several minor releases over the next few months.
Additionally, we have optimized module loading so that PyTorch or Jax are only loaded when users import wrappers that require them, not on import gymnasium.
In previous versions, Gymnasium supported gym.make(spec) where the spec is an EnvSpec from gym.spec(str) or env.spec and worked identically to the string based gym.make(“”). In both cases, there was no way to specify additional wrappers that should be applied to an environment. With this release, we added additional_wrappers to EnvSpec for specifying wrappers applied to the base environment (TimeLimit, PassiveEnvChecker, Autoreset and ApiCompatibility are not included as they are specify in other fields).
This additional field will allow users to accurately save or reproduce an environment used in training for a policy or to generate an offline RL dataset. We provide a json converter function (EnvSpec.to_json) for saving the EnvSpec to a “safe” file type however there are several cases (NumPy data, functions) which cannot be saved to json. In these cases, we recommend pickle but be warned that this can allow remote users to include malicious data in the spec.
import gymnasium as gym
env = gym.make("CartPole-v0")
env = gym.wrappers.TimeAwareObservation(env)
print(env)
# <TimeAwareObservation<TimeLimit<OrderEnforcing<PassiveEnvChecker<CartPoleEnv<CartPole-v0>>>>>>
env_spec = env.spec
env_spec.pprint()
# id=CartPole-v0
# reward_threshold=195.0
# max_episode_steps=200
# additional_wrappers=[
# name=TimeAwareObservation, kwargs={}
# ]
import json
import pickle
json_env_spec = json.loads(env_spec.to_json())
pickled_env_spec = pickle.loads(pickle.dumps(env_spec))
recreated_env = gym.make(json_env_spec)
print(recreated_env)
# <TimeAwareObservation<TimeLimit<OrderEnforcing<PassiveEnvChecker<CartPoleEnv<CartPole-v0>>>>>>
# Be aware that the `TimeAwareObservation` was included by `make`
To support this type of recreation, wrappers must inherit from gym.utils.RecordConstructorUtils to allow gym.make to know what arguments to create the wrapper with. Gymnasium has implemented this for all built-in wrappers but for external projects, should be added to each wrapper. To do this, call gym.utils.RecordConstructorUtils.__init__(self, …) in the first line of the wrapper’s constructor with identical l keyword arguments as passed to the wrapper’s constructor, except for env. As an example see the Atari Preprocessing wrapper
For a more detailed discussion, see the original PRs - https://github.com/Farama-Foundation/Gymnasium/pull/292 and https://github.com/Farama-Foundation/Gymnasium/pull/355
GymV22Compatibility environment was added to support Gym-based environments in Gymnasium. However, the name was incorrect as the env supported Gym’s v0.21 API, not v0.22, therefore, we have updated it to GymV21Compatibility to accurately reflect the API supported. https://github.com/Farama-Foundation/Gymnasium/pull/282Sequence space allows for a dynamic number of elements in an observation or action space sample. To make this more efficient, we added a stack argument which can support which can support a more efficient representation of an element than a tuple, which was what was previously supported. https://github.com/Farama-Foundation/Gymnasium/pull/284Box.sample previously would clip incorrectly for up-bounded spaces such that 0 could never be sampled if the dtype was discrete or boolean. This is fixed such that 0 can be sampled in these cases. https://github.com/Farama-Foundation/Gymnasium/pull/249jax or pytorch was installed then on import gymnasium both of these modules would also be loaded causing significant slow downs in load time. This is now fixed such that jax and torch are only loaded when particular wrappers is loaded by the user. https://github.com/Farama-Foundation/Gymnasium/pull/323Wrapper to allow different observation and action types to be specified for the wrapper and its sub-environment. However, this raised type issues with pyright and mypy, this is now fixed through Wrapper having four generic arguments, [ObsType, ActType, WrappedEnvObsType, WrappedEnvActType]. https://github.com/Farama-Foundation/Gymnasium/pull/337Text, Graph and Sequence however the vector utility functions were not updated to support these spaces. Support for these spaces has been added to the experimental vector space utility functions: batch_space, concatenate, iterate and create_empty_array. https://github.com/Farama-Foundation/Gymnasium/pull/223FrameStackObservation, DelayObservation and TimeAwareObservation) did not work as expected. These wrappers are now fixed and testing has been added. https://github.com/Farama-Foundation/Gymnasium/pull/224__all__ dunder by @howardh in https://github.com/Farama-Foundation/Gymnasium/pull/321MuJoCo/Ant clarify the lack of use_contact_forces on v3 (and older) by @Kallinteris-Andreas in https://github.com/Farama-Foundation/Gymnasium/pull/342Thank you to our new contributors in this release: @Matyasch, @DrRyanHuang, @nerdyespresso, @khoda81, @howardh, @mihaic, and @keyb0ardninja.
Full Changelog: https://github.com/Farama-Foundation/Gymnasium/compare/v0.27.1...v0.28.0
Replace np.bool8 with np.bool_ for numpy 1.24 deprecation warning by @pseudo-rnd-thoughts in https://github.com/Farama-Foundation/Gymnasium/pull/221
np.bool8 with np.bool_ for numpy 1.24 deprecation warning by @pseudo-rnd-thoughts in https://github.com/Farama-Foundation/Gymnasium/pull/221make error when render mode is used without metadata render modes by @pseudo-rnd-thoughts in https://github.com/Farama-Foundation/Gymnasium/pull/216AsyncVectorEnv.reset by @younik in https://github.com/Farama-Foundation/Gymnasium/pull/252callable to Callable by @ianyfan in https://github.com/Farama-Foundation/Gymnasium/pull/259step performance by >1.5x by @PaulMest in https://github.com/Farama-Foundation/Gymnasium/pull/235MuJoCo.Humanoid action description by @Kallinteris-Andreas in https://github.com/Farama-Foundation/Gymnasium/pull/206Ant use_contact_forces obs and reward DOC by @Kallinteris-Andreas in https://github.com/Farama-Foundation/Gymnasium/pull/218MuJoCo.Reacher-v4 doc fixes by @Kallinteris-Andreas in https://github.com/Farama-Foundation/Gymnasium/pull/219Mujoco/Hooper doc minor typo fix by @Kallinteris-Andreas in https://github.com/Farama-Foundation/Gymnasium/pull/247Full Changelog: https://github.com/Farama-Foundation/Gymnasium/compare/v0.27.0...v0.27.1
…we work through our backlog. There should be no breaking changes beyond dropping Python 3.6 support and remove the mujoco Viewer class in favor of a M…
Gymnasium 0.27.0 is our first major release of Gymnasium. It has several significant new features, and numerous small bug fixes and code quality improvements as we work through our backlog. There should be no breaking changes beyond dropping Python 3.6 support and remove the mujoco Viewer class in favor of a MujocoRendering class. You should be able to upgrade your code that's using Gymnasium 0.26.x to 0.27.0 with little-to-no-effort.
Like always, our development roadmap is publicly available here so you can follow our future plans. The only large breaking changes that are still planned are switching selected environments to use hardware accelerated physics engines and our long standing plans for overhauling the vector API and built-in wrappers.
This release notably includes an entirely new part of the library: gymnasium.experimental. We are adding new features, wrappers and functional environment API discussed below for users to test and try out to find bugs and provide feedback.
These new wrappers, accessible in gymnasium.experimental.wrappers, see the full list in https://gymnasium.farama.org/main/api/experimental/ are aimed to replace the wrappers in gymnasium v0.30.0 and contain several improvements
LambaActionV0. We don't expect these version numbers to change regularly and will act similarly to environment version numbers. This should ensure that all users know when significant changes could affect your agent's performance for environments and wrappers. Additionally, we hope that this will improve reproducibility of RL in the future, which is critical for academia.Core developers: @gianlucadecola, @RedTachyon, @pseudo-rnd-thoughts
The Env class provides a very generic structure for environments to be written in allowing high flexibility in the program structure. However, this limits the ability to efficiently vectorize environments, compartmentalize the environment code, etc. Therefore, the gymnasium.experimental.FuncEnv provides a much more strict structure for environment implementation with stateless functions, for every stage of the environment implementation. This class does not inherit from Env and requires a translation / compatibility class for doing this. We already provide a FuncJaxEnv for converting jax-based FuncEnv to Env. We hope this will help improve the readability of environment implementations along with potential speed-ups for users that vectorize their code.
This API is very experimental so open to changes in the future. We are interested in feedback from users who try to use the API which we believe will be in particular interest to users exploring RL planning, model-based RL and modifying environment functions like the rewards.
Core developers: @RedTachyon, @pseudo-rnd-thoughts, @balisujohn
Viewer in favor of MujocoRenderer which offscreen, human and other render mode can use by @rodrigodelazcano in https://github.com/Farama-Foundation/Gymnasium/pull/112gym.make(..., apply_env_compatibility=True) in favour of gym.make("GymV22Environment", env_id="...") by @pseudo-rnd-thoughts in https://github.com/Farama-Foundation/Gymnasium/pull/125gymnasium.pprint_registry() for pretty printing the gymnasium registry by @kad99kev in https://github.com/Farama-Foundation/Gymnasium/pull/124Discrete.dtype to np.int64 such that samples are np.int64 not python ints. by @pseudo-rnd-thoughts in https://github.com/Farama-Foundation/Gymnasium/pull/141core.py for Env, Wrapper and more by @pseudo-rnd-thoughts in https://github.com/Farama-Foundation/Gymnasium/pull/39gymnasium.spaces by @pseudo-rnd-thoughts in https://github.com/Farama-Foundation/Gymnasium/pull/37play() resizable by @Markus28 in https://github.com/Farama-Foundation/Gymnasium/pull/190VideoRecorder wrapper by @younik in https://github.com/Farama-Foundation/Gymnasium/pull/42seeding.np_random error message to report seed type by @theo-brown in https://github.com/Farama-Foundation/Gymnasium/pull/74check_env and PassiveEnvChecker by @Markus28 in https://github.com/Farama-Foundation/Gymnasium/pull/117__all__ in root __init__.py to specify the correct folders by @pseudo-rnd-thoughts in https://github.com/Farama-Foundation/Gymnasium/pull/130play() assertion error by @Markus28 in https://github.com/Farama-Foundation/Gymnasium/pull/132is_slippy by @MarionJS in https://github.com/Farama-Foundation/Gymnasium/pull/136render_mode is None by @younik in https://github.com/Farama-Foundation/Gymnasium/pull/143is_np_flattenable property to documentation by @Markus28 in https://github.com/Farama-Foundation/Gymnasium/pull/172AsyncVectorEnv for success before splitting result in step_wait by @aaronwalsman in https://github.com/Farama-Foundation/Gymnasium/pull/178MuJoCo.Ant-v4.use_contact_forces by @Kallinteris-Andreas in https://github.com/Farama-Foundation/Gymnasium/pull/183MuJoCo.Ant v4 changelog by @Kallinteris-Andreas in https://github.com/Farama-Foundation/Gymnasium/pull/186MuJoCo.Ant action order in documentation by @Kallinteris-Andreas in https://github.com/Farama-Foundation/Gymnasium/pull/208raise-from exception for the whole codebase by @cool-RR in https://github.com/Farama-Foundation/Gymnasium/pull/205pre-commit hooks for better code quality by @XuehaiPan in https://github.com/Farama-Foundation/Gymnasium/pull/179Note: ale-py (atari) has not updated to Gymnasium yet. Therefore pip install gymnasium[atari] will fail, this will be fixed in v0.27. In the meantime,
Note: ale-py (atari) has not updated to Gymnasium yet. Therefore pip install gymnasium[atari] will fail, this will be fixed in v0.27. In the meantime, use pip install shimmy[atari] for the fix.
HumanRendering and RenderCollection wrappers to have the correct metadata by @RedTachyon in https://github.com/Farama-Foundation/Gymnasium/pull/35EpisodeStatisticsRecorder wrapper by @DavidSlayback in https://github.com/Farama-Foundation/Gymnasium/pull/31Full Changelog: https://github.com/Farama-Foundation/Gymnasium/compare/v0.26.2...v0.26.3
This Release is an upstreamed version of Gym v26.2
This Release is an upstreamed version of Gym v26.2
This Release is an upstreamed version of Gym v26.1
Nothing published for this version
Your coding agent can read these notes before it upgrades. Set up the MCP server →