[gym_jiminy/common] Add 'BodyObserver' to get orientation and angular velocity of IMUs' parent bodies. #2117
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: MacOS CI (Build from source dependencies) | |
on: | |
# Trigger the workflow on push on the master branch, or for any pull request | |
push: | |
branches: | |
- master | |
pull_request: | |
jobs: | |
build-and-test-osx: | |
name: >- | |
(${{ matrix.OS }}) (${{ matrix.PYTHON_VERSION }}) (${{ matrix.BUILD_TYPE }}) | |
Build and run the unit tests. Then generate and publish the wheels on PyPi. | |
strategy: | |
matrix: | |
OS: ['macos-15'] # 'macos-13': Intel (x86), 'macos-14+': Apple Silicon (arm64) | |
PYTHON_VERSION: ['3.10', '3.11', '3.12'] # `setup-python` does not support Python<3.10 on Apple Silicon | |
BUILD_TYPE: ['Release'] | |
include: | |
- OS: 'macos-13' | |
PYTHON_VERSION: '3.10' | |
BUILD_TYPE: 'Release' | |
- OS: 'macos-15' | |
PYTHON_VERSION: '3.12' | |
BUILD_TYPE: 'Debug' | |
LINKER_FLAGS: '-Wl,-ld_classic' # New "ld_prime" linker (XCode 15+) causes build failures | |
runs-on: ${{ matrix.OS }} | |
defaults: | |
run: | |
shell: bash -ieo pipefail {0} | |
env: | |
C_COMPILER: "/usr/bin/clang" | |
CXX_COMPILER: "/usr/bin/clang++" | |
CXX_FLAGS: "-DEIGEN_MPL2_ONLY -Wno-deprecated-declarations" | |
OSX_DEPLOYMENT_TARGET: "11.0" | |
OSX_ARCHITECTURES: "x86_64;arm64" | |
WHEEL_ARCH: "universal2" | |
##################################################################################### | |
steps: | |
- name: Checkout jiminy | |
uses: actions/checkout@v4 | |
##################################################################################### | |
- name: Configure Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.PYTHON_VERSION }} | |
- name: Setup minimal build environment | |
run: | | |
git config --global advice.detachedHead false | |
PYTHON_EXECUTABLE="${pythonLocation}/bin/python3" | |
echo "PYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}" >> $GITHUB_ENV | |
echo "RootDir=${GITHUB_WORKSPACE}" >> $GITHUB_ENV | |
echo "InstallDir=${GITHUB_WORKSPACE}/install" >> $GITHUB_ENV | |
# FIXME: Panda3d software rendering is partially broken on Apple Silicon | |
if [[ "${{ matrix.OS }}" != 'macos-13' ]] ; then | |
echo "JIMINY_PANDA3D_FORCE_TINYDISPLAY=" >> $GITHUB_ENV | |
fi | |
"${PYTHON_EXECUTABLE}" -m pip install setuptools wheel "pip>=20.3" | |
"${PYTHON_EXECUTABLE}" -m pip install delocate twine | |
- name: Install pre-compiled binaries for additional gym-jiminy dependencies | |
if: matrix.PYTHON_VERSION != '3.13' | |
run: | | |
"${PYTHON_EXECUTABLE}" -m pip install "torch" -f https://download.pytorch.org/whl/torch | |
"${PYTHON_EXECUTABLE}" -m pip install "gymnasium>=0.28,<1.0" "stable_baselines3>=2.0,<2.4" | |
- name: Install latest numpy version at build-time for run-time binary compatibility | |
run: | | |
if [[ "${{ matrix.BUILD_TYPE }}" != 'Debug' && "${{ matrix.OS }}" != 'macos-13' ]] ; then | |
"${PYTHON_EXECUTABLE}" -m pip install --upgrade "numpy>=1.24" numba torch | |
else | |
# FIXME: torch on MacOS x86 for Python 3.10 does not support Numpy 2.X | |
# but does not enforce such restriction in requirements. | |
"${PYTHON_EXECUTABLE}" -m pip install --upgrade "numpy>=1.24,<2.0" numba torch | |
fi | |
- name: Build jiminy dependencies | |
run: | | |
OSX_DEPLOYMENT_TARGET=${OSX_DEPLOYMENT_TARGET} OSX_ARCHITECTURES=${OSX_ARCHITECTURES} \ | |
LINKER_FLAGS="${{ matrix.LINKER_FLAGS }}" BUILD_TYPE="${{ matrix.BUILD_TYPE }}" \ | |
./build_tools/build_install_deps_unix.sh | |
##################################################################################### | |
- name: Build and install Jiminy | |
run: | | |
unset Boost_ROOT | |
# Build jiminy | |
mkdir "${RootDir}/build" | |
cd "${RootDir}/build" | |
export LD_LIBRARY_PATH="${InstallDir}/lib/:/usr/local/lib" | |
cmake "${RootDir}" -Wdev \ | |
-DCMAKE_EXE_LINKER_FLAGS="${{ matrix.LINKER_FLAGS }}" \ | |
-DCMAKE_SHARED_LINKER_FLAGS="${{ matrix.LINKER_FLAGS }}" \ | |
-DCMAKE_INSTALL_PREFIX="${InstallDir}" -DCMAKE_PREFIX_PATH="${InstallDir}" \ | |
-DCMAKE_C_COMPILER="${C_COMPILER}" -DCMAKE_CXX_COMPILER="${CXX_COMPILER}" \ | |
-DCMAKE_OSX_ARCHITECTURES="${OSX_ARCHITECTURES}" \ | |
-DCMAKE_OSX_DEPLOYMENT_TARGET="${OSX_DEPLOYMENT_TARGET}" \ | |
-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON \ | |
-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}" \ | |
-DBUILD_TESTING=ON -DBUILD_EXAMPLES=ON -DBUILD_PYTHON_INTERFACE=ON \ | |
-DINSTALL_GYM_JIMINY=${{ (matrix.PYTHON_VERSION == '3.13' && 'OFF') || 'ON' }} \ | |
-DCMAKE_CXX_FLAGS="${CXX_FLAGS}" -DCMAKE_BUILD_TYPE="${{ matrix.BUILD_TYPE }}" | |
make -j4 | |
# Bundle the boost python dependencies with jiminy | |
mkdir -p "${RootDir}/build/pypi/jiminy_py/src/jiminy_py" | |
cp -R -H "${InstallDir}/lib/python${{ matrix.PYTHON_VERSION }}/site-packages/." \ | |
"${RootDir}/build/pypi/jiminy_py/src/jiminy_py/core" | |
# Install jiminy along with its dependencies | |
make install | |
# Strip all symbol table and relocation information from python bindings and shared libraries | |
find "${RootDir}/build/pypi/" -name "*.so" -print -exec strip -x {} + | |
find "${InstallDir}/lib" -name "*.dylib" -maxdepth 1 -print -exec strip -x {} + | |
##################################################################################### | |
- name: Generate and install Python Pip wheels | |
run: | | |
export LD_LIBRARY_PATH="${InstallDir}/lib:${DYLD_LIBRARY_PATH}" | |
export DYLD_FALLBACK_LIBRARY_PATH="${LD_LIBRARY_PATH}" | |
# Generate stubs | |
if [[ "${{ matrix.BUILD_TYPE }}" != 'Debug' && "${{ matrix.OS }}" != 'macos-13' ]] ; then | |
# FIXME: stubgen does not work with Numpy 2.X | |
# (see https://github.com/python/mypy/issues/17396) | |
"${PYTHON_EXECUTABLE}" -m pip install "numpy<2.0" | |
stubgen -p jiminy_py -o ${RootDir}/build/pypi/jiminy_py/src | |
# FIXME: Python 3.10 crashes when generating stubs without any backtrace... | |
if [[ "${{ matrix.PYTHON_VERSION }}" != '3.10' ]] ; then | |
# lldb --batch -o "settings set target.process.stop-on-exec false" \ | |
# -o "break set -n main" -o "run" -k "bt" -k "quit" -- \ | |
"${PYTHON_EXECUTABLE}" "${RootDir}/build_tools/stubgen.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 | |
fi | |
"${PYTHON_EXECUTABLE}" -m pip install --upgrade "numpy>=1.24" numba torch | |
fi | |
# Generate wheels | |
cd "${RootDir}/build" | |
cmake . -DCOMPONENT=pypi -P ./cmake_install.cmake | |
# Bundle non-standard dependencies with the wheels | |
delocate-wheel -vvv --require-archs "${WHEEL_ARCH}" \ | |
-w "${RootDir}/build/wheelhouse" "${RootDir}/build/pypi/dist/jiminy_py/"*.whl | |
"${PYTHON_EXECUTABLE}" "${RootDir}/build_tools/wheel_addplat_macos.py" -vvv --rm-orig --clobber \ | |
-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 != 'Debug' && matrix.OS != 'macos-13' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: wheelhouse-${{ matrix.PYTHON_VERSION }} | |
path: build/wheelhouse | |
##################################################################################### | |
- name: Build extension module | |
run: | | |
export DYLD_FALLBACK_LIBRARY_PATH="${InstallDir}/lib" | |
"${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_EXE_LINKER_FLAGS="${{ matrix.LINKER_FLAGS }}" \ | |
-DCMAKE_SHARED_LINKER_FLAGS="${{ matrix.LINKER_FLAGS }}" \ | |
-DCMAKE_C_COMPILER="${C_COMPILER}" -DCMAKE_CXX_COMPILER="${CXX_COMPILER}" \ | |
-DCMAKE_INSTALL_PREFIX="${InstallDir}" -DCMAKE_PREFIX_PATH="${InstallDir}" \ | |
-DPYTHON_EXECUTABLE="${PYTHON_EXECUTABLE}" \ | |
-DCMAKE_CXX_FLAGS="${CXX_FLAGS}" -DCMAKE_BUILD_TYPE="${{ matrix.BUILD_TYPE }}" | |
make install | |
"${InstallDir}/bin/pip_double_pendulum" | |
##################################################################################### | |
- name: Run unit tests for jiminy | |
run: | | |
export DYLD_FALLBACK_LIBRARY_PATH="${InstallDir}/lib" | |
ctest --output-on-failure --test-dir "${RootDir}/build/core/unit" | |
cd "${RootDir}/python/jiminy_py/unit_py" | |
"${PYTHON_EXECUTABLE}" -m unittest discover -v | |
- name: Run unit tests for gym jiminy base module | |
run: | | |
export LD_LIBRARY_PATH="${InstallDir}/lib/:/usr/local/lib" | |
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 examples for gym jiminy add-on modules | |
if: matrix.BUILD_TYPE != 'Debug' | |
run: | | |
export LD_LIBRARY_PATH="${InstallDir}/lib/:/usr/local/lib" | |
cd "${RootDir}/python/gym_jiminy/examples/rllib" | |
"${PYTHON_EXECUTABLE}" acrobot_ppo.py | |
######################################################################################### | |
publish-pypi-macos: | |
name: (MacOS CI) Publish on PyPi the wheel for OS X of jiminy_py | |
runs-on: ubuntu-24.04 | |
permissions: | |
id-token: write | |
needs: build-and-test-osx | |
if: github.repository == 'duburcqa/jiminy' && github.event_name == 'push' && github.ref == 'refs/heads/master' | |
steps: | |
- name: Download the wheel previously generated | |
uses: actions/download-artifact@v4 | |
with: | |
pattern: wheelhouse-* | |
merge-multiple: true | |
path: wheelhouse | |
- name: Publish the wheel | |
uses: pypa/gh-action-pypi-publish@v1.10.3 | |
with: | |
packages-dir: wheelhouse | |
verify-metadata: false |