Skip to content

Commit

Permalink
Add docker
Browse files Browse the repository at this point in the history
  • Loading branch information
benellis3 committed Oct 21, 2021
1 parent e9be1dc commit 3db03de
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 13 deletions.
13 changes: 13 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM pytorch/pytorch:1.1.0-cuda10.0-cudnn7.5-runtime

RUN apt-get -y update
RUN apt-get -y install git
ADD install_dependencies.sh /source/
RUN bash -c /source/install_dependencies.sh

RUN pip install pymongo

ENV smac_ver 1
ENV SC2PATH /source/3rdparty/StarCraftII

WORKDIR /source/
2 changes: 1 addition & 1 deletion install_dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
# conda create -n pymarl python=3.7 -y
# conda activate pymarl

conda install pytorch torchvision cudatoolkit=11.0 -c pytorch -y
conda install pytorch torchvision cudatoolkit=9.0 -c pytorch -y
pip install sacred numpy scipy gym==0.10.8 matplotlib seaborn pyyaml pygame pytest probscale imageio snakeviz tensorboard-logger
pip install git+https://github.com/oxwhirl/smac.git
15 changes: 8 additions & 7 deletions install_sc2.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
#!/bin/bash
# Install SC2 and add the custom maps

smac_mpas=$(pwd)/smac_maps
pymarl_dir=$HOME/src/pymarl2
cd $pymarl_dir/3rdparty/
smac_maps=$pymarl_dir/smac_maps

cd "$HOME"
export SC2PATH="$HOME/StarCraftII"
export SC2PATH="$HOME/src/pymarl2/3rdparty/StarCraftII"
echo 'SC2PATH is set to '$SC2PATH

if [ ! -d $SC2PATH ]; then
echo 'StarCraftII is not installed. Installing now ...';
wget http://blzdistsc2-a.akamaihd.net/Linux/SC2.4.10.zip
unzip -P iagreetotheeula SC2.4.10.zip
rm -rf SC2.4.10.zip
rm -f SC2.4.10.zip
else
echo 'StarCraftII is already installed.'
fi
Expand All @@ -28,9 +29,9 @@ cd ..
wget https://github.com/oxwhirl/smac/releases/download/v0.1-beta1/SMAC_Maps.zip
unzip SMAC_Maps.zip

cp -r "$smac_mpas/*.SC2Map" ./SMAC_Maps
cp -r "$smac_maps/*.SC2Map" ./SMAC_Maps
mv SMAC_Maps $MAP_DIR
rm -rf SMAC_Maps.zip
rm -f SMAC_Maps.zip


echo 'StarCraft II and SMAC are installed.'
echo 'StarCraft II and SMAC are installed.'
10 changes: 5 additions & 5 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ function onCtrlC () {
}

config=$1 # qmix
maps=$2 # MMM2,3s5z_vs_3s6z
threads=$3 # 2
args=$4 # ""
maps=${2:-2c_vs_64zg,8m_vs_9m,3s_vs_5z,5m_vs_6m,3s5z_vs_3s6z,corridor,6h_vs_8z,MMM2,27m_vs_30m} # MMM2,3s5z_vs_3s6z
threads=${3:-2} # 2
args=${4:-} # ""
gpus=$5 # 0,1
times=$6 # 5

Expand All @@ -37,7 +37,7 @@ if [ ! $gpus ]; then
fi

if [ ! $times ]; then
times=6
times=3
fi

echo "CONFIG:" $config
Expand All @@ -53,7 +53,7 @@ count=0
for map in "${maps[@]}"; do
for((i=0;i<times;i++)); do
gpu=${gpus[$(($count % ${#gpus[@]}))]}
CUDA_VISIBLE_DEVICES="$gpu" python3 src/main.py --config="$config" --env-config=sc2 with env_args.map_name="$map" "${args[@]}" &
./run_docker.sh $gpu python3 src/main.py --config="$config" --env-config=sc2 with env_args.map_name="$map" "${args[@]}" &

count=$(($count + 1))
if [ $(($count % $threads)) -eq 0 ]; then
Expand Down
20 changes: 20 additions & 0 deletions run_docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
HASH=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 4 | head -n 1)
GPU=$1
name=${USER}_pymarl_GPU_${GPU}_${HASH}

echo "Launching container named '${name}' on GPU '${GPU}'"
# Launches a docker container using our image, and runs the provided command

if hash nvidia-docker 2>/dev/null; then
cmd=nvidia-docker
else
cmd=docker
fi

NV_GPU="$GPU" ${cmd} run -it \
--name $name \
--user $(id -u) \
-v $(pwd):/source \
-t pymarl:ben_smac \
${@:2}

0 comments on commit 3db03de

Please sign in to comment.