vmas

make_env(scenario: str | BaseScenario, num_envs: int, device: device | str | int = 'cpu', continuous_actions: bool = True, wrapper: Wrapper | str | None = None, max_steps: int | None = None, seed: int | None = None, dict_spaces: bool = False, multidiscrete_actions: bool = False, clamp_actions: bool = False, grad_enabled: bool = False, terminated_truncated: bool = False, wrapper_kwargs: dict | None = None, **kwargs)[source]

Create a vmas environment.

Parameters:
  • scenario (Union[str, BaseScenario]) – Scenario to load. Can be the name of a file in vmas.scenarios folder or a BaseScenario class,

  • num_envs (int) – Number of vectorized simulation environments. VMAS performs vectorized simulations using PyTorch. This argument indicates the number of vectorized environments that should be simulated in a batch. It will also determine the batch size of the environment.

  • device (Union[str, int, torch.device], optional) – Device for simulation. All the tensors created by VMAS will be placed on this device. Default is "cpu",

  • continuous_actions (bool, optional) – Whether to use continuous actions. If False, actions will be discrete. The number of actions and their size will depend on the chosen scenario. Default is True,

  • wrapper (Union[Wrapper, str], optional) – Wrapper class to use. For example, it can be "rllib", "gym", "gymnasium", "gymnasium_vec". Default is None.

  • max_steps (int, optional) – Horizon of the task. Defaults to None (infinite horizon). Each VMAS scenario can be terminating or not. If max_steps is specified, the scenario is also terminated whenever this horizon is reached,

  • seed (int, optional) – Seed for the environment. Defaults to None,

  • dict_spaces (bool, optional) – Weather to use dictionaries spaces with format {"agent_name": tensor, ...} for obs, rewards, and info instead of tuples. Defaults to False: obs, rewards, info are tuples with length number of agents,

  • multidiscrete_actions (bool, optional) – Whether to use multidiscrete action spaces when continuous_actions=False. Default is False: the action space will be Discrete, and it will be the cartesian product of the discrete action spaces available to an agent,

  • clamp_actions (bool, optional) – Weather to clamp input actions to their range instead of throwing an error when continuous_actions==True and actions are out of bounds,

  • grad_enabled (bool, optional) – If True the simulator will not call detach() on input actions and gradients can be taken from the simulator output. Default is False.

  • terminated_truncated (bool, optional) – Weather to use terminated and truncated flags in the output of the step method (or single done). Default is False.

  • wrapper_kwargs (dict, optional) – Keyword arguments to pass to the wrapper class. Default is {}.

  • **kwargs (dict, optional) – Keyword arguments to pass to the BaseScenario class.

Examples

>>> from vmas import make_env
>>> env = make_env(
...     "waterfall",
...     num_envs=3,
...     num_agents=2,
... )
>>> print(env.reset())
render_interactively(scenario: str | BaseScenario, control_two_agents: bool = False, display_info: bool = True, save_render: bool = False, **kwargs)[source]

Executes a scenario and renders it so that you can debug and control agents interactively.

You can change the agent to control by pressing TAB. You can reset the environment by pressing R. You can control agent actions with the arrow keys and M/N (left/right control the first action, up/down control the second, M/N controls the third)

If you have more than 1 agent, you can control another one with W,A,S,D and Q,E in the same way. and switch the agent using LSHIFT.

Parameters:
  • scenario (Union[str, BaseScenario]) – Scenario to load. Can be the name of a file in vmas.scenarios folder or a BaseScenario class

  • control_two_agents (bool, optional) – Whether to control two agents or just one. Defaults to False.

  • display_info (bool, optional) – Whether to display on the screen the following info from the first controlled agent: name, reward, total reward, done, and observation. Defaults to True.

  • save_render (bool, optional) – Whether to save a video of the render up to the first reset. The video will be saved in the directory of this file with the name {scenario}_interactive. Defaults to False.

Examples

>>> from vmas import render_interactively
>>> render_interactively(
...     "waterfall",
...     control_two_agents=True,
...     save_render=False,
...     display_info=True,
... )
scenarios = ['balance', 'ball_passage', 'ball_trajectory', 'buzz_wire', 'discovery', 'dispersion', 'dropout', 'flocking', 'football', 'give_way', 'joint_passage', 'joint_passage_size', 'multi_give_way', 'navigation', 'passage', 'reverse_transport', 'road_traffic', 'sampling', 'transport', 'wheel', 'wind_flocking']

List of the vmas scenarios (excluding MPE and debug)

debug_scenarios = ['asym_joint', 'circle_trajectory', 'diff_drive', 'drone', 'goal', 'het_mass', 'kinematic_bicycle', 'line_trajectory', 'pollock', 'vel_control', 'waterfall']

List of the vmas debug scenarios

mpe_scenarios = ['simple', 'simple_adversary', 'simple_crypto', 'simple_push', 'simple_reference', 'simple_speaker_listener', 'simple_spread', 'simple_tag', 'simple_world_comm']

List of the vmas MPE scenarios