Skip to content

Commit

Permalink
[misc] Run all unit tests for gym jiminy base modules on Python 3.12 …
Browse files Browse the repository at this point in the history
…and Debug.
  • Loading branch information
duburcqa committed Mar 14, 2024
1 parent 9a31ca4 commit ea3b8fe
Show file tree
Hide file tree
Showing 12 changed files with 100 additions and 74 deletions.
52 changes: 28 additions & 24 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ jobs:
run: |
unset Boost_ROOT
mkdir "$RootDir/build"
cd "$RootDir/build"
cmake "$RootDir" -DCMAKE_INSTALL_PREFIX="$InstallDir" -DCMAKE_PREFIX_PATH="$InstallDir" \
mkdir "${RootDir}/build"
cd "${RootDir}/build"
cmake "${RootDir}" -DCMAKE_INSTALL_PREFIX="$InstallDir" -DCMAKE_PREFIX_PATH="$InstallDir" \
-DBOOST_ROOT="$InstallDir" -DBoost_INCLUDE_DIR="$InstallDir/include" \
-DBoost_NO_SYSTEM_PATHS=TRUE -DBoost_NO_BOOST_CMAKE=TRUE -DBoost_USE_STATIC_LIBS=ON \
-DPYTHON_EXECUTABLE="${PYTHON_EXECUTABLE}" \
Expand All @@ -103,9 +103,9 @@ jobs:
run: |
"$InstallDir/bin/jiminy_double_pendulum"
mkdir -p "$RootDir/core/examples/external_project/build"
cd "$RootDir/core/examples/external_project/build"
cmake "$RootDir/core/examples/external_project/" -DCMAKE_INSTALL_PREFIX="$InstallDir" \
mkdir -p "${RootDir}/core/examples/external_project/build"
cd "${RootDir}/core/examples/external_project/build"
cmake "${RootDir}/core/examples/external_project/" -DCMAKE_INSTALL_PREFIX="$InstallDir" \
-DCMAKE_PREFIX_PATH="$InstallDir" -DPYTHON_EXECUTABLE="${PYTHON_EXECUTABLE}" \
-DCMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS}" -DCMAKE_BUILD_TYPE="${BUILD_TYPE}"
make install
Expand All @@ -118,39 +118,43 @@ jobs:
run: |
ctest --output-on-failure --test-dir "${RootDir}/build/core/unit"
"${PYTHON_EXECUTABLE}" -m unittest discover -s "$RootDir/python/jiminy_py/unit_py" -v
"${PYTHON_EXECUTABLE}" -m unittest discover -s "${RootDir}/python/jiminy_py/unit_py" -v
- name: Run unit tests for gym_jiminy
if: matrix.BUILD_TYPE == 'Release' && matrix.PYTHON_VERSION != '3.12'
- name: Run unit tests for gym jiminy base module
run: |
cd "$RootDir/python/gym_jiminy/examples/rllib"
gdb -batch -ex "run" -ex "bt" --args "${PYTHON_EXECUTABLE}" acrobot_ppo.py 2>&1 | \
grep -v ^"No stack."$ && exit 1
if [[ "${{ matrix.BUILD_TYPE }}" == 'Debug' ]] ; then
export JIMINY_BUILD_DEBUG=
fi
"${PYTHON_EXECUTABLE}" -m unittest discover -s "${RootDir}/python/gym_jiminy/unit_py" -v
"${PYTHON_EXECUTABLE}" -m unittest discover -s "$RootDir/python/gym_jiminy/unit_py" -v
- name: Run examples for gym jiminy add-on modules
if: matrix.BUILD_TYPE != 'Debug' && matrix.PYTHON_VERSION != '3.12'
run: |
cd "${RootDir}/python/gym_jiminy/examples/rllib"
"${PYTHON_EXECUTABLE}" acrobot_ppo.py
- name: Python static type checker
if: matrix.PYTHON_VERSION == '3.8' && matrix.BUILD_TYPE == 'Release'
if: matrix.PYTHON_VERSION == '3.8' && matrix.BUILD_TYPE != 'Debug'
run: |
# Generate stubs
stubgen -p jiminy_py -o $RootDir/build/pypi/jiminy_py/src
"${PYTHON_EXECUTABLE}" "$RootDir/build_tools/stub_gen.py" \
-o $RootDir/build/stubs --ignore-invalid=all jiminy_py
cp $RootDir/build/stubs/jiminy_py-stubs/core/__init__.pyi \
$RootDir/build/pypi/jiminy_py/src/jiminy_py/core/core.pyi
stubgen -p jiminy_py -o ${RootDir}/build/pypi/jiminy_py/src
"${PYTHON_EXECUTABLE}" "${RootDir}/build_tools/stub_gen.py" \
-o ${RootDir}/build/stubs --ignore-invalid=all jiminy_py
cp ${RootDir}/build/stubs/jiminy_py-stubs/core/__init__.pyi \
${RootDir}/build/pypi/jiminy_py/src/jiminy_py/core/core.pyi
# Re-install jiminy with stubs
cd "$RootDir/build"
cd "${RootDir}/build"
make install
# mypy is not able to follow `.pth` when checking directories or files.
# This bug may be fixed in the future. The only workaround is to set `MYPYPATH` manually.
# Anyway, the stubs generated for eigenpy, hppfcl and pinocchio they are incomplete and
# even partially wrong, so it is better to ignore them for now.
# See: https://github.com/python/mypy/issues/14848.
cd "$RootDir/python/jiminy_py/"
mypy --config-file="$RootDir/.mypy.ini" -p src
cd "${RootDir}/python/jiminy_py/"
mypy --config-file="${RootDir}/.mypy.ini" -p src
for name in "common" "envs" "toolbox" "rllib"; do
cd "$RootDir/python/gym_jiminy/$name"
mypy --config-file="$RootDir/.mypy.ini" -p gym_jiminy
cd "${RootDir}/python/gym_jiminy/$name"
mypy --config-file="${RootDir}/.mypy.ini" -p gym_jiminy
done
23 changes: 12 additions & 11 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ jobs:
-p "macosx_${OSX_DEPLOYMENT_TARGET//./_}_${WHEEL_ARCH}" "${RootDir}/build/wheelhouse/"*.whl
"${PYTHON_EXECUTABLE}" -m pip install --force-reinstall --no-deps "${RootDir}/build/wheelhouse/"*.whl
- name: Upload the wheel for Linux of jiminy_py
if: matrix.BUILD_TYPE == 'Release'
if: matrix.BUILD_TYPE != 'Debug'
uses: actions/upload-artifact@v4
with:
name: wheelhouse-${{ matrix.PYTHON_VERSION }}
Expand Down Expand Up @@ -175,24 +175,25 @@ jobs:
cd "${RootDir}/python/jiminy_py/unit_py"
"${PYTHON_EXECUTABLE}" -m unittest discover -v
- name: Run unit tests for gym_jiminy
if: matrix.BUILD_TYPE != 'Release'
- name: Run unit tests for gym jiminy base module
run: |
# Disabling `test_pipeline_control.py` on MacOS because `test_pid_standing` is failing
# for 'panda3d-sync' backend due to meshes still loading at screenshot time.
cd "${RootDir}/python/gym_jiminy/unit_py"
"${PYTHON_EXECUTABLE}" -m unittest test_pipeline_design.py -v
export LD_LIBRARY_PATH="${InstallDir}/lib/:/usr/local/lib"
# FIXME: Disabling `test_pipeline_control.py` on MacOS because `test_pid_standing` is
# failing for 'panda3d-sync' backend due to meshes still loading at screenshot time.
if [[ "${{ matrix.BUILD_TYPE }}" == 'Debug' ]] ; then
export JIMINY_BUILD_DEBUG=
fi
"${PYTHON_EXECUTABLE}" -m unittest discover -s "${RootDir}/python/gym_jiminy/unit_py" -v
- name: Run unit tests for gym jiminy
if: matrix.BUILD_TYPE == 'Release' && matrix.PYTHON_VERSION != '3.12'
- name: Run examples for gym jiminy add-on modules
if: matrix.BUILD_TYPE != 'Debug' && matrix.PYTHON_VERSION != '3.12'
run: |
export LD_LIBRARY_PATH="${InstallDir}/lib/:/usr/local/lib"
cd "${RootDir}/python/gym_jiminy/examples/rllib"
"${PYTHON_EXECUTABLE}" acrobot_ppo.py
"${PYTHON_EXECUTABLE}" -m unittest discover -s "${RootDir}/python/gym_jiminy/unit_py" -v
#########################################################################################

publish-pypi-macos:
Expand Down
19 changes: 9 additions & 10 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ jobs:
#####################################################################################

- name: PEP8 Code Style Check
if: matrix.OS == 'ubuntu-20.04' && matrix.BUILD_TYPE == 'Release' && matrix.COMPILER == 'gcc'
if: matrix.OS == 'ubuntu-20.04' && matrix.BUILD_TYPE != 'Debug' && matrix.COMPILER == 'gcc'
run: |
"${PYTHON_EXECUTABLE}" -m pip install flake8
flake8 --ignore=E121,E126,E123,E226,E241,E266,E402,E741,F405,W504 \
Expand Down Expand Up @@ -143,24 +143,23 @@ jobs:
"${PYTHON_EXECUTABLE}" -m unittest discover -s "${RootDir}/python/jiminy_py/unit_py" -v
- name: Run unit tests for gym_jiminy
if: matrix.BUILD_TYPE != 'Release'
- name: Run unit tests for gym jiminy base module
run: |
cd "${RootDir}/python/gym_jiminy/unit_py"
"${PYTHON_EXECUTABLE}" -m unittest test_pipeline_control.py test_pipeline_design.py -v
if [[ "${{ matrix.BUILD_TYPE }}" == 'Debug' ]] ; then
export JIMINY_BUILD_DEBUG=
fi
"${PYTHON_EXECUTABLE}" -m unittest discover -s "${RootDir}/python/gym_jiminy/unit_py" -v
- name: Run unit tests for gym_jiminy
if: matrix.BUILD_TYPE == 'Release'
- name: Run examples for gym jiminy add-on modules
if: matrix.BUILD_TYPE != 'Debug'
run: |
cd "${RootDir}/python/gym_jiminy/examples/rllib"
"${PYTHON_EXECUTABLE}" acrobot_ppo.py
"${PYTHON_EXECUTABLE}" -m unittest discover -s "${RootDir}/python/gym_jiminy/unit_py" -v
#####################################################################################

- name: Python linter
if: matrix.OS == 'ubuntu-20.04' && matrix.BUILD_TYPE == 'Release' && matrix.COMPILER == 'gcc'
if: matrix.OS == 'ubuntu-20.04' && matrix.BUILD_TYPE != 'Debug' && matrix.COMPILER == 'gcc'
run: |
cd "${RootDir}/python/jiminy_py/"
pylint --rcfile="${RootDir}/.pylintrc" "src/"
Expand Down
20 changes: 11 additions & 9 deletions .github/workflows/win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ jobs:
python -m pip install --force-reinstall --no-deps $wheel_path
}
- name: Upload the wheel for Windows of jiminy_py
if: matrix.BUILD_TYPE == 'Release'
if: matrix.BUILD_TYPE != 'Debug'
uses: actions/upload-artifact@v4
with:
name: wheelhouse-${{ matrix.PYTHON_VERSION }}
Expand Down Expand Up @@ -182,24 +182,26 @@ jobs:
python -m unittest discover -s "${RootDir}/python/jiminy_py/unit_py" -v
- name: Run unit tests for gym_jiminy
if: matrix.BUILD_TYPE != 'Release'
- name: Run unit tests for gym jiminy base module
run: |
$RootDir = "${env:GITHUB_WORKSPACE}/workspace" -replace '\\', '/'
Set-Location -Path "$RootDir/python/gym_jiminy/unit_py"
python -m unittest test_pipeline_control.py test_pipeline_design.py -v
if ("${{ matrix.BUILD_TYPE }}" -eq "Debug") {
${env:JIMINY_BUILD_DEBUG} = 1
}
python -m unittest discover -s "$RootDir/python/gym_jiminy/unit_py" -v
- name: Running unit tests for gym_jiminy
if: matrix.BUILD_TYPE == 'Release' && matrix.PYTHON_VERSION != '3.12'
- name: Run examples for gym jiminy add-on modules
if: matrix.BUILD_TYPE != 'Debug' && matrix.PYTHON_VERSION != '3.11' && matrix.PYTHON_VERSION != '3.12'
run: |
$RootDir = "${env:GITHUB_WORKSPACE}/workspace" -replace '\\', '/'
# FIXME: Python 3.11 was not supported by ray on Windows until very recently.
# It has been fixed on master but not on the latest available release (2.93).
# See: https://github.com/ray-project/ray/pull/42097
Set-Location -Path "$RootDir/python/gym_jiminy/examples/rllib"
python acrobot_ppo.py
python -m unittest discover -s "$RootDir/python/gym_jiminy/unit_py" -v
#########################################################################################

publish-pypi-win10:
Expand Down
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ cmake_minimum_required(VERSION 3.12.4)
# Set the build version (specify a tweak version to indicated post-release if needed)
set(BUILD_VERSION 1.8.3)

# MSVC runtime library flags are defined by 'CMAKE_MSVC_RUNTIME_LIBRARY'
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.15.7)
cmake_policy(SET CMP0091 NEW)
set(CMAKE_POLICY_DEFAULT_CMP0091 NEW)
endif()

# Set find_package strategy to look for both upper-case and case-preserved variables
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.27.0)
cmake_policy(SET CMP0144 NEW)
set(CMAKE_POLICY_DEFAULT_CMP0144 NEW)
endif()

# Set compatibility
set(COMPATIBILITY_VERSION SameMinorVersion)

Expand Down
10 changes: 0 additions & 10 deletions build_tools/cmake/base.cmake
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
# Minimum version required
cmake_minimum_required(VERSION 3.12.4)

# MSVC runtime library flags are defined by 'CMAKE_MSVC_RUNTIME_LIBRARY'
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.15.7)
cmake_policy(SET CMP0091 NEW)
endif()

# Set find_package strategy to look for both upper-case and case-preserved variables
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.27.0)
cmake_policy(SET CMP0144 NEW)
endif()

# Forces GCC/Clang compilers to enable color diagnostics.
# CMake versions 3.24 and below do not support this option, so we have
# to invoke the color diagnostics flags manually.
Expand Down
14 changes: 8 additions & 6 deletions build_tools/cmake/setupPython.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ else()
OUTPUT_VARIABLE HAS_NO_WRITE_PERMISSION_ON_PYTHON_SYS_SITELIB)
endif()

set(PYTHON_INSTALL_FLAGS " --no-warn-script-location --prefer-binary ")
# Libraries not distributed as wheel must be explicitly whitelisted via '--no-binary'.
set(PYTHON_INSTALL_FLAGS " --no-warn-script-location --only-binary :all:")
if(${HAS_NO_WRITE_PERMISSION_ON_PYTHON_SYS_SITELIB})
set(PYTHON_INSTALL_FLAGS "${PYTHON_INSTALL_FLAGS} --user ")
message(STATUS "No right on Python system site-packages: ${Python_SYS_SITELIB}.\n"
Expand Down Expand Up @@ -168,14 +169,15 @@ function(deployPythonPackageDevelop)

# Loop over all packages sequentially
foreach(PKG_NAME IN LISTS ARGS)
install(CODE "execute_process(COMMAND ${Python_EXECUTABLE} -m pip install ${PYTHON_INSTALL_FLAGS} -e .
install(CODE "cmake_policy(SET CMP0012 NEW)
execute_process(COMMAND ${Python_EXECUTABLE} -m pip install ${PYTHON_INSTALL_FLAGS} -e .
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/${PKG_NAME}
RESULT_VARIABLE RETURN_CODE)
if(NOT RETURN_CODE EQUAL 0)
if (NOT ${ALLOW_FAILURE})
message(FATAL_ERROR \"Python installation of '${PKG_NAME}' failed.\")
if(RETURN_CODE AND NOT RETURN_CODE EQUAL 0)
if (${ALLOW_FAILURE})
message(AUTHOR_WARNING \"Python installation of '${PKG_NAME}' failed.\")
else()
message(WARNING \"Python installation of '${PKG_NAME}' failed.\")
message(FATAL_ERROR \"Python installation of '${PKG_NAME}' failed.\")
endif()
endif()")
endforeach()
Expand Down
2 changes: 1 addition & 1 deletion python/gym_jiminy/rllib/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
# * <1.6.0: GPU detection must be patched to work
# * > 2.5.0: multi-GPU support
# * 1.11.0 / 2.2.0 / 2.5.0 / 2.9.0: Breaking changes
"ray[default,rllib]~=2.9.0",
"ray[rllib]~=2.9.0",
# Used for monitoring (logging and publishing) learning progress
"tensorboardX",
# Plot data directly in terminal to monitor stats without X-server
Expand Down
7 changes: 5 additions & 2 deletions python/gym_jiminy/unit_py/test_deformation_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
from gym_jiminy.envs import AntJiminyEnv


DEBUG = "JIMINY_BUILD_DEBUG" in os.environ


class DeformationEstimatorBlock(unittest.TestCase):
""" TODO: Write documentation
"""
Expand Down Expand Up @@ -102,7 +105,7 @@ def test_arm(self):
simulator.engine.set_options(engine_options)

# Instantiate the environment
env = BaseJiminyEnv(simulator, step_dt=0.01)
env = BaseJiminyEnv(simulator, step_dt=0.01, debug=DEBUG)

# Add controller and observer blocks
pd_controller = PDController(
Expand Down Expand Up @@ -243,7 +246,7 @@ def _setup(self) -> None:
)

# Instantiate the environment
env = PipelineEnv()
env = PipelineEnv(debug=DEBUG)

# Run a simulation
env.reset(seed=0)
Expand Down
6 changes: 6 additions & 0 deletions python/gym_jiminy/unit_py/test_pipeline_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""
import os
import io
import sys
import base64
import logging
import unittest
Expand Down Expand Up @@ -29,6 +30,9 @@
# Small tolerance for numerical equality
TOLERANCE = 1.0e-6

# Skip some tests if Jiminy has been compiled in debug on Mac OS
DEBUG = "JIMINY_BUILD_DEBUG" in os.environ


class PipelineControl(unittest.TestCase):
""" TODO: Write documentation
Expand Down Expand Up @@ -101,6 +105,8 @@ def _test_pid_standing(self):
self.assertTrue(np.all(
np.abs(velocity_mes[time > time[-1] - 1.0]) < 1.0e-3))

@unittest.skipIf(DEBUG and sys.platform == "darwin",
"skipping when compiled in debug on Mac OS")
def test_pid_standing(self):
for backend in ('panda3d-sync', 'meshcat'):
for Env in (AtlasPDControlJiminyEnv,
Expand Down
7 changes: 7 additions & 0 deletions python/gym_jiminy/unit_py/test_training_toys_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
low-level Jiminy engine, to the Gym environment integration. However, it does
not assessed that the viewer is working properly.
"""
import os
import unittest
from typing import Optional, Dict, Any

Expand All @@ -14,9 +15,13 @@
from utilities import train


# Fix the seed and number of threads for CI stability
SEED = 0
N_THREADS = 5

# Skip some tests if Jiminy has been compiled in debug
DEBUG = "JIMINY_BUILD_DEBUG" in os.environ


class ToysModelsStableBaselinesPPO(unittest.TestCase):
"""Solve several official Open AI Gym toys models problems simulated in
Expand Down Expand Up @@ -89,6 +94,7 @@ def _ppo_training(cls,
# Run the learning process
return train(train_agent, test_env, max_timesteps=200000)

@unittest.skipIf(DEBUG, "skipping when compiled in debug")
def test_acrobot_stable_baselines(self):
"""Solve acrobot for both continuous and discrete action spaces.
"""
Expand All @@ -97,6 +103,7 @@ def test_acrobot_stable_baselines(self):
self.assertTrue(self._ppo_training(
"gym_jiminy.envs:acrobot", {'continuous': False}))

@unittest.skipIf(DEBUG, "skipping when compiled in debug")
def test_cartpole_stable_baselines(self):
"""Solve cartpole for both continuous and discrete action spaces.
"""
Expand Down
2 changes: 1 addition & 1 deletion python/jiminy_pywrap/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 3.12.4)
# Project name
project(${LIBRARY_NAME}_pywrap VERSION ${BUILD_VERSION})

# Find libraries and headers.
# Find libraries and headers
find_package(eigenpy 2.9.0 REQUIRED NO_MODULE NO_CMAKE_SYSTEM_PATH) # >=2.9.0 fully support vectorization

# Enable all warnings
Expand Down

0 comments on commit ea3b8fe

Please sign in to comment.