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 15, 2024
1 parent 9a31ca4 commit b69f69d
Show file tree
Hide file tree
Showing 14 changed files with 116 additions and 80 deletions.
53 changes: 29 additions & 24 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,10 @@ 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}" -Wdev \
-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 +104,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 +119,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
26 changes: 14 additions & 12 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ jobs:
mkdir "${RootDir}/build"
cd "${RootDir}/build"
export LD_LIBRARY_PATH="${InstallDir}/lib/:/usr/local/lib"
cmake "${RootDir}" -DCMAKE_INSTALL_PREFIX="${InstallDir}" -DCMAKE_PREFIX_PATH="${InstallDir}" \
cmake "${RootDir}" -Wdev \
-DCMAKE_INSTALL_PREFIX="${InstallDir}" -DCMAKE_PREFIX_PATH="${InstallDir}" \
-DCMAKE_C_COMPILER="${CMAKE_C_COMPILER}" -DCMAKE_CXX_COMPILER="${CMAKE_CXX_COMPILER}" \
-DCMAKE_OSX_ARCHITECTURES="${OSX_ARCHITECTURES}" \
-DCMAKE_OSX_DEPLOYMENT_TARGET="${OSX_DEPLOYMENT_TARGET}" \
Expand Down Expand Up @@ -140,7 +141,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 +176,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
21 changes: 10 additions & 11 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 All @@ -94,7 +94,7 @@ jobs:
mkdir "${RootDir}/build" "${InstallDir}"
cd "${RootDir}/build"
cmake "${RootDir}" -G "${{ matrix.GENERATOR }}" \
cmake "${RootDir}" -Wdev -G "${{ matrix.GENERATOR }}" \
-DCMAKE_EXE_LINKER_FLAGS="${{ matrix.LINKER_FLAGS }}" \
-DCMAKE_SHARED_LINKER_FLAGS="${{ matrix.LINKER_FLAGS }}" \
-DCMAKE_C_COMPILER="${CMAKE_C_COMPILER}" -DCMAKE_CXX_COMPILER="${CMAKE_CXX_COMPILER}" \
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
26 changes: 16 additions & 10 deletions .github/workflows/win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ jobs:
#####################################################################################

- name: Configure and build jiminy
# FIXME: CMake exits with non-zero code if an error occurred in 'execute_process'.
# Indeed, such errors are expected to occur if some gym_jiminy add-on cannot be
# installed because of missing pre-compiled dependency on Pypi.
continue-on-error: true
run: |
$ErrorActionPreference = "Stop"
Set-PSDebug -Trace 1
Expand All @@ -86,7 +90,7 @@ jobs:
New-Item -ItemType "directory" -Force -Path "$RootDir/build"
}
Set-Location -Path $RootDir/build
cmake "$RootDir" -G "${env:GENERATOR}" -DCMAKE_GENERATOR_PLATFORM=x64 `
cmake "$RootDir" -Wdev -G "${env:GENERATOR}" -DCMAKE_GENERATOR_PLATFORM=x64 `
-DCMAKE_MSVC_RUNTIME_LIBRARY="MultiThreaded$<$<CONFIG:Debug>:Debug>DLL" `
-DCMAKE_INSTALL_PREFIX="$InstallDir" -DCMAKE_PREFIX_PATH="$InstallDir" `
-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=OFF -DCMAKE_VERBOSE_MAKEFILE=ON `
Expand Down Expand Up @@ -141,7 +145,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 +186,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.\")
else()
if(RETURN_CODE AND NOT RETURN_CODE EQUAL 0)
if (${ALLOW_FAILURE})
message(WARNING \"Python installation of '${PKG_NAME}' failed.\")
else()
message(FATAL_ERROR \"Python installation of '${PKG_NAME}' failed.\")
endif()
endif()")
endforeach()
Expand Down
4 changes: 2 additions & 2 deletions core/examples/external_project/double_pendulum.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void internalDynamics(double t,
{
}

bool callback(double t, const Eigen::VectorXd & q, const Eigen::VectorXd & v)
bool callback()
{
return true;
}
Expand Down Expand Up @@ -97,7 +97,7 @@ int main(int argc, char * argv[])

// Run simulation
timer.tic();
engine.simulate(tf, q0, v0, std::nullopt, callback);
engine.simulate(tf, q0, v0, std::nullopt, false, callback);
std::cout << "Simulation: " << timer.toc<std::milli>() << "ms" << std::endl;

// Write the log file
Expand Down
6 changes: 5 additions & 1 deletion python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ buildPythonWheel("python/${LIBRARY_NAME}_py"
"${CMAKE_BINARY_DIR}/pypi/dist/${LIBRARY_NAME}_py")

# Install Python package jiminy_py
deployPythonPackage("${LIBRARY_NAME}_py[meshcat,plot,dev]")
if(DEFINED CMAKE_SUPPRESS_DEVELOPER_WARNINGS AND NOT CMAKE_SUPPRESS_DEVELOPER_WARNINGS)
deployPythonPackage("${LIBRARY_NAME}_py[meshcat,plot,dev]")
else()
deployPythonPackage("${LIBRARY_NAME}_py[meshcat,plot]")
endif()

################ gym_jiminy ################

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
Loading

0 comments on commit b69f69d

Please sign in to comment.