Skip to content

Commit 7bd8172

Browse files
montplaisiralexander-zapAmineAndam04OliviaBayleyvadim0x60
authored
Migrate gym to gymnasium (#6309)
Migrate from Gym to Gymnasium (gymnasium>=0.26.0) Upgrade Pettingzoo to 1.24.0 Relax the dependencies for Numpy Reference PRs: - #6211 Pettingzoo wrapper changed to gymnasium interface - #6203 Upgrade to Gymnasium interface - #6166 Update Gym to Gymnasium - #6136 Update unity_pettingzoo_base_env.py - #6060 Upgraded from gym to Gymnasium Co-authored-by: alexander-zap <65029346+alexander-zap@users.noreply.github.com> Co-authored-by: AmineAndam04 <andamamine83@gmail.com> Co-authored-by: Olivia Bayley <150163193+OliviaBayley@users.noreply.github.com> Co-authored-by: Vadim Liventsev <dev@vadim.me> Co-authored-by: Zachary Laborde <zachlaborde93@gmail.com>
1 parent 47c965c commit 7bd8172

17 files changed

Lines changed: 370 additions & 212 deletions

colab/Colab_UnityEnvironment_4_SB3VectorEnv.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@
161161
"from pathlib import Path\n",
162162
"from typing import Callable, Any\n",
163163
"\n",
164-
"import gym\n",
165-
"from gym import Env\n",
164+
"import gymnasium as gym\n",
165+
"from gymnasium import Env\n",
166166
"\n",
167167
"from stable_baselines3 import PPO\n",
168168
"from stable_baselines3.common.vec_env import VecMonitor, VecEnv, SubprocVecEnv\n",

com.unity.ml-agents/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to
77
[Semantic Versioning](http://semver.org/spec/v2.0.0.html).
88

99
## [Unreleased]
10+
### Major Changes
11+
#### ml-agents / ml-agents-envs
12+
- Migrated from gym to gymnasium (#6309)
13+
1014
### Minor Changes
1115
#### com.unity.ml-agents (C#)
1216
- Fixed StackingSensor compressed observation for sensors with more than 3 channels. (#6299)

com.unity.ml-agents/Documentation~/ML-Agents-Overview.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ The ML-Agents Toolkit contains five high-level components:
2828
- **Python Low-Level API** - which contains a low-level Python interface for interacting and manipulating a learning environment. Note that, unlike the Learning Environment, the Python API is not part of Unity, but lives outside and communicates with Unity through the Communicator. This API is contained in a dedicated `mlagents_envs` Python package and is used by the Python training process to communicate with and control the Academy during training. However, it can be used for other purposes as well. For example, you could use the API to use Unity as the simulation engine for your own machine learning algorithms. See [Python API](Python-LLAPI.md) for more information.
2929
- **External Communicator** - which connects the Learning Environment with the Python Low-Level API. It lives within the Learning Environment.
3030
- **Python Trainers** which contains all the machine learning algorithms that enable training agents. The algorithms are implemented in Python and are part of their own `mlagents` Python package. The package exposes a single command-line utility `mlagents-learn` that supports all the training methods and options outlined in this document. The Python Trainers interface solely with the Python Low-Level API.
31-
- **Gym Wrapper** (not pictured). A common way in which machine learning researchers interact with simulation environments is via a wrapper provided by OpenAI called [gym](https://github.com/openai/gym). We provide a gym wrapper in the `ml-agents-envs` package and [instructions](Python-Gym-API.md) for using it with existing machine learning algorithms which utilize gym.
32-
- **PettingZoo Wrapper** (not pictured) PettingZoo is python API for interacting with multi-agent simulation environments that provides a gym-like interface. We provide a PettingZoo wrapper for Unity ML-Agents environments in the `ml-agents-envs` package and [instructions](Python-PettingZoo-API.md) for using it with machine learning algorithms.
31+
- **Gym Wrapper** (not pictured). A common way in which machine learning researchers interact with simulation environments is via a wrapper provided by the Farama Foundation called [gymnasium](https://gymnasium.farama.org/) (formerly OpenAI `gym`). Unity provides a gym wrapper in the `ml-agents-envs` package and [instructions](Python-Gym-API.md) for using it with existing machine learning algorithms which utilize gymnasium.
32+
- **PettingZoo Wrapper** (not pictured) PettingZoo is python API for interacting with multi-agent simulation environments that provides a gym-like interface. Unity provides a PettingZoo wrapper for Unity ML-Agents environments in the `ml-agents-envs` package and [instructions](Python-PettingZoo-API.md) for using it with machine learning algorithms.
3333

3434
<p align="center"> <img src="images/learning_environment_basic.png" alt="Simplified ML-Agents Scene Block Diagram" width="600" border="10" /> </p>
3535

@@ -68,7 +68,7 @@ It is important to note that the ML-Agents Toolkit leverages [Sentis](Inference-
6868

6969
### Custom Training and Inference
7070

71-
In the previous mode, the Agents were used for training to generate a PyTorch model that the Agents can later use. However, any user of the ML-Agents Toolkit can leverage their own algorithms for training. In this case, the behaviors of all the Agents in the scene will be controlled within Python. You can even turn your environment into a [gym.](Python-Gym-API.md)
71+
In the previous mode, the Agents were used for training to generate a PyTorch model that the Agents can later use. However, any user of the ML-Agents Toolkit can leverage their own algorithms for training. In this case, the behaviors of all the Agents in the scene will be controlled within Python. You can even turn your environment into a [gymnasium environment.](Python-Gym-API.md)
7272

7373
Unity doesn't provide a tutorial highlighting this mode, but you can learn more about the Python API in [Unity ML-Agents Python Low Level API](Python-LLAPI.md).
7474

com.unity.ml-agents/Documentation~/Python-Gym-API-Documentation.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,19 @@ Environment initialization
4242
#### reset
4343

4444
```python
45-
| reset() -> Union[List[np.ndarray], np.ndarray]
45+
| reset(*, seed: Optional[int] = None, options: Optional[Dict[str, Any]] = None) -> Tuple[np.ndarray, Dict]
4646
```
4747

48-
Resets the state of the environment and returns an initial observation. Returns: observation (object/list): the initial observation of the space.
48+
Resets the state of the environment and returns an initial observation and info. Returns: observation (object/list): the initial observation of the space. info (dict): contains auxiliary diagnostic information.
4949

5050
<a name="mlagents_envs.envs.unity_gym_env.UnityToGymWrapper.step"></a>
5151
#### step
5252

5353
```python
54-
| step(action: List[Any]) -> GymStepResult
54+
| step(action: Any) -> GymStepResult
5555
```
5656

57-
Run one timestep of the environment's dynamics. When end of episode is reached, you are responsible for calling `reset()` to reset this environment's state. Accepts an action and returns a tuple (observation, reward, done, info).
57+
Run one timestep of the environment's dynamics. When end of episode is reached, you are responsible for calling `reset()` to reset this environment's state. Accepts an action and returns a tuple (observation, reward, terminated, truncated, info).
5858

5959
**Arguments**:
6060

@@ -63,14 +63,15 @@ Run one timestep of the environment's dynamics. When end of episode is reached,
6363
**Returns**:
6464

6565
- `observation` _object/list_ - agent's observation of the current environment reward (float/list) : amount of reward returned after previous action
66-
- `done` _boolean/list_ - whether the episode has ended.
66+
- `terminated` _boolean/list_ - whether the episode has ended by termination.
67+
- `truncated` _boolean/list_ - whether the episode has ended by truncation.
6768
- `info` _dict_ - contains auxiliary diagnostic information.
6869

6970
<a name="mlagents_envs.envs.unity_gym_env.UnityToGymWrapper.render"></a>
7071
#### render
7172

7273
```python
73-
| render(mode="rgb_array")
74+
| render()
7475
```
7576

7677
Return the latest visual observations. Note that it will not render a new frame of the environment.

0 commit comments

Comments
 (0)