diff --git a/.gitignore b/.gitignore index d95db30..fad75a6 100644 --- a/.gitignore +++ b/.gitignore @@ -34,6 +34,9 @@ htmlcov/ .coverage venv/ ENV/ +.env/ +openai_lab/ +src/ node_modules/ diff --git a/Gruntfile.js b/Gruntfile.js index d12f7bc..4c5b879 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -110,9 +110,11 @@ module.exports = function(grunt) { eStr = resumeExperimentStr(eStr) } + const envCmd = 'if (conda env list | grep --quiet "openai_lab"); then echo "activating conda"; source activate openai_lab; elif [ -d ./.env ]; then echo "activating virtualenv"; source .env/bin/activate; else echo "using system python"; fi;' + // override with custom command if has 'python' - var pyCmd = _.includes(eStr, 'python') ? eStr : `python3 main.py${bestCmd()}${debugCmd()}${quietCmd()} -t 5 -e ${eStr}` - const cmd = `${remoteCmd()} ${pyCmd} | tee ./data/terminal.log; ${notiCmd(eStr)}` + const pyCmd = _.includes(eStr, 'python') ? eStr : `python3 main.py${bestCmd()}${debugCmd()}${quietCmd()} -t 5 -e ${eStr}` + const cmd = `${remoteCmd()} ${envCmd} ${pyCmd} | tee ./data/terminal.log; ${notiCmd(eStr)}` grunt.log.ok(`Composed command: ${cmd}`) return cmd } diff --git a/bin/setup b/bin/setup index afca0d0..bd28a81 100755 --- a/bin/setup +++ b/bin/setup @@ -1,114 +1,61 @@ #!/bin/bash # This script runs the same sequence as the CircleCI build +# Run this as: +# bin/setup + # Fail on the first error; killable by SIGINT set -e trap "exit" INT + +read -p " +================================================ + +Welcome to the OpenAI Lab setup script; +This will invoke sudo; alternatively, +inspect bin/setup_ubuntu or bin/setup_macOS and run the lines manually. + +Press enter to continue, Ctrl+c to quit: + +================================================ +" + # copy keys file if not already exist BIN_DIR=`pwd`/bin $BIN_DIR/copy-config -# install system dependencies -if [ $(uname) == "Darwin" ]; then - if which brew >/dev/null; then - echo "Brew is already installed" - else - ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" - fi -else - sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test && sudo apt-get update - sudo apt-get install -y gcc-4.9 g++-4.9 libhdf5-dev libopenblas-dev git +# determine if is Mac OSX, or Linux; then run accordingly +if [ $(uname) == "Darwin" ]; +# Mac runs below +then ( + $BIN_DIR/setup_macOS; + ); +else ( + $BIN_DIR/setup_ubuntu; + ); fi -# install python -if which python3 >/dev/null; then - echo "Python3 is already installed" -else - if [ $(uname) == "Darwin" ]; then - brew install python3 - else - sudo apt-get -y install python3-dev python3-pip python3-setuptools - fi -fi -# install nodejs (for npm and file watcher) -if which node >/dev/null; then - echo "Nodejs is already installed" -else - if [ $(uname) == "Darwin" ]; then - brew install node - else - curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash - - sudo apt-get install -y nodejs - fi -fi +echo " +================================================ -# install npm modules -if [ -d ./node_modules ]; then - echo "Npm modules already installed" -else - npm install - sudo npm i -g grunt-cli -fi +Setup done. +Running basic installation checks. -# install noti -if [ $(uname) == "Darwin" ]; then - curl -L https://github.com/variadico/noti/releases/download/v2.5.0/noti2.5.0.darwin-amd64.tar.gz | tar -xz - sudo mv noti /usr/local/bin/ -else - curl -L https://github.com/variadico/noti/releases/download/v2.5.0/noti2.5.0.linux-amd64.tar.gz | tar -xz - sudo mv noti /usr/bin/ -fi +================================================ +" -# install common dependencies from from -sudo python3 -m pip install -U pip -sudo python3 -m pip install six -sudo python3 -m pip install h5py -sudo python3 -m pip install numpy -sudo python3 -m pip install scipy -sudo python3 -m pip install matplotlib -sudo python3 -m pip install seaborn -sudo python3 -m pip install pandas -sudo python3 -m pip install atari_py -sudo python3 -m pip install Pillow -sudo python3 -m pip install PyOpenGL -sudo python3 -m pip install glances -sudo python3 -m pip install mem_top -sudo python3 -m pip install pytest-cov -sudo python3 -m pip install pytest-xdist -sudo python3 -m pip install codacy-coverage - -# install tensorflow -if [ $(uname) == "Darwin" ]; then - sudo python3 -m pip install tensorflow -else - sudo python3 -m pip install tensorflow-gpu -fi +# post-installation checks python3 -c "import tensorflow; print('tensorflow version:'); print(tensorflow.__version__)" - -# install theano -if which clang >/dev/null; then - echo "clang is already installed" -else - if [ $(uname) == "Darwin" ]; then - brew install --with-clang llvm - fi -fi -# sudo pip3 install --upgrade --no-deps git+git://github.com/Theano/Theano.git -sudo python3 -m pip install theano==0.8.2 -python3 -c "import theano; print('theano version:'); print(theano.__version__)" - -# install keras -sudo python3 -m pip install keras - -# install full openai gym -if [ $(uname) == "Darwin" ]; then - brew install cmake boost boost-python sdl2 swig wget -else - sudo apt-get install -y cmake zlib1g-dev libjpeg-dev xvfb libav-tools xorg-dev python-opengl libboost-all-dev libsdl2-dev swig -fi -git clone https://github.com/openai/gym.git && cd gym && sudo python3 -m pip install -e .[all] && cd .. -git clone https://github.com/pybox2d/pybox2d && cd pybox2d/ && sudo python3 setup.py clean && sudo python3 setup.py build && sudo python3 setup.py install && cd .. python3 -c "import gym; gym.make('LunarLander-v2')" python3 -c "import gym; gym.make('SpaceInvaders-v0')" + + +echo " +================================================ + +Installation complete. + +================================================ +" \ No newline at end of file diff --git a/bin/setup_macOS b/bin/setup_macOS new file mode 100755 index 0000000..c82fe1e --- /dev/null +++ b/bin/setup_macOS @@ -0,0 +1,50 @@ +#!/bin/bash +# This script sets up OpenAI Lab for macOS + +# Fail on the first error; killable by SIGINT +set -e +trap "exit" INT + +# install system dependencies +if which brew >/dev/null; then + echo "Brew is already installed" +else + ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" +fi + +# system dependencies for full openai gym +hb_list=(cmake boost boost-python sdl2 swig wget) +for item in "${hb_list[@]}"; do + brew info "${item}" | grep --quiet 'Not installed' && brew install "${item}" +done + +# install noti for auto-notification +if which noti >/dev/null; then + echo "Noti is already installed" +else + curl -L https://github.com/variadico/noti/releases/download/v2.5.0/noti2.5.0.darwin-amd64.tar.gz | tar -xz + sudo mv noti /usr/local/bin/ +fi + +# install nodejs (for npm and file watcher) +if which node >/dev/null; then + echo "Nodejs is already installed" +else + brew install node +fi +# install npm modules +if [ -d ./node_modules ]; then + echo "Npm modules already installed" +else + npm install; sudo npm i -g grunt-cli +fi + +# install python3 +if which python3 >/dev/null; then + echo "Python3 is already installed" +else + brew install python3 +fi + +# install python dependencies +sudo python3 -m pip install -r requirements.txt diff --git a/bin/setup_ubuntu b/bin/setup_ubuntu new file mode 100644 index 0000000..e2c0973 --- /dev/null +++ b/bin/setup_ubuntu @@ -0,0 +1,45 @@ +#!/bin/bash +# This script sets up OpenAI Lab for Linux Ubuntu + +# Fail on the first error; killable by SIGINT +set -e +trap "exit" INT + +# install system dependencies +sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test && sudo apt-get update +sudo apt-get install -y gcc-4.9 g++-4.9 libhdf5-dev libopenblas-dev git + +# system dependencies for full openai gym +sudo apt-get install -y cmake zlib1g-dev libjpeg-dev xvfb libav-tools xorg-dev python-opengl libboost-all-dev libsdl2-dev swig + +# install noti for auto-notification +if which noti >/dev/null; then + echo "Noti is already installed" +else + curl -L https://github.com/variadico/noti/releases/download/v2.5.0/noti2.5.0.linux-amd64.tar.gz | tar -xz + sudo mv noti /usr/bin/ +fi + +# install nodejs (for npm and file watcher) +if which node >/dev/null; then + echo "Nodejs is already installed" +else + curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash - + sudo apt-get install -y nodejs +fi +# install npm modules +if [ -d ./node_modules ]; then + echo "Npm modules already installed" +else + npm install; sudo npm i -g grunt-cli +fi + +# install python3 +if which python3 >/dev/null; then + echo "Python3 is already installed" +else + sudo apt-get -y install python3-dev python3-pip python3-setuptools +fi + +# install python dependencies +sudo python3 -m pip install -r requirements.txt diff --git a/circle.yml b/circle.yml index e7529bd..ee2f616 100644 --- a/circle.yml +++ b/circle.yml @@ -5,14 +5,11 @@ machine: dependencies: pre: - sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test && sudo apt-get update - - sudo apt-get install -y gcc-4.9 g++-4.9 libhdf5-dev libopenblas-dev git python3-dev python3-setuptools + - sudo apt-get install -y gcc-4.9 g++-4.9 libhdf5-dev libopenblas-dev git python3-tk tk-dev python3-dev python3-setuptools + - sudo apt-get install -y cmake zlib1g-dev libjpeg-dev xvfb libav-tools xorg-dev python-opengl libboost-all-dev libsdl2-dev swig - pip install -U pip - - pip install six h5py numpy scipy matplotlib seaborn pandas atari_py Pillow PyOpenGL glances mem_top pytest-cov pytest-xdist codacy-coverage override: - - pip install tensorflow - - pip install theano - - pip install keras - - git clone https://github.com/openai/gym.git && cd gym && pip install -e .[all] && cd .. + - pip install -r requirements.txt - mkdir ~/.keras && cp ./config/keras.json ~/.keras/ test: override: diff --git a/config/example-default.json b/config/example-default.json index c3bc399..9d94fcd 100644 --- a/config/example-default.json +++ b/config/example-default.json @@ -3,7 +3,6 @@ "NOTI_SLACK_DEST": "#rl-monitor", "NOTI_SLACK_TOK": "GET_SLACK_BOT_TOKEN_FROM_https://my.slack.com/services/new/bot", "experiments": [ - "dev_dqn", - "dqn" + "quickstart_dqn" ] } diff --git a/environment.yml b/environment.yml new file mode 100644 index 0000000..b3bd707 --- /dev/null +++ b/environment.yml @@ -0,0 +1,23 @@ +name: openai_lab +channels: + - conda-forge +dependencies: +- python>=3.5 +- anaconda +- six +- h5py +- matplotlib==1.4.3 +- seaborn>=0.7.1 +- Pillow>=3.3.1 +- PyOpenGL>=3.1.0 +- glances>=2.6.2 +- pytest-cov>=2.3.1 +- pytest-xdist>=1.15.0 +- pip: + - codacy-coverage>=1.3.3 + - mem_top==0.1.5 + - atari_py>=0.0.18 + - cmake==0.6.0 + - tensorflow>=1.0.0 + - Keras>=1.2.2,<2.0.0 + - "--editable=git+https://github.com/kengz/gym.git#egg=gym[all]" diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..c78cb96 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,18 @@ +six +h5py +numpy>=1.12 +scipy>=0.18 +matplotlib==1.4.3 +seaborn>=0.7.1 +pandas>=0.18.1 +atari_py>=0.0.18 +Pillow>=3.3.1 +PyOpenGL>=3.1.0 +glances>=2.6.2 +mem_top==0.1.5 +pytest-cov>=2.3.1 +pytest-xdist>=1.15.0 +codacy-coverage>=1.3.3 +tensorflow>=1.0.0 +Keras>=1.2.2,<2.0.0 +-e git+https://github.com/kengz/gym.git#egg=gym[all] diff --git a/rl/spec/classic_experiment_specs.json b/rl/spec/classic_experiment_specs.json index 58fe583..3658017 100644 --- a/rl/spec/classic_experiment_specs.json +++ b/rl/spec/classic_experiment_specs.json @@ -1,4 +1,27 @@ { + "quickstart_dqn": { + "problem": "CartPole-v0", + "Agent": "DQN", + "HyperOptimizer": "GridSearch", + "Memory": "LinearMemoryWithForgetting", + "Optimizer": "AdamOptimizer", + "Policy": "BoltzmannPolicy", + "PreProcessor": "NoPreProcessor", + "param": { + "lr": 0.02, + "gamma": 0.99, + "hidden_layers": [64], + "hidden_layers_activation": "sigmoid", + "exploration_anneal_episodes": 10 + }, + "param_range": { + "lr": [0.001, 0.01], + "hidden_layers": [ + [32], + [64] + ] + } + }, "dqn_epsilon": { "problem": "CartPole-v0", "Agent": "DQN", diff --git a/test/test_advanced.py b/test/test_advanced.py index 8056d23..eec9607 100644 --- a/test/test_advanced.py +++ b/test/test_advanced.py @@ -33,8 +33,6 @@ def test_mountain_dqn(cls): data_df = run('mountain_dqn') assert isinstance(data_df, pd.DataFrame) - @unittest.skipIf(environ.get('CI'), - "OpenAI Gym Box2D swigconstant error, issue #100") @classmethod def test_lunar_dqn(cls): data_df = run('lunar_dqn')