SMACv2 (StarCraft Multi-Agent Challenge v2)

repository·main·Indexed 43 days ago

https://github.com/oxwhirl/smacv2

An improved benchmark for Cooperative Multi-Agent Reinforcement Learning (MARL) focusing on micromanagement in StarCraft II. SMACv2 enhances the original SMAC by providing capabilities for procedural unit distribution and randomized starting positions via the StarCraftCapabilityEnvWrapper.

Tokens
5.4K
Snippets
17
Records
28
Agent score
55%

What's inside SMACv2

  1. Understand the SMAC micromanagement research focus

    main

    SMAC (StarCraft Multi-Agent Challenge) is a research platform designed for evaluating Multi-Agent Reinforcement Learning (MARL) algorithms. Unlike standard StarCraft II gameplay which includes high-level strategy (macromanagement), SMAC focuses exclusively on micromanagement.

    Key characteristics of the SMAC environment include:

    • Decentralized Control: Each unit is controlled by an independent agent.
    • Partial Observability: Agents condition only on local observations restricted to a limited field of view centered on that specific unit.
    • Cooperative Combat: Groups of agents must learn to solve combat scenarios against a scripted AI opponent.
    • Complex Behaviors: The environment is designed to test skills such as focus fire (jointly attacking specific targets), avoiding overkill, kiting (maintaining distance while attacking), and utilizing formations or terrain.
  2. Understand SMAC observations and state vectors

    main

    SMAC provides two types of information: local observations for agents and a global state for centralized training.

    Local Observations

    Agents receive partially observable information within a circular field of view (radius of 9). The observation includes:

    • Unit attributes (for both allies and enemies in sight): distance, relative x, relative y, health, shield, and unit_type.
    • Self-information: The agent's own health, shield, and unit_type are included.
    • Action history: The last actions of allied units within the field of view.
    • Terrain: Eight points at a fixed radius indicating height and walkability.

    Global State

    Used during centralized training, the state vector contains:

    • Coordinates: All agents' coordinates relative to the map center.
    • Unit features: All unit features present in observations.
    • Special attributes: energy for Medivacs and cooldown for other allied units (minimum delay between attacks).
    • Action history: The last actions of all agents.

    All features are normalized by their maximum values.

  3. Understand SMAC scenarios and types

    main

    SMAC (StarCraft Multi-Agent Challenge) consists of micro scenarios designed to evaluate cooperative Multi-Agent Reinforcement Learning (MARL). Scenarios involve a confrontation between two armies: the first army is controlled by learned allied agents, and the second consists of enemy units controlled by a built-in game AI using scripted heuristics.

    Scenarios are categorized by their structure:

    • Symmetric: Both armies have equal compositions.
      • Homogeneous: Each army has only one unit type (e.g., Marines).
      • Heterogeneous: Armies have multiple unit types (e.g., Stalkers and Zealots).
    • Asymmetric: The enemy army outnumbers the allied army.
    • Micro-trick: Scenarios requiring specific coordination techniques, such as:
      • Alternating fire: (e.g., 2m_vs_1z)
      • Kiting: (e.g., 3s_vs_3z)
      • Focus fire: (e.g., 6h_vs_8z)
      • Wall off: (e.g., corridor)
      • Positioning: (e.g., so_many_banelings)

    The goal is to maximize the win rate (ratio of games won to games played).

  4. How to extend SMACv2 procedural generation

    main

    Procedural generation in SMACv2 consists of two parts that a developer can extend:

    1. Implementation: Located in smac/env/starcraft2/starcraft2.py. This part handles the actual logic of spawning units at specific positions using StarCraft APIs, based on the config passed to the reset function.
    2. Distribution: Located in smac/env/starcraft2/distributions.py. This part defines the mathematical distribution (e.g., random across the map) that the implementation follows.

    To add new content, you should implement a new distribution in distributions.py and the corresponding spawning logic in starcraft2.py.

  5. Run MAPPO SMACv2 Baselines

    main

    To run the MAPPO baseline, follow these steps:

    1. Ensure WANDB_API_KEY_FILE is set.
    2. Clone the mappo repository: git clone https://github.com/benellis3/mappo.git.
    3. Build the Docker container by running build.sh inside the docker directory.
    4. Install Starcraft in the mappo directory: ./install_sc2.sh.
    5. Configure src/config/default.yaml: set project to your desired name and entity to your WandB username.
    6. Modify run.sh:
      • Set lr to 0.0005.
      • Set clip_range to 0.1.
      • Closed-loop baseline: Set maps to only contain maps without open_loop in their name.
      • Open-loop baseline: Set maps to only contain maps with open_loop in their name.
    7. Execute the experiment: ./run.sh clipping_rnn_central_V <tag>

    Note on Scenarios: For 10_vs_11 or 20_vs_23 scenarios, set the offset on line 21 of run.sh to control the enemy-to-ally ratio.

    git clone https://github.com/benellis3/mappo.git
    # ... inside mappo ...
    ./docker/build.sh
    ./install_sc2.sh
    ./run.sh clipping_rnn_central_V my_experiment_tag
  6. Run Open-Loop SMAC Baselines

    main

    Open-loop baselines require specific git branches.

    MAPPO Open-Loop:

    1. Clone mappo and ensure WANDB_API_KEY_FILE is set.
    2. Checkout the stochastic-experiment branch: git checkout stochastic-experiment.
    3. Install Starcraft: ./install_sc2.sh.
    4. Build Docker: ./build.sh in the docker directory.
    5. Configure src/config/default.yaml (project and entity).
    6. Run: ./run_exp.sh clipping_rnn_central_V <tag>

    QMIX Open-Loop:

    1. Clone pymarl2 and ensure WANDB_API_KEY_FILE is set.
    2. Checkout the stochastic_test branch: git checkout stochastic_test.
    3. Install Starcraft: ./install_sc2.sh in the pymarl2 directory.
    4. Build Docker: ./build.sh in the docker directory.
    5. Configure src/config/default.yaml (project and entity).
    6. Run: ./run.sh qmix <tag>
    # MAPPO Open-Loop
    git checkout stochastic-experiment
    ./run_exp.sh clipping_rnn_central_V <tag>
    
    # QMIX Open-Loop
    git checkout stochastic_test
    ./run.sh qmix <tag>
  7. Configure WandB for experiment logging

    main

    SMACv2 experiments use wandb.ai for logging. To enable this, you must provide your WandB API key via a file path.

    1. Obtain your API key from your WandB user settings (User Settings > Danger Zone > API Keys).
    2. Save the key into a file.
    3. Set the WANDB_API_KEY_FILE environment variable to the path of that file.
    export WANDB_API_KEY_FILE=$HOME/.wandb_api_key
  8. Install SMACv2 in editable mode for development

    main

    If you intend to extend or modify SMACv2, install it in editable mode with development dependencies and set up pre-commit:

    git clone https://github.com/oxwhirl/smacv2.git
    cd smacv2
    pip install -e ".[dev]"
    pre-commit install
  9. Install SMACv2 via pip

    main

    To install SMACv2 as a standard package, use the following command:

    pip install git+https://github.com/oxwhirl/smacv2.git

    Prerequisites:

    • You must have StarCraft II installed.
    • You must have the 32x32_flat.SC2Map map file in your SMAC_Maps folder. You can download the required maps here.
  10. Run QMIX SMACv2 Baselines

    main

    To run the QMIX baseline, follow these steps:

    1. Ensure WANDB_API_KEY_FILE is set.
    2. Clone the pymarl2 repository: git clone https://github.com/benellis3/pymarl2.git.
    3. Build the Docker container from the pymarl2 directory: docker build -t pymarl2:ben_smac -f docker/Dockerfile --build-arg UID=$UID .
    4. Install Starcraft in the pymarl2 directory: ./install_sc2.sh.
    5. Configure src/config/default.yaml: set project to your desired name and entity to your WandB username.
    6. Modify run_exp.sh:
      • Set td_lambdas (line 21) to 0.4.
      • Set eps_anneal to 100000.
    7. Execute the experiment: ./run_exp.sh qmix <tag>

    Note on Scenarios: For 10_vs_11 or 20_vs_23 scenarios, you must manually set n_units and n_enemies in the ./run_docker.sh command (line 46). For example, for 20_vs_23, use n_units=20 and n_enemies=23.

    git clone https://github.com/benellis3/pymarl2.git
    # ... inside pymarl2 ...
    docker build -t pymarl2:ben_smac -f docker/Dockerfile --build-arg UID=$UID .
    ./install_sc2.sh
    ./run_exp.sh qmix my_experiment_tag