AYUSH-ISHAN / Type-Based_Heirarchial_MARL_SC2

StarCraft 2 via Type Based Heirarchial Multi Agent Reinforcement Leanring

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Multi-agent deep reinforcement learning with type-based hierarchical group communication

Preface

Here, I have implemented THGC(Type Based Heirarchial for Group Communication netwroks) in StarCraft II environment. I have used this environment along with PyMARL. More detail about this is given below.



- Please pay attention to the version of SC2 you are using for your experiments. 
- Performance is *not* always comparable between versions. 
- The results in SMAC (https://arxiv.org/abs/1902.04043) use SC2.4.6.2.69232 not SC2.4.10.

Python MARL framework

PyMARL is WhiRL's framework for deep multi-agent reinforcement learning and includes implementations of the following algorithms:

PyMARL is written in PyTorch and uses SMAC {this smac env is customised by me for this model, go to the link to the customized smac} as its environment.

THGC Algorithm

Model Architectures :

In the above shown figure we have the THGC network architecture.

Agent Grouping :

Here, we have grouped the allies by two methods as shown in figures. One is groupinf on basis of location and another is grouping on basis of health.

  1. On basis of health (right) : In this we basically grouped the allies who were having normalised health differences in between 0 to 0.3. The noramlised health is foud the (agent_health) / (agent_max_health). This type of group helps us in combining the strngth of our army together get more commulative reward.
  2. On basis of location (left) : In this grouping takes place if the agents are in a distance of 0.5 units. This not only improves the communication but also helps in improving quick group actions.


Types of Agents

Here, we have a default agent (rnn agent) and other it thgc agent, which is specifically designed for this project.

Communication or Knoweldege share via Graph Attention Netowrks:

For, commication we have used Graph Attention Networks (GAT). The GAT netwroks are for communication between the agents of a group (intra level) and for inter group communication.


Adjacency Matrix:

The adjacency matrix is basically a boolen matrix which tells whether the ally is near a range of communication or not (specifically 0.5). The threshold of including the nodes in the Graph attention vertex is 0.5. The main reason for this was, if agent were far enough, then we don't need communication with them as it will lead to noise or unnecessary data collection, which is not so beneficial and will affect the performance of agents in a group. Specifically for grouing, we have used some heuristics to get the commincation on basis of latest data from the env.

Results:

The results show the performance of THGC algorithm as compared to other algorithms in different modes of battle.

Conclusion:

THGC seens to better than rest of them.

Installation instructions

Build the Dockerfile using

cd docker
bash build.sh

Set up StarCraft II and SMAC:

bash install_sc2.sh

This will download SC2 into the 3rdparty folder and copy the maps necessary to run over.

The requirements.txt file can be used to install the necessary packages into a virtual environment (not recomended).

Run an experiment

python3 src/main.py --config=thgc --env-config=sc2 with env_args.map_name=2s3z

The config files act as defaults for an algorithm or environment.

They are all located in src/config. --config refers to the config files in src/config/algs --env-config refers to the config files in src/config/envs

To run experiments using the Docker container:

bash run.sh $GPU python3 src/main.py --config=qmix --env-config=sc2 with env_args.map_name=2s3z

All results will be stored in the Results folder.

The previous config files used for the SMAC Beta have the suffix _beta.

Saving and loading learnt models

Saving models

You can save the learnt models to disk by setting save_model = True, which is set to False by default. The frequency of saving models can be adjusted using save_model_interval configuration. Models will be saved in the result directory, under the folder called models. The directory corresponding each run will contain models saved throughout the experiment, each within a folder corresponding to the number of timesteps passed since starting the learning process.

Loading models

Learnt models can be loaded using the checkpoint_path parameter, after which the learning will proceed from the corresponding timestep.

Watching StarCraft II replays

save_replay option allows saving replays of models which are loaded using checkpoint_path. Once the model is successfully loaded, test_nepisode number of episodes are run on the test mode and a .SC2Replay file is saved in the Replay directory of StarCraft II. Please make sure to use the episode runner if you wish to save a replay, i.e., runner=episode. The name of the saved replay file starts with the given env_args.save_replay_prefix (map_name if empty), followed by the current timestamp.

The saved replays can be watched by double-clicking on them or using the following command:

python -m pysc2.bin.play --norender --rgb_minimap_size 0 --replay NAME.SC2Replay

Note: Replays cannot be watched using the Linux version of StarCraft II. Please use either the Mac or Windows version of the StarCraft II client.

About

StarCraft 2 via Type Based Heirarchial Multi Agent Reinforcement Leanring

License:Apache License 2.0


Languages

Language:Python 96.9%Language:Shell 1.6%Language:Dockerfile 1.5%