InforMARL: Scalable Multi-Agent Reinforcement Learning Framework

repository·main·Indexed 41 days ago

https://github.com/nsidn98/informarl

A Graph Neural Network (GNN) framework for Scalable Multi-Agent Reinforcement Learning (MARL), focusing on multi-agent navigation and collision avoidance with limited local observability. It includes implementations of DGN, GPG, and MPNN, as well as baselines for MVDN, VDN, QMIX, MQMIX, MADDPG, RMADDPG, MATD3, and RMATD3. The framework provides various environments including the Surviving environment, Gym Flock (FormationFlying-v3), and the Multi-Agent Particle Environment (MPE).

Tokens
9.2K
Snippets
32
Records
57
Agent score
50%

What's inside InforMARL

  1. Code structure of the Multi-Agent Particle Environment

    main

    Understanding the module layout for integration or customization:

    • make_env.py: Provides code for importing a multiagent environment as an OpenAI Gym-like object.
    • ./multiagent/environment.py: Core simulation logic, including interaction physics and the _step() function.
    • ./multiagent/core.py: Defines base classes for Entities, Landmarks, Agents, etc.
    • ./multiagent/rendering.py: Handles visual display of agent behaviors.
    • ./multiagent/policy.py: Contains interactive policies driven by keyboard input.
    • ./multiagent/scenario.py: The base scenario object used for all specific scenarios.
    • ./multiagent/scenarios/: Directory containing individual scenario implementations.
  2. Evaluate DGN using the Surviving environment

    main

    The Surviving environment is a large-scale multi-agent environment designed to evaluate DGN.

    Environment Specifications:

    • Scale: 100 agents interacting in a grid-based world.
    • Observations: Each agent has a limited local observation consisting of a 3x3 grid centered on the agent.
    • Communication: Agents can communicate with neighbors within a 7x7 grid region.
    • Actions: At each timestep, an agent can move to one of four neighboring grids or eat food at its current location.
    • Mechanics:
      • Agents start with 10 health.
      • Agents lose 1 health per step.
      • Eating food increases health.
    • Rewards:
      • If health reaches 0: -0.2 reward.
      • If agent survives: 0.4 reward.
  3. How to create new environments/scenarios

    main

    New scenarios are created by extending the base scenario object and implementing four required functions. These functions define the world's inhabitants, their properties, and the rules of the game.

    Required functions to implement:

    1. make_world(): Creates all entities (landmarks, agents, etc.) and assigns capabilities (e.g., whether they can communicate or move). Called once at the start of a training session.
    2. reset_world(): Resets properties like position and color for all entities. Called before every episode.
    3. reward(): Defines the reward function for a given agent.
    4. observation(): Defines the observation space for a given agent.

    Optional function:

    • benchmark_data(): Provides diagnostic data or evaluation metrics for trained policies.
    # Implementation skeleton for a new scenario
    def make_world():
        pass
    
    def reset_world():
        pass
    
    def reward():
        pass
    
    def observation():
        pass
    
    def benchmark_data():
        pass
  4. Install dependencies for GPG

    main

    To run the GPG (Graph Policy Gradient) baseline, you must install the following dependencies:

    1. Deep Graph Library (DGL): Visit https://www.dgl.ai/ for installation instructions.
    2. PyTorch: Ensure you have a version compatible with your installed DGL version.
    3. gym_formation: You must install gym_formation following the specific instructions located within its own repository/folder before running GPG.
  5. Transfer Training to a Larger Team

    main

    You can continue training from a previously saved model to transfer learned behaviors to a team with a different number of agents. Use the --continue-training flag along with --load-dir pointing to the saved model file.

    # Example: Transferring a policy trained with 3 agents to a team of 5 agents in simple_spread
    python main.py --env-name simple_spread --entity-mp --continue-training --load-dir models/ss/na3_uc.pt --num-agents 5
  6. Use the FormationFlying-v3 environment

    main

    Gym Flock provides the FormationFlying-v3 environment, which is compatible with the standard OpenAI Gym API. You can interface with it using env.reset() and env.step().

    Additionally, these implementations include an env.controller() method, which returns the best current set of actions suitable for imitation learning tasks.

    import gym
    import gym_flock
    
    # Initialize the environment
    env = gym.make("FormationFlying-v3")
    
    # Standard Gym interface
    obs = env.reset()
    # ... in your loop ...
    # action = agent.get_action(obs)
    # next_obs, reward, done, info = env.step(action)
    
    # For imitation learning, use the built-in controller
    # best_actions = env.controller()
  7. Train InforMARL using the CLI

    main

    To train the InforMARL model, run the onpolicy/scripts/train_mpe.py script with the required arguments. Key arguments include --env_name (e.g., GraphMPE), --algorithm_name (e.g., rmappo), and --scenario_name (e.g., navigation_graph).

    python -u onpolicy/scripts/train_mpe.py --use_valuenorm --use_popart \
    --project_name "informarl" \
    --env_name "GraphMPE" \
    --algorithm_name "rmappo" \
    --seed 0 \
    --experiment_name "informarl" \
    --scenario_name "navigation_graph" \
    --num_agents 3 \
    --collision_rew 5 \
    --n_training_threads 1 --n_rollout_threads 128 \
    --num_mini_batch 1 \
    --episode_length 25 \
    --num_env_steps 2000000 \
    --ppo_epoch 10 --use_ReLU --gain 0.01 --lr 7e-4 --critic_lr 7e-4 \
    --user_name "marl" \
    --use_cent_obs "False" \
    --graph_feat_type "relative" \
    --auto_mini_batch_size --target_mini_batch_size 128