【多智能体强化学习】Pymarl环境配置

Last updated on March 24, 2024 pm

SMAC是基于暴雪星际争霸II RTS游戏的协作多智能体强化学习领域的研究环境。SMAC利用星际争霸2机器学习API和DeepMind的PySC2为自主代理提供了一个方便的接口。

本文主要介绍在多智能体强化学习中的验证平台SAMC和Pymarl的配置和安装过程

环境地址:https://github.com/oxwhirl/pymarl

依赖环境:https://github.com/oxwhirl/smac

主要针对Ubuntu下的Pymarl环境的配置(MAC和Windows类似)

SMAC

安装StarCraftII

Windows/Mac

直接在官网下载安装最新版,需要加速器或者更换亚服:https://sc2.blizzard.cn/landing

安装地图:https://link.zhihu.com/?target=https%3A//github.com/oxwhirl/smac/releases/download/v0.1-beta1/SMAC_Maps.zip

将地图放在Maps文件夹下

Ubuntu

在Ubuntu系统中,安装需要版本的SCII即可https://github.com/Blizzard/s2client-proto#downloads

下载压缩包之后安装并解压放到用户名文件夹下:~/StarCraftII/

如果没有把SCII安装到用户名之下,这个地方的路径可以根据放置的位置来进行更改:

1
vim ~/.bashrc

在最后一行增加环境变量,这里可以更改星际争霸的位置索引到任何想要放置的位置

1
export SC2PATH=~/StarCraftII/

添加完之后更新环境

1
source ~/.bashrc

添加SAMC的地图:Linux系统在下载SCII的时候就自带了地图

安装SMAC

创建虚拟环境并安装pytorch

1
2
3
4
conda create -n pymarl python=3.8 -y
conda activate pymarl
# CUDA 10.2 例子具体的的CUDA版本根据自己的服务器来定
conda install pytorch==1.10.0 torchvision==0.11.0 torchaudio==0.10.0 cudatoolkit=10.2 -c pytorch

直接利用虚拟环境中的pip来安装

1
pip install git+https://github.com/oxwhirl/smac.git

或者可以利用git进行安装,先git clone下载下来然后进入文件夹中进行安装

1
2
git clone https://github.com/oxwhirl/smac.git
pip install -e smac/

如果pip install安装失败可以考虑升级pip:

1
pip install --upgrade pip

如果安装的内容失败了可以手动安装,比如pymarl运行所依赖的包有以下:

1
2
pip install sacred numpy scipy matplotlib seaborn pyyaml pygame pytest probscale imageio snakeviz tensorboard-logger

或者根据https://github.com/oxwhirl/pymarl/tree/master/docker中的bash脚本中Dockerfile依赖内容进行安装

Pymarl与SCII

采用上述安装步骤

对于上述的操作完成操作之后,下载pymarl的环境包并进入

1
2
git clone git@github.com:oxwhirl/pymarl.git
cd pymarl

将上述安装的SCII文件夹复制到pymarl的src的3dparty之下

如果利用Docker安装

或者根据pymarl中的内容对上述环境进行自动配置(需要Docker)

1
2
cd docker
bash build.sh

同时安装SCII和SMAC

1
bash install_sc2.sh

测试环境

测试地图信息

1
python -m smac.bin.map_list 

Maps show

测试环境信息

1
python -m smac.examples.random_agents

test agents

测试Pymarl环境

1
python src/main.py --config=qmix --env-config=sc2 with env_args.map_name=2s3z
test pymarl

依赖包的版本问题

当运行pymarl的时候容易因为依赖包产生问题

image-20240104210308852

原因是 sacred版本不对劲,只需要将版本降低到0.7.5这个问题就能解决

额外设置

在利用pymarl进行实验的过程中可能会出现

some bug

需要进行设置

1
vim torch/_tensor.py

将757行的内容进行修改

1
2
-: self.numpy()
+: self.cpu().numpy()

谷歌足球环境

Google Research Football:https://github.com/google-research/football

安装Linux依赖环境

1
2
3
4
5
sudo apt-get install git cmake build-essential libgl1-mesa-dev libsdl2-dev \
libsdl2-image-dev libsdl2-ttf-dev libsdl2-gfx-dev libboost-all-dev \
libdirectfb-dev libst-dev mesa-utils xvfb x11vnc python3-pip

python3 -m pip install --upgrade pip setuptools psutil wheel

这一步非常重要,必须合理安装相应的包。

安装GFootball

1
python3 -m pip install gfootball

或者用github的仓库来进行安装

1
2
git clone https://github.com/google-research/football.git
cd football

可以选择使用虚拟环境:

1
2
python3 -m venv football-env
source football-env/bin/activate

安装依赖包

1
python3 -m pip install .

运行结果展示:

谷歌足球结果展示

遇到的问题

编译错误,缺少boost的包:

编译错误

选择安装如下包:

1
conda install anaconda::py-boost

第二个错误:

错误二

解决方法:

1
export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libffi.so.7

需要更新linux依赖包

1
sudo apt-get update

如果出现无法编译的情况如:subprocess-exited-with-error

1
2
pip install setuptools==65.5.0
pip install --user wheel==0.38.0

【多智能体强化学习】Pymarl环境配置
https://lihaibineric.github.io/2023/10/22/marl_pymarl_env/
Author
Haibin Li
Posted on
October 22, 2023
Updated on
March 24, 2024
Licensed under