Skip to content

Commit

Permalink
Migrate to CircleCI (#121)
Browse files Browse the repository at this point in the history
* Prototype CircleCI and Docker config

* Update Docker and setup

* Fix typo in Dockerfile

* Include mujoco_py support

* Install right version of MuJoCo

* CircleCI: fix cache saving

* Fix linting

* Replace local code checks script

* Fix typechecking

* envs: close environment after testing

* Fix Dockerfile and setup.py

* Bugfix: include AIRL example envs assets in install

* CircleCI: codespell - skip notebooks

* test_scripts: reduce Ray resource consumption

* setup.py: fix pytype ignore comment

* test_scripts: limit # of trials running in parallel

* Remove Travis config

* Update status badge in README

* Address code review

* README.md: Bump python version
  • Loading branch information
AdamGleave authored Nov 19, 2019
1 parent 43e23fa commit b3f66d2
Show file tree
Hide file tree
Showing 16 changed files with 290 additions and 104 deletions.
119 changes: 119 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
version: 2.1

orbs:
codecov: codecov/[email protected]

executors:
my-executor:
docker:
- image: humancompatibleai/imitation:base
working_directory: /imitation
environment:
# If you change these, also change ci/code_checks.sh
SRC_FILES: src/ tests/ experiments/ setup.py

commands:
dependencies:
# You must still manually update the Docker image if any
# binary (non-Python) dependencies change.
description: "Check out and update Python dependencies."
steps:
- checkout
# Download and cache dependencies
- restore_cache:
keys:
- v1-dependencies-{{ checksum "setup.py" }}

- run:
name: install dependencies
# MUJOCO_KEY is defined in a CircleCI context
# Do some sanity checks to make sure key works
command: |
curl -o /root/.mujoco/mjkey.txt ${MUJOCO_KEY}
md5sum /root/.mujoco/mjkey.txt
# Only create venv if it's not been restored from cache
[[ -d venv ]] || USE_MPI=True ./ci/build_venv.sh
python -c "import mujoco_py"
- save_cache:
paths:
- ./venv
key: v1-dependencies-{{ checksum "setup.py" }}

- run:
name: install imitation
# Build a wheel then install to avoid copying whole directory (pip issue #2195)
command: |
python setup.py sdist bdist_wheel
pip install --upgrade dist/imitation-*.whl
jobs:
lintandtype:
executor: my-executor

steps:
- dependencies
- run:
name: flake8
command: flake8 ${SRC_FILES}

- run:
name: codespell
command: codespell -I .codespell.skip --skip='*.pyc,tests/data/*,*.ipynb,*.csv' ${SRC_FILES}

- run:
name: sphinx
command: pushd docs/ && make clean && make html && popd

- run:
name: pytype
command: pytype ${SRC_FILES}

unit-test:
executor: my-executor
parallelism: 3
steps:
- dependencies

- run:
name: Memory Monitor
command: |
mkdir /tmp/resource-usage
export FILE=/tmp/resource-usage/memory.txt
while true; do
ps -u root eo pid,%cpu,%mem,args,uname --sort=-%mem >> $FILE
echo "----------" >> $FILE
sleep 1
done
background: true

- run:
name: run tests
command: |
export DISPLAY=:0
pytest --cov=venv/lib/python3.7/site-packages/imitation --cov=tests \
--junitxml=/tmp/test-reports/junit.xml \
--shard-id=${CIRCLE_NODE_INDEX} --num-shards=${CIRCLE_NODE_TOTAL} \
-vv tests/
mv .coverage .coverage.imitation
coverage combine # rewrite paths from virtualenv to src/
- codecov/upload

- store_artifacts:
path: /tmp/test-reports
destination: test-reports
- store_test_results:
path: /tmp/test-reports
unit-test:
- store_artifacts:
path: /tmp/resource-usage
destination: resource-usage

workflows:
version: 2
test:
jobs:
- lintandtype:
context: MuJoCo
- unit-test:
context: MuJoCo
1 change: 1 addition & 0 deletions .dockerignore
14 changes: 12 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Project-specific
.*/
.#*
*.html
output/
Expand Down Expand Up @@ -55,6 +54,7 @@ htmlcov/
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

Expand Down Expand Up @@ -98,8 +98,12 @@ ipython_config.py
# install all needed dependencies.
#Pipfile.lock

# celery beat schedule file
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py
Expand All @@ -120,6 +124,9 @@ venv.bak/
# Rope project settings
.ropeproject

# PyCharm project settings
.idea

# mkdocs documentation
/site

Expand All @@ -131,6 +138,9 @@ dmypy.json
# Pyre type checker
.pyre/

# Pytype type checker
.pytype/

# Mac OSX
.DS_STORE

Expand Down
47 changes: 0 additions & 47 deletions .travis.yml

This file was deleted.

78 changes: 78 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Based on OpenAI's mujoco-py Dockerfile

# base stage contains just binary dependencies.
# This is used in the CI build.
FROM nvidia/cuda:10.0-runtime-ubuntu18.04 AS base
ARG DEBIAN_FRONTEND=noninteractive

RUN echo ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true | debconf-set-selections \
&& apt-get update -q \
&& apt-get install -y --no-install-recommends \
build-essential \
curl \
ffmpeg \
git \
libgl1-mesa-dev \
libgl1-mesa-glx \
libglew-dev \
libosmesa6-dev \
net-tools \
parallel \
python3.7 \
python3.7-dev \
python3-pip \
rsync \
software-properties-common \
unzip \
vim \
virtualenv \
xpra \
xserver-xorg-dev \
ttf-mscorefonts-installer \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

RUN curl -o /usr/local/bin/patchelf https://s3-us-west-2.amazonaws.com/openai-sci-artifacts/manual-builds/patchelf_0.9_amd64.elf \
&& chmod +x /usr/local/bin/patchelf

ENV LANG C.UTF-8

RUN mkdir -p /root/.mujoco \
&& curl -o mjpro150.zip https://www.roboti.us/download/mjpro150_linux.zip \
&& unzip mjpro150.zip -d /root/.mujoco \
&& rm mjpro150.zip

# Set the PATH to the venv before we create the venv, so it's visible in base.
# This is since we may create the venv outside of Docker, e.g. in CI
# or by binding it in for local development.
ENV PATH="/imitation/venv/bin:$PATH"
ENV LD_LIBRARY_PATH /usr/local/nvidia/lib64:/root/.mujoco/mjpro150/bin:${LD_LIBRARY_PATH}

# python-req stage contains Python venv, but not code.
# It is useful for development purposes: you can mount
# code from outside the Docker container.
FROM base as python-req

WORKDIR /imitation
# Copy over just setup.py and __init__.py (including version)
# to avoid rebuilding venv when requirements have not changed.
COPY ./setup.py ./setup.py
COPY ./src/imitation/__init__.py ./src/imitation/__init__.py
COPY ./ci/build_venv.sh ./ci/build_venv.sh
# mjkey.txt needs to exist for build, but doesn't need to be a real key
RUN touch /root/.mujoco/mjkey.txt \
&& ci/build_venv.sh \
&& rm -rf $HOME/.cache/pip

# full stage contains everything.
# Can be used for deployment and local testing.
FROM python-req as full

# Delay copying (and installing) the code until the very end
COPY . /imitation
# Build a wheel then install to avoid copying whole directory (pip issue #2195)
RUN python3 setup.py sdist bdist_wheel
RUN pip install --upgrade dist/imitation-*.whl

# Default entrypoints
CMD ["pytest", "-n", "auto", "-vv", "tests/"]
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Build Status](https://travis-ci.com/HumanCompatibleAI/imitation.svg?branch=master)](https://travis-ci.com/HumanCompatibleAI/imitation)
[![CircleCI](https://circleci.com/gh/HumanCompatibleAI/imitation.svg?style=svg)](https://circleci.com/gh/HumanCompatibleAI/imitation)
[![codecov](https://codecov.io/gh/HumanCompatibleAI/imitation/branch/master/graph/badge.svg)](https://codecov.io/gh/HumanCompatibleAI/imitation)

# Imitation Learning Baseline Implementations
Expand All @@ -10,7 +10,7 @@ Currently we have implementations of [AIRL](https://arxiv.org/abs/1710.11248) an
To install:
```
sudo apt install libopenmpi-dev
conda create -n imitation python=3.7 # python 3.6 and virtualenv are also okay.
conda create -n imitation python=3.8 # python 3.7 and virtualenv are also okay.
conda activate imitation
pip install -e '.[dev]' # install `imitation` in developer mode
```
Expand Down
8 changes: 8 additions & 0 deletions ci/build_venv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

set -e # exit immediately on any error

venv=venv
virtualenv -p python3.7 ${venv}
source ${venv}/bin/activate
pip install .[cpu,dev,test] gym[mujoco]
26 changes: 26 additions & 0 deletions ci/code_checks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash

# If you change these, also change .circle/config.yml.
SRC_FILES=(src/ tests/ experiments/ setup.py)

set -x # echo commands
set -e # quit immediately on error

echo "Source format checking"
flake8 ${SRC_FILES}
codespell -I .codespell.skip --skip='*.pyc,tests/data/*,*.ipynb,*.csv' ${SRC_FILES}

if [ -x "`which circleci`" ]; then
circleci config validate
fi

if [ "$skipexpensive" != "true" ]; then
echo "Building docs (validates docstrings)"
pushd docs/
make clean
make html
popd

echo "Type checking"
pytype ${SRC_FILES}
fi
34 changes: 0 additions & 34 deletions ci/lint.sh

This file was deleted.

6 changes: 0 additions & 6 deletions ci/type_check.sh

This file was deleted.

Loading

0 comments on commit b3f66d2

Please sign in to comment.