Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(nyz): move atari_py to ale-py; split base and env docker build #77

Merged
merged 5 commits into from
Sep 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 66 additions & 6 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: deploy # deploy docker
on: [push]

jobs:
docker:
docker_base:
runs-on: ubuntu-latest
if: "contains(github.event.head_commit.message, 'enable docker')"
strategy:
Expand All @@ -29,14 +29,73 @@ jobs:
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
fi
if [ "${{ github.event_name }}" = "schedule" ]; then
VERSION=nightly
fi
TAGS="${DOCKER_IMAGE}:${VERSION}"
NIGHTLY_TAGS="${DOCKER_IMAGE}:nightly"
if [[ $VERSION =~ ^v[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
TAGS="$TAGS,${DOCKER_IMAGE}:latest"
fi
echo ::set-output name=tags::${TAGS}
echo ::set-output name=nightlytags::${NIGHTLY_TAGS}
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
with:
platforms: all

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1

- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERIO_USERNAME }}
password: ${{ secrets.DOCKERIO_PASSWORD }}

- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
builder: ${{ steps.buildx.outputs.name }}
context: ./
file: ./Dockerfile.base
push: ${{ github.event_name != 'pull_request' }}
tags: |
${{ steps.prep.outputs.tags }}
${{ steps.prep.outputs.nightlytags }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache

- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}

docker_env:
runs-on: ubuntu-latest
needs: docker_base
if: "contains(github.event.head_commit.message, 'enable docker')"
strategy:
matrix:
platform: [linux/amd64]
# python-version: [3.6, 3.7, 3.8]
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Prepare
id: prep
env:
DOCKERIO_ORG: opendilab
TARGET: ding
run: |
DOCKER_IMAGE=$DOCKERIO_ORG/$TARGET
VERSION=nightly-atari
ATARI_TAGS="${DOCKER_IMAGE}:${VERSION}"
echo ::set-output name=ataritags::${ATARI_TAGS}
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
with:
Expand Down Expand Up @@ -65,11 +124,12 @@ jobs:
with:
builder: ${{ steps.buildx.outputs.name }}
context: ./
file: ./Dockerfile
file: ./Dockerfile.env
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.prep.outputs.tags }}
tags: ${{ steps.prep.outputs.ataritags }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
target: atari

- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
12 changes: 1 addition & 11 deletions Dockerfile → Dockerfile.base
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,4 @@ ADD dizoo dizoo
ADD ding ding

RUN python3 -m pip install --upgrade pip \
&& python3 -m pip install --no-cache-dir .[common_env]

# install ROMs with rar
RUN curl -sL https://www.rarlab.com/rar/rarlinux-x64-6.0.1.tar.gz | tar -zxvf - \
&& cd rar && make \
&& cd .. && rm -rf rar \
&& mkdir roms && cd roms \
&& curl -O http://www.atarimania.com/roms/Roms.rar && unrar e Roms.rar \
&& python -m atari_py.import_roms . \
&& cd .. && rm -rf roms \
&& rm /usr/local/bin/rar /usr/local/bin/unrar /etc/rarfiles.lst /usr/local/lib/default.sfx
&& python3 -m pip install --no-cache-dir .[fast]
8 changes: 8 additions & 0 deletions Dockerfile.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM opendilab/ding:nightly as atari

WORKDIR /ding

RUN python3 -m pip install --upgrade pip \
&& python3 -m pip install --no-cache-dir .[common_env] \
&& pip install autorom \
&& AutoROM --accept-license
1 change: 0 additions & 1 deletion dizoo/atari/envs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
from .atari_env import AtariEnv, AtariEnvMR
from .atari_multi_discrete_env import AtariMultiDiscreteEnv
6 changes: 4 additions & 2 deletions dizoo/atari/envs/atari_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ def seed(self, seed: int, dynamic_seed: bool = True) -> None:

def step(self, action: np.ndarray) -> BaseEnvTimestep:
assert isinstance(action, np.ndarray), type(action)
action = action.item()
obs, rew, done, info = self._env.step(action)
self._final_eval_reward += rew
obs = to_ndarray(obs)
Expand Down Expand Up @@ -240,7 +241,7 @@ class AtariEnvMR(AtariEnv):

def reset(self) -> np.ndarray:
if not self._init_flag:
self._make_env(only_info=False)
self._env = self._make_env(only_info=False)
self._init_flag = True
if hasattr(self, '_seed'):
np_seed = 100 * np.random.randint(1, 1000)
Expand All @@ -251,7 +252,7 @@ def reset(self) -> np.ndarray:
return obs

def _make_env(self, only_info=False):
self._env = wrap_deepmind_mr(
return wrap_deepmind_mr(
self._cfg.env_id,
frame_stack=self._cfg.frame_stack,
episode_life=self._cfg.is_train,
Expand All @@ -269,6 +270,7 @@ def info(self) -> BaseEnvInfo:
info.obs_space.shape = obs_shape
info.act_space.shape = act_shape
info.rew_space.shape = rew_shape
return info
else:
raise NotImplementedError('{} not found in ATARIENV_INFO_DICT [{}]'\
.format(self._cfg.env_id, ATARIENV_INFO_DICT.keys()))
102 changes: 0 additions & 102 deletions dizoo/atari/envs/atari_multi_discrete_env.py

This file was deleted.

2 changes: 1 addition & 1 deletion dizoo/atari/envs/test_atari_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from dizoo.atari.envs import AtariEnv, AtariEnvMR


@pytest.mark.unittest
@pytest.mark.envtest
class TestAtariEnv:

def test_pong(self):
Expand Down
30 changes: 0 additions & 30 deletions dizoo/atari/envs/test_atari_mutli_discrete_env.py

This file was deleted.

6 changes: 4 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
'numpy>=1.10',
'requests>=2.25.1',
'six',
'gym>=0.15.3', # pypy incompatible
'gym>=0.20.0', # pypy incompatible
'torch>=1.3.1,<=1.8.0',
'pyyaml',
'easydict==1.9',
Expand Down Expand Up @@ -88,11 +88,13 @@
'fast': [
'numpy-stl',
'numba>=0.53.0',
],
'dist': [
'redis==3.5.3',
'redis-py-cluster==2.1.0',
],
'common_env': [
'atari_py',
'ale-py', # atari
'box2d-py',
'cmake>=3.18.4',
'opencv-python', # pypy incompatible
Expand Down