diff --git a/.github/workflows/unittest.yml b/.github/workflows/unittest.yml new file mode 100644 index 000000000..c010df75b --- /dev/null +++ b/.github/workflows/unittest.yml @@ -0,0 +1,113 @@ +name: PARL CI +on: + pull_request: + branches: + - develop + +jobs: + + CheckStyle: + name: CheckStyle + runs-on: ubuntu-20.04 + steps: + - name: Checkout PR code + uses: actions/checkout@v3 + + - name: Set up Python 3.7 + uses: actions/setup-python@v2 + with: + python-version: 3.7 + + - name: Check Style + run: | + ls + pwd + cat .github/workflows/*.yml + bash .teamcity/action_build.sh check_style + + PaddleTest: + name: UnitTest for Paddle + runs-on: ubuntu-20.04 + strategy: + matrix: + python-version: [3.8, 3.9] + + steps: + - name: Checkout PR code + uses: actions/checkout@v3 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + + - name: Install Package + run: | + sudo apt-get update + sudo apt-get install -y cmake + sudo apt-get install -y libgflags-dev libunwind-dev libgoogle-glog-dev libomp-dev unzip + sudo apt-get install -y libgtest-dev && cd /usr/src/gtest && sudo mkdir build && cd build && sudo cmake .. + sudo make && ls -l lib && sudo cp lib/libgtest*.a /usr/local/lib + md5sum /usr/src/googletest/googletest/build/lib/*.a && md5sum lib/*.a + + - name: Run Paddle tests + run: | + bash .teamcity/action_build.sh test_paddle + + TorchTest: + name: UnitTest for Troch + runs-on: ubuntu-20.04 + strategy: + matrix: + python-version: [3.8] + + steps: + - name: Checkout PR code + uses: actions/checkout@v3 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + + - name: Install Package + run: | + sudo apt-get update + sudo apt-get install -y cmake + sudo apt-get install -y libgflags-dev libunwind-dev libgoogle-glog-dev libomp-dev unzip + sudo apt-get install -y libgtest-dev && cd /usr/src/gtest && sudo mkdir build && cd build && sudo cmake .. + sudo make && ls -l lib && sudo cp lib/libgtest*.a /usr/local/lib + md5sum /usr/src/googletest/googletest/build/lib/*.a && md5sum lib/*.a + + - name: Run Torch tests + run: | + bash .teamcity/action_build.sh test_torch + + ExampleTest: + name: Test for Examples + runs-on: ubuntu-20.04 + strategy: + matrix: + python-version: [3.8] + + steps: + - name: Checkout PR code + uses: actions/checkout@v3 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + + - name: Install Package + run: | + sudo apt-get update + sudo apt-get install -y cmake + sudo apt-get install -y libgflags-dev libunwind-dev libgoogle-glog-dev libomp-dev unzip + sudo apt-get install -y libgtest-dev && cd /usr/src/gtest && sudo mkdir build && cd build && sudo cmake .. + sudo make && ls -l lib && sudo cp lib/libgtest*.a /usr/local/lib + md5sum /usr/src/googletest/googletest/build/lib/*.a && md5sum lib/*.a + + - name: Run Example tests + run: | + bash .teamcity/action_build.sh example diff --git a/.teamcity/action_build.sh b/.teamcity/action_build.sh new file mode 100755 index 000000000..0bea571d3 --- /dev/null +++ b/.teamcity/action_build.sh @@ -0,0 +1,258 @@ +#!/usr/bin/env bash + +# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +set -ex + +function init() { + RED='\033[0;31m' + BLUE='\033[0;34m' + BOLD='\033[1m' + NONE='\033[0m' + + REPO_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}")/../" && pwd )" + + ls -l /usr/local/ + export LC_ALL=C.UTF-8 + export LANG=C.UTF-8 + + which python + python -c "import platform;print(platform.architecture()[0]);print(platform.machine())" +} + +function run_example_test { + for exp in QuickStart DQN DQN_variant PPO SAC TD3 OAC DDPG MADDPG ES A2C + do + sed -i '/paddlepaddle/d' ./examples/${exp}/requirements*.txt + sed -i '/parl/d' ./examples/${exp}/requirements*.txt + done + + python -m pip install -r ./examples/QuickStart/requirements.txt + python examples/QuickStart/train.py + python -m pip uninstall -r ./examples/QuickStart/requirements.txt -y + + # TODO: raise Error in Atari env + # python -m pip install -r ./examples/DQN/requirements.txt + # python examples/DQN/train.py + # python -m pip uninstall -r ./examples/DQN/requirements.txt -y + + # python -m pip install -r ./examples/DQN_variant/requirements.txt + # python examples/DQN_variant/train.py --train_total_steps 200 --warmup_size 100 --test_every_steps 50 --dueling True --env PongNoFrameskip-v4 + # python -m pip uninstall -r ./examples/DQN_variant/requirements.txt -y + + # python -m pip install -r ./examples/PPO/requirements_atari.txt + # python examples/PPO/train.py --train_total_steps 5000 --env PongNoFrameskip-v4 + # python -m pip uninstall -r ./examples/PPO/requirements_atari.txt -y + + python -m pip install -r ./examples/PPO/requirements_mujoco.txt + python examples/PPO/train.py --train_total_steps 5000 --env HalfCheetah-v4 --continuous_action + python -m pip uninstall -r ./examples/PPO/requirements_mujoco.txt -y + + python -m pip install -r ./examples/SAC/requirements.txt + python examples/SAC/train.py --train_total_steps 5000 --env HalfCheetah-v4 + python -m pip uninstall -r ./examples/SAC/requirements.txt -y + + python -m pip install -r ./examples/TD3/requirements.txt + python examples/TD3/train.py --train_total_steps 5000 --env HalfCheetah-v4 + python -m pip uninstall -r ./examples/TD3/requirements.txt -y + + python -m pip install -r ./examples/OAC/requirements.txt + python examples/OAC/train.py --train_total_steps 5000 --env HalfCheetah-v4 + python -m pip uninstall -r ./examples/OAC/requirements.txt -y + + python -m pip install -r ./examples/DDPG/requirements.txt + python examples/DDPG/train.py --train_total_steps 5000 --env HalfCheetah-v4 + python -m pip uninstall -r ./examples/DDPG/requirements.txt -y + + xparl start --port 8837 --cpu_num 4 + python -m pip install -r ./examples/ES/requirements.txt + sed -i 's/24/4/g' ./examples/ES/es_config.py + cat ./examples/ES/es_config.py + python ./examples/ES/train.py --train_steps 2 --actor_num 4 + python -m pip uninstall -r ./examples/ES/requirements.txt -y + xparl stop + + # TODO: raise Error while in Atari env + # xparl start --port 8110 --cpu_num 5 + # python -m pip install -r ./examples/A2C/requirements.txt + # python ./examples/A2C/train.py --max_sample_steps 50000 + # python -m pip uninstall -r ./examples/A2C/requirements.txt -y + # xparl stop + + python -m pip install -r ./examples/MADDPG/requirements.txt + python examples/MADDPG/train.py --max_episodes 21 --test_every_episodes 10 + python -m pip uninstall -r ./examples/MADDPG/requirements.txt -y +} + +function print_usage() { + echo -e "\n${RED}Usage${NONE}: + ${BOLD}$0${NONE} [OPTION]" + + echo -e "\n${RED}Options${NONE}: + ${BLUE}test_paddle${NONE}: run all unit tests with paddlepaddle + ${BLUE}test_torch${NONE}: run all unit tests with torch + ${BLUE}check_style${NONE}: run check for code style + ${BLUE}example${NONE}: run examples + " +} + +function abort(){ + echo "Your change doesn't follow PaddlePaddle's code style." 1>&2 + echo "Please use pre-commit to check what is wrong." 1>&2 + exit 1 +} + +function check_style() { + trap 'abort' 0 + set -e + + python -m pip install pre-commit + pre-commit install + # clang-format --version + + if ! pre-commit run -a ; then + git diff + exit 1 + fi + + trap : 0 +} + +function run_test_with_cpu() { + export CUDA_VISIBLE_DEVICES="" + + mkdir -p ${REPO_ROOT}/build + cd ${REPO_ROOT}/build + if [ $# -eq 0 ];then + cmake .. + else + cmake .. -$1=ON + fi + cat <