You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Feature] Terminated/truncated support and Gymnasium wrapper (#143)
* add gymnasium integration but maintain openai gym support
* update documentation (default being gym)
* by default preserve original interface of all functions
* Update gymnasium/ gym integration
- base VMAS environment uses OpenAI gym spaces
- base VMAS environment has new flag `terminated_truncated` (default:
False) that determines whether `done()` and `step()` return the
default `done` value or separate values for `terminated` and
`truncated`
- update `gymnasium` wrapper to convert gym spaces of base environment
to gymnasium spaces
- add `gymnasium_vec` wrapper that can wrap vectorized VMAS environment
as gymnasium environment
- add new installation options of VMAS for optional dependencies (used
for features like rllib, torchrl, gymnasium, rendering, testing)
- add `return_numpy` flag in gymnasium wrappers (default: True) to
determine whether to convert torch tensors to numpy --> passed through by `make_env` function
- add `render_mode` flag in gymnasium wrappers (default: "human") to
determine mode to render --> passed through by `make_env` function
* use gymnasium and shimmy tools to convert spaces + use vmas to_numpy
conversion
* update VMAS wrappers
- add base VMAS wrapper class for type conversion between tensors and np
for singleton and vectorized envs
- change default of gym wrapper to return np data
- update interactive rendering to be compatible with non gym wrapper
class (to preserve tensor types)
- add error messages for gymnasium and rllib wrappers without installing
first
* update vmas wrapper base class, move wrappers and add wrapper tests
* incorporate feedback
- update github dependency installation
- unify get scenario test function and limit wrapper tests to fewer
scenarios
- allow import of all gym wrappers from `vmas.simulator.environment.gym`
- consider env continuous_actions for action type conversion in wrappers
- compress info to single nested info if needed rather than combining
keys
* remove import error
* Revert "remove import error"
This reverts commit 2d0ad62.
* import optional deps only when needed
* relative imports
* installation docs
* interactive render
* docs
* more docs
* various
* small nits
* gym wrapper tests for dict spaces check obs shapes matching obs key
---------
Co-authored-by: Matteo Bettini <[email protected]>
Copy file name to clipboardexpand all lines: README.md
+31-15
Original file line number
Diff line number
Diff line change
@@ -28,7 +28,7 @@ Scenario creation is made simple and modular to incentivize contributions.
28
28
VMAS simulates agents and landmarks of different shapes and supports rotations, elastic collisions, joints, and custom gravity.
29
29
Holonomic motion models are used for the agents to simplify simulation. Custom sensors such as LIDARs are available and the simulator supports inter-agent communication.
30
30
Vectorization in [PyTorch](https://pytorch.org/) allows VMAS to perform simulations in a batch, seamlessly scaling to tens of thousands of parallel environments on accelerated hardware.
31
-
VMAS has an interface compatible with [OpenAI Gym](https://github.com/openai/gym), with [RLlib](https://docs.ray.io/en/latest/rllib/index.html), with [torchrl](https://github.com/pytorch/rl) and its MARL training library: [BenchMARL](https://github.com/facebookresearch/BenchMARL),
31
+
VMAS has an interface compatible with [OpenAI Gym](https://github.com/openai/gym), with [Gymnasium](https://gymnasium.farama.org/), with [RLlib](https://docs.ray.io/en/latest/rllib/index.html), with [torchrl](https://github.com/pytorch/rl) and its MARL training library: [BenchMARL](https://github.com/facebookresearch/BenchMARL),
32
32
enabling out-of-the-box integration with a wide range of RL algorithms.
33
33
The implementation is inspired by [OpenAI's MPE](https://github.com/openai/multiagent-particle-envs).
34
34
Alongside VMAS's scenarios, we port and vectorize all the scenarios in MPE.
By default, vmas has only the core requirements. Here are some optional packages you may want to install:
116
+
By default, vmas has only the core requirements. To install further dependencies to enable training with [Gymnasium](https://gymnasium.farama.org/) wrappers, [RLLib](https://docs.ray.io/en/latest/rllib/index.html) wrappers, for rendering, and testing, you may want to install these further options:
117
117
```bash
118
-
# Training
119
-
pip install "ray[rllib]"==2.1.0 # We support versions "ray[rllib]<=2.2,>=1.13"
120
-
pip install torchrl
118
+
# install gymnasium for gymnasium wrappers
119
+
pip install vmas[gymnasium]
121
120
122
-
#Logging
123
-
pip installl wandb
121
+
#install rllib for rllib wrapper
122
+
pip install vmas[rllib]
124
123
125
-
#Rendering
126
-
pip install opencv-python moviepy matplotlib
124
+
#install rendering dependencies
125
+
pip install vmas[render]
127
126
128
-
# Tests
129
-
pip install pytest pyyaml pytest-instafail tqdm
127
+
# install testing dependencies
128
+
pip install vmas[test]
129
+
130
+
# install all dependencies
131
+
pip install vmas[all]
132
+
```
133
+
134
+
You can also install the following training libraries:
135
+
136
+
```bash
137
+
pip install benchmarl # For training in BenchMARL
138
+
pip install torchrl # For training in TorchRL
139
+
pip install "ray[rllib]"==2.1.0 # For training in RLlib. We support versions "ray[rllib]<=2.2,>=1.13"
130
140
```
131
141
132
142
### Run
133
143
134
144
To use the simulator, simply create an environment by passing the name of the scenario
135
145
you want (from the `scenarios` folder) to the `make_env` function.
136
-
The function arguments are explained in the documentation. The function returns an environment
137
-
object with the OpenAI gym interface:
146
+
The function arguments are explained in the documentation. The function returns an environment object with the VMAS interface:
138
147
139
148
Here is an example:
140
149
```python
@@ -143,17 +152,24 @@ Here is an example:
143
152
num_envs=32,
144
153
device="cpu", # Or "cuda" for GPU
145
154
continuous_actions=True,
146
-
wrapper=None, # One of: None, vmas.Wrapper.RLLIB, and vmas.Wrapper.GYM
155
+
wrapper=None, # One of: None, "rllib", "gym", "gymnasium", "gymnasium_vec"
147
156
max_steps=None, # Defines the horizon. None is infinite horizon.
148
157
seed=None, # Seed of the environment
149
158
dict_spaces=False, # By default tuple spaces are used with each element in the tuple being an agent.
150
159
# If dict_spaces=True, the spaces will become Dict with each key being the agent's name
151
160
grad_enabled=False, # If grad_enabled the simulator is differentiable and gradients can flow from output to input
161
+
terminated_truncated=False, # If terminated_truncated the simulator will return separate `terminated` and `truncated` flags in the `done()`, `step()`, and `get_from_scenario()` functions instead of a single `done` flag
152
162
**kwargs # Additional arguments you want to pass to the scenario initialization
153
163
)
154
164
```
155
165
A further example that you can run is contained in `use_vmas_env.py` in the `examples` directory.
156
166
167
+
With the `terminated_truncated` flag set to `True`, the simulator will return separate `terminated` and `truncated` flags
168
+
in the `done()`, `step()`, and `get_from_scenario()` functions instead of a single `done` flag.
169
+
This is useful when you want to know if the environment is done because the episode has ended or
170
+
because the maximum episode length/ timestep horizon has been reached.
171
+
See [the Gymnasium documentation](https://gymnasium.farama.org/tutorials/gymnasium_basics/handling_time_limits/) for more details on this.
172
+
157
173
#### RLlib
158
174
159
175
To see how to use VMAS in RLlib, check out the script in `examples/rllib.py`.
@@ -235,7 +251,7 @@ Each format will work regardless of the fact that tuples or dictionary spaces ha
235
251
-**Simple**: Complex vectorized physics engines exist (e.g., [Brax](https://github.com/google/brax)), but they do not scale efficiently when dealing with multiple agents. This defeats the computational speed goal set by vectorization. VMAS uses a simple custom 2D dynamics engine written in PyTorch to provide fast simulation.
236
252
-**General**: The core of VMAS is structured so that it can be used to implement general high-level multi-robot problems in 2D. It can support adversarial as well as cooperative scenarios. Holonomic point-robot simulation has been chosen to focus on general high-level problems, without learning low-level custom robot controls through MARL.
237
253
-**Extensible**: VMAS is not just a simulator with a set of environments. It is a framework that can be used to create new multi-agent scenarios in a format that is usable by the whole MARL community. For this purpose, we have modularized the process of creating a task and introduced interactive rendering to debug it. You can define your own scenario in minutes. Have a look at the dedicated section in this document.
238
-
-**Compatible**: VMAS has wrappers for [RLlib](https://docs.ray.io/en/latest/rllib/index.html), [torchrl](https://pytorch.org/rl/reference/generated/torchrl.envs.libs.vmas.VmasEnv.html), and [OpenAI Gym](https://github.com/openai/gym). RLlib and torchrl have a large number of already implemented RL algorithms.
254
+
-**Compatible**: VMAS has wrappers for [RLlib](https://docs.ray.io/en/latest/rllib/index.html), [torchrl](https://pytorch.org/rl/reference/generated/torchrl.envs.libs.vmas.VmasEnv.html), [OpenAI Gym](https://github.com/openai/gym) and [Gymnasium](https://gymnasium.farama.org/). RLlib and torchrl have a large number of already implemented RL algorithms.
239
255
Keep in mind that this interface is less efficient than the unwrapped version. For an example of wrapping, see the main of `make_env`.
240
256
-**Tested**: Our scenarios come with tests which run a custom designed heuristic on each scenario.
241
257
-**Entity shapes**: Our entities (agent and landmarks) can have different customizable shapes (spheres, boxes, lines).
0 commit comments