Convert Figma logo to code with AI

openai logomulti-agent-emergence-environments

Environment generation code for the paper "Emergent Tool Use From Multi-Agent Autocurricula"

1,627
302
1,627
27

Top Related Projects

OpenSpiel is a collection of environments and algorithms for research in general reinforcement learning and search/planning in games.

17,044

The Unity Machine Learning Agents Toolkit (ML-Agents) is an open-source project that enables games and simulations to serve as environments for training intelligent agents using deep reinforcement learning and imitation learning.

An API standard for multi-agent reinforcement learning environments, with popular reference environments and related utilities

An API standard for single-agent reinforcement learning environments, with popular reference environments and related utilities (formerly Gym)

Check out the new game server:

1,069

SMAC: The StarCraft Multi-Agent Challenge

Quick Overview

The openai/multi-agent-emergence-environments repository is a collection of environments for studying the emergence of complex behaviors in multi-agent reinforcement learning. It provides a set of challenging scenarios where agents must learn to cooperate or compete to achieve their goals, enabling researchers to explore emergent behaviors and strategies in multi-agent systems.

Pros

  • Offers a diverse range of multi-agent environments for research
  • Facilitates the study of emergent behaviors in complex systems
  • Provides a standardized platform for comparing different multi-agent learning algorithms
  • Supports integration with popular reinforcement learning frameworks

Cons

  • Limited documentation and examples for some environments
  • May require significant computational resources for training complex multi-agent systems
  • Some environments may be too specialized for general-purpose research
  • Potential learning curve for researchers new to multi-agent reinforcement learning

Code Examples

# Example 1: Importing and creating a simple environment
import gym
import ma_gym

env = gym.make('PredatorPrey5x5-v0')
obs_n = env.reset()

for _ in range(100):
    actions = [env.action_space.sample() for _ in range(env.n_agents)]
    obs_n, reward_n, done_n, info = env.step(actions)
    env.render()

This example demonstrates how to import and create a simple predator-prey environment, reset it, and run a basic loop with random actions.

# Example 2: Using a custom environment
from ma_gym.envs.traffic_junction import TrafficJunction

env = TrafficJunction()
obs = env.reset()

for _ in range(100):
    actions = [env.action_space.sample() for _ in range(env.n_agents)]
    obs, rewards, dones, info = env.step(actions)
    env.render()

This example shows how to use a custom environment (TrafficJunction) from the ma_gym package, initialize it, and run a simulation loop.

# Example 3: Accessing environment information
env = gym.make('PredatorPrey5x5-v0')
print(f"Number of agents: {env.n_agents}")
print(f"Observation space: {env.observation_space}")
print(f"Action space: {env.action_space}")

This example demonstrates how to access important information about the environment, such as the number of agents, observation space, and action space.

Getting Started

To get started with the multi-agent-emergence-environments:

  1. Clone the repository:

    git clone https://github.com/openai/multi-agent-emergence-environments.git
    cd multi-agent-emergence-environments
    
  2. Install the required dependencies:

    pip install -r requirements.txt
    
  3. Run a simple example:

    import gym
    import ma_gym
    
    env = gym.make('PredatorPrey5x5-v0')
    obs_n = env.reset()
    env.render()
    
    for _ in range(100):
        actions = [env.action_space.sample() for _ in range(env.n_agents)]
        obs_n, reward_n, done_n, info = env.step(actions)
        env.render()
    

This will create a predator-prey environment, reset it, and run a simulation with random actions for 100 steps, rendering the environment at each step.

Competitor Comparisons

OpenSpiel is a collection of environments and algorithms for research in general reinforcement learning and search/planning in games.

Pros of open_spiel

  • Broader scope: Covers a wide range of games and algorithms
  • More extensive documentation and examples
  • Active development and community support

Cons of open_spiel

  • Higher complexity: Steeper learning curve for beginners
  • Less focus on emergent behaviors in multi-agent systems
  • Potentially slower execution due to its comprehensive nature

Code Comparison

multi-agent-emergence-environments:

env = gym.make('SumoAnts-v0')
obs = env.reset()
action = env.action_space.sample()
next_obs, reward, done, info = env.step(action)

open_spiel:

game = pyspiel.load_game("tic_tac_toe")
state = game.new_initial_state()
legal_actions = state.legal_actions()
action = np.random.choice(legal_actions)
state.apply_action(action)

Both repositories provide environments for multi-agent reinforcement learning, but open_spiel offers a more comprehensive set of games and algorithms. multi-agent-emergence-environments focuses on emergent behaviors in specific scenarios, while open_spiel provides a broader framework for game-theoretic research. The code examples illustrate the different approaches: multi-agent-emergence-environments uses a gym-like interface, while open_spiel employs a more game-specific API.

17,044

The Unity Machine Learning Agents Toolkit (ML-Agents) is an open-source project that enables games and simulations to serve as environments for training intelligent agents using deep reinforcement learning and imitation learning.

Pros of ml-agents

  • Integrated with Unity game engine, providing a robust and flexible environment for developing AI agents
  • Extensive documentation and tutorials, making it more accessible for beginners
  • Supports a wide range of learning algorithms and environments

Cons of ml-agents

  • Requires knowledge of Unity and C#, which may have a steeper learning curve for some users
  • Less focused on multi-agent scenarios compared to multi-agent-emergence-environments

Code Comparison

ml-agents:

public class RollerAgent : Agent
{
    public override void OnEpisodeBegin()
    {
        // Reset agent position and state
    }
}

multi-agent-emergence-environments:

class SimpleAgent(Agent):
    def reset(self):
        # Reset agent position and state
        return self.observe()

Both repositories provide frameworks for developing AI agents, but they differ in their focus and implementation. ml-agents is tightly integrated with Unity, offering a more comprehensive toolkit for game developers and researchers. multi-agent-emergence-environments, on the other hand, is more specialized in studying emergent behaviors in multi-agent systems, using simpler environments built with Python.

An API standard for multi-agent reinforcement learning environments, with popular reference environments and related utilities

Pros of PettingZoo

  • Broader scope: Supports a wide range of multi-agent environments beyond emergent behavior scenarios
  • Active development: Regularly updated with new features and environments
  • Extensive documentation: Comprehensive guides and examples for users

Cons of PettingZoo

  • Less focused on emergent behavior: May not provide specialized tools for studying emergence
  • Steeper learning curve: Due to its broader scope, it might be more complex for beginners

Code Comparison

PettingZoo:

from pettingzoo.butterfly import knights_archers_zombies_v10
env = knights_archers_zombies_v10.env()
env.reset()
for agent in env.agent_iter():
    observation, reward, termination, truncation, info = env.last()
    action = env.action_space(agent).sample()
    env.step(action)

Multi-agent-emergence-environments:

from mujoco_worldgen import Floor, WorldBuilder
from mujoco_worldgen.util.types import store_args
from multi_agent_emergence_environments.scenarios.base import BaseScenario

class Scenario(BaseScenario):
    @store_args
    def __init__(self, n_agents):
        super().__init__()

An API standard for single-agent reinforcement learning environments, with popular reference environments and related utilities (formerly Gym)

Pros of Gymnasium

  • Broader scope, supporting a wide range of reinforcement learning environments
  • More active development and larger community support
  • Extensive documentation and examples for easier implementation

Cons of Gymnasium

  • Less focused on multi-agent scenarios
  • May require additional setup for complex multi-agent environments
  • Potentially steeper learning curve for beginners in multi-agent RL

Code Comparison

Multi-agent-emergence-environments:

env = gym.make('ma_envs:PredatorPrey5x5-v0')
obs = env.reset()
action = env.action_space.sample()
next_obs, reward, done, info = env.step(action)

Gymnasium:

env = gymnasium.make('CartPole-v1')
observation, info = env.reset(seed=42)
action = env.action_space.sample()
observation, reward, terminated, truncated, info = env.step(action)

While both use similar API structures, Multi-agent-emergence-environments is tailored for multi-agent scenarios, whereas Gymnasium provides a more general-purpose framework for reinforcement learning environments.

Check out the new game server:

Pros of Football

  • More realistic simulation of a complex team sport
  • Supports both single-agent and multi-agent scenarios
  • Includes a comprehensive set of pre-defined scenarios and reward functions

Cons of Football

  • Limited to a single sport, less versatile for general multi-agent research
  • Higher computational requirements due to more complex environment
  • Steeper learning curve for researchers unfamiliar with soccer/football rules

Code Comparison

Football:

env = football_env.create_environment(
    env_name="11_vs_11_stochastic",
    representation="raw",
    rewards="scoring,checkpoints"
)

Multi-agent-emergence-environments:

env = gym.make('SumoAnts-v0')
env.reset()

Key Differences

Multi-agent-emergence-environments focuses on simpler, more abstract environments that allow for emergent behaviors, while Football provides a more structured and realistic simulation of a specific sport. The former is better suited for studying fundamental multi-agent interactions, while the latter is ideal for research on complex team strategies and decision-making in a well-defined context.

1,069

SMAC: The StarCraft Multi-Agent Challenge

Pros of SMAC

  • More focused on multi-agent reinforcement learning in StarCraft II
  • Provides a standardized benchmark for MARL research
  • Includes pre-built scenarios and evaluation metrics

Cons of SMAC

  • Limited to StarCraft II environment
  • Less flexibility in creating custom scenarios
  • May require more domain-specific knowledge to use effectively

Code Comparison

SMAC environment setup:

from smac.env import StarCraft2Env

env = StarCraft2Env(map_name="8m")
env.reset()

Multi-Agent Emergence Environments setup:

from mage import make_env

env = make_env("hide_and_seek")
env.reset()

Key Differences

  • SMAC is specifically designed for StarCraft II, while Multi-Agent Emergence Environments offer a broader range of scenarios
  • Multi-Agent Emergence Environments focus on emergent behaviors, while SMAC emphasizes tactical coordination
  • SMAC provides more structured scenarios, whereas Multi-Agent Emergence Environments allow for more open-ended interactions

Both repositories offer valuable tools for multi-agent research, with SMAC being more specialized and Multi-Agent Emergence Environments providing greater flexibility across different domains.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Status: Archive (code is provided as-is, no updates expected)

Multiagent emergence environments

Environment generation code for Emergent Tool Use From Multi-Agent Autocurricula (blog)

Installation

This repository depends on the mujoco-worldgen package. You will need to clone the mujoco-worldgen repository and install it and its dependencies:

pip install -r mujoco-worldgen/requirements.txt
pip install -e mujoco-worldgen/
pip install -e multi-agent-emergence-environments/

This repository has been tested only on Mac OS X and Ubuntu 16.04 with Python 3.6

Use

Environment construction works in the following way: You start from the Base environment (defined in mae_envs/envs/base.py) and then you add environment modules (e.g. Boxes, Ramps, RandomWalls, etc.) and then wrappers on top. You can see examples in the mae_envs/envs folder.

If you want to construct a new environment, we highly recommend using the above paradigm in order to minimize code duplication. If you need new objects or game dynamics that don't already exist in this codebase, add them in via a new EnvModule class or a gym.Wrapper class rather than subclassing Base (or mujoco-worldgen's Env class). In general, EnvModules should be used for adding objects or sites to the environment, or otherwise modifying the mujoco simulator; wrappers should be used for everything else (e.g. adding rewards, additional observations, or implementing game mechanics like Lock and Grab).

The environments defined in this repository are:
Hide and seek - mae_envs/envs/hide_and_seek.py - The Hide and Seek environment described in the paper. This encompasses the random rooms, quadrant and food versions of the game (you can switch between them by changing the arguments given to the make_env function in the file)
Box locking - mae_envs/envs/box_locking.py - Encompasses the Lock and Return and Sequential Lock transfer tasks described in the paper.
Blueprint Construction - mae_envs/envs/blueprint_construction.py
Shelter Construction - mae_envs/envs/shelter_construction.py

You can test out environments by using the bin/examine script. Example usage: bin/examine.py base.
You can also use bin/examine to play a saved policy on an environment. There are several environment jsonnets and policies in the examples folder. Example usage:

bin/examine.py examples/hide_and_seek_quadrant.jsonnet examples/hide_and_seek_quadrant.npz

Note that to be able to play saved policies, you will need to install a few additional packages. You can do this via

pip install -r multi-agent-emergence-environments/requirements_ma_policy.txt