Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move from Pybind11 to nanobind #345

Merged
merged 44 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
f004de9
[python/external] swap out pybind11 for nanobind
ManifoldFR Aug 5, 2024
d28e4eb
[bindings/python] update CMake listfile, targets and instruction-set.…
ManifoldFR Aug 5, 2024
7168637
[bindings/python] instruction-set.cpp : fix crashes because of lack o…
ManifoldFR Aug 5, 2024
14ab3a3
[proxqp/sparse] explicitly delete copy ctor and operator, fixing conf…
ManifoldFR Aug 5, 2024
a0a97fa
[bindings/python] expose-all.cpp : do pybind11 -> nanobind swap
ManifoldFR Aug 5, 2024
86863f2
[bindings/python] expose-workspace.hpp : do pybind11 -> nanobind swap
ManifoldFR Aug 5, 2024
82d372f
[bindings/python] helpers.hpp : do pybind11 -> nanobind swap
ManifoldFR Aug 5, 2024
887b5c3
[bindings/python] expose-settings.hpp : do pybind11 -> nanobind swap
ManifoldFR Aug 5, 2024
ad7e215
[bindings/python] workspace, model : do pybind11 -> nanobind swap
ManifoldFR Aug 5, 2024
54040cd
[bindings/python] remove optional.hpp
ManifoldFR Aug 5, 2024
16a8825
[bindings/python] expose-solver.hpp : switch to nanobind
ManifoldFR Aug 5, 2024
97909b4
[bindings/python] expose-{backward,parallel,qpobject}.hpp : switch to…
ManifoldFR Aug 5, 2024
520afab
[bindings/python] expose-qpvector.hpp : upgrade to nanobind
ManifoldFR Aug 5, 2024
783d88f
[ci] checkout submodule recursive
fabinsch Aug 6, 2024
7de7adf
[bindings/python] cmake : add stub generation (basic)
ManifoldFR Aug 6, 2024
bc0e35a
Update CHANGELOG
ManifoldFR Aug 6, 2024
3ea4718
[test] dense_qp_solve.py : remove useless line
ManifoldFR Aug 6, 2024
a8256bf
[bindings/python] remove macro PROXSUITE_PYTHON_EIGEN_READWRITE
ManifoldFR Aug 6, 2024
aaeca09
[test] fix bare except
ManifoldFR Aug 6, 2024
54f42c6
[test] Fix serialization
ManifoldFR Aug 6, 2024
0297676
[test] Force C-order (row-major) for all matrices in the tests
ManifoldFR Aug 6, 2024
8dccf3b
[bindings/python] Fix overloaded dense.solve() signatures, switch nul…
ManifoldFR Aug 6, 2024
395933c
[test] reformat using black
ManifoldFR Aug 6, 2024
9008bf9
[workflows] also install typing_extensions package
ManifoldFR Aug 6, 2024
22fcd22
[examples/python] fix toarray() for C order
ManifoldFR Aug 7, 2024
603e208
[test] parallel_qp_solve : .toarray() to C order
ManifoldFR Aug 7, 2024
856e057
Update minimum Python to 3.8 (3.7 has been EOL for a year)
ManifoldFR Aug 7, 2024
4882f59
[test] cvxpy.py : ensure matrix and gradient are float64
ManifoldFR Aug 8, 2024
b810caf
[bindings/python] cmake : fix the bloody include dirs variable ??
ManifoldFR Aug 8, 2024
e7394b3
[examples/python] fix some more C orders
ManifoldFR Aug 8, 2024
f004f5d
cmake : alias some targets to Python::*
ManifoldFR Aug 9, 2024
05632d2
[workflows] remove macOS C++14
ManifoldFR Aug 9, 2024
2723872
[bindings/python] use nanobind::none() instead of nullopt
ManifoldFR Aug 9, 2024
94f13f1
[bindings] point nanobind to latest master
ManifoldFR Aug 20, 2024
6d167e8
Add fix for std::optional<Eigen::Ref<const T>>
ManifoldFR Aug 27, 2024
3d637fd
apparently i64/u64 and isize/size_t are not the same thing on the Win…
ManifoldFR Aug 27, 2024
3804bae
Change back URL of nanobind submodule
ManifoldFR Aug 27, 2024
bfc2bea
Allow use of installed nanobind
ManifoldFR Aug 27, 2024
0e4db0a
Update bindings/python/helpers/instruction-set.cpp
ManifoldFR Aug 27, 2024
449267f
Update bindings/python/src/expose-results.hpp
ManifoldFR Aug 27, 2024
d509b5e
Update bindings/python/src/expose-helpers.hpp
ManifoldFR Aug 27, 2024
519a624
[workflows] do not re-run linux, osx, win, arch CI and release CI whe…
ManifoldFR Aug 27, 2024
c7c2b2a
Set version of nanobind submodule to release v2.1.0
ManifoldFR Aug 30, 2024
d719663
Fix for nanobind v2.1.0 release
ManifoldFR Aug 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/ci-arch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ name: CI - ArchLinux
on:
push:
pull_request:
paths-ignore:
- CHANGELOG.md

jobs:
build-with-arch:
Expand All @@ -14,7 +16,7 @@ jobs:

- uses: actions/checkout@v4
with:
submodules: true
submodules: recursive

- run: cmake -B build -S . -DBUILD_PYTHON_INTERFACE=ON
- run: cmake --build build
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/ci-linux-osx-win-conda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ name: CI - Linux/OSX/Windows - Conda
on:
push:
pull_request:
paths-ignore:
- CHANGELOG.md

jobs:
build-with-conda:
Expand All @@ -29,10 +31,6 @@ jobs:
compiler: clang-cl
- name: windows-latest
os: windows-latest
- name: macos-latest
os: macos-latest
build_type: Release
cxx_std: 14
- name: macos-latest
fabinsch marked this conversation as resolved.
Show resolved Hide resolved
os: macos-latest
build_type: Debug
Expand All @@ -55,7 +53,9 @@ jobs:
continue_on_error: false

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
submodules: recursive

- uses: conda-incubator/setup-miniconda@v2
if: matrix.os != 'macos-14'
Expand All @@ -80,7 +80,7 @@ jobs:
# Workaround for https://github.com/conda-incubator/setup-miniconda/issues/186
conda config --remove channels defaults
# Compilation related dependencies
mamba install cmake compilers make pkg-config doxygen ninja graphviz
mamba install cmake compilers make pkg-config doxygen ninja graphviz typing_extensions
# Main dependencies
mamba install eigen simde
# Test dependencies
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/ci-linux-ros.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
name: CI - Linux - ROS
on: [push, pull_request]
on:
push:
pull_request:
paths-ignore:
- CHANGELOG.md

jobs:
CI:
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
submodules: recursive

- uses: conda-incubator/setup-miniconda@v2
with:
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/release-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ name: Release on PyPI [Linux]

on:
pull_request:
paths-ignore:
- CHANGELOG.md
release:
types:
- published
Expand Down Expand Up @@ -33,9 +35,9 @@ jobs:
build: "cp312-manylinux*"

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: 'true'
submodules: recursive
- uses: actions/setup-python@v4
with:
python-version: "3.10"
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/release-osx-win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ name: Release on PyPI [Windows, Mac]

on:
pull_request:
paths-ignore:
- CHANGELOG.md
release:
types:
- published
Expand All @@ -21,7 +23,7 @@ jobs:
toolset: v143

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
submodules: recursive

Expand Down Expand Up @@ -57,7 +59,7 @@ jobs:
run: |
# Workaround for https://github.com/conda-incubator/setup-miniconda/issues/186
conda config --remove channels defaults
mamba install doxygen graphviz eigen simde cmake compilers
mamba install doxygen graphviz eigen simde cmake compilers typing_extensions

- name: Print environment [Conda]
if: contains(matrix.os, 'macos') || contains(matrix.os, 'windows')
Expand Down
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[submodule "external/pybind11"]
path = bindings/python/external/pybind11
url = https://github.com/pybind/pybind11
[submodule "bindings/python/external/nanobind"]
path = bindings/python/external/nanobind
url = https://github.com/wjakob/nanobind
[submodule "cmake-module"]
path = cmake-module
url = https://github.com/jrl-umi3218/jrl-cmakemodules.git
Expand Down
14 changes: 11 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,23 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [Unreleased]

### Added

* Stub files for Python bindings, using [nanobind's native support](https://nanobind.readthedocs.io/en/latest/typing.html#stub-generation) ([#340](https://github.com/Simple-Robotics/proxsuite/pull/340))

### Changed

* Change Python bindings to use nanobind instead of pybind11 ([#340](https://github.com/Simple-Robotics/proxsuite/pull/340))

## [0.6.7] - 2024-08-27

### Added
* Fix mu update function for PrimalLDLT backend ([#349](https://github.com/Simple-Robotics/proxsuite/pull/349))
* Allow use of installed pybind11, cereal and jrl-cmakemodules via cmake
* Add compatibility with jrl-cmakemodules workspace ([#339](https://github.com/Simple-Robotics/proxsuite/pull/339))
* Specifically mention that timings are in microseconds ([#340](https://github.com/Simple-Robotics/proxsuite/pull/340))
* Fix cereal include directory in cmake ([#340](https://github.com/Simple-Robotics/proxsuite/pull/340))
* Extend doc with hint for conda installation from source ([#340](https://github.com/Simple-Robotics/proxsuite/pull/340))
* Specifically mention that timings are in microseconds ([#342](https://github.com/Simple-Robotics/proxsuite/pull/342))
* Fix cereal include directory in cmake ([#342](https://github.com/Simple-Robotics/proxsuite/pull/342))
* Extend doc with hint for conda installation from source ([#342](https://github.com/Simple-Robotics/proxsuite/pull/342))

### Fixed
* Fix inequality constraints return in QPLayer ([#343](https://github.com/Simple-Robotics/proxsuite/pull/343))
Expand Down
73 changes: 57 additions & 16 deletions bindings/python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
if(UNIX)
set(PYTHON_COMPONENTS Development.Module)
set(PYTHON_COMPONENTS Interpreter Development.Module)
endif()

include(${JRL_CMAKE_MODULES}/python.cmake)
include(${JRL_CMAKE_MODULES}/python-helpers.cmake)

findpython(REQUIRED Development.Module)
option(GENERATE_PYTHON_STUBS "Generate Python stubs" OFF)

findpython(REQUIRED)
set(Python_INCLUDE_DIRS ${Python3_INCLUDE_DIRS})
# Nanobind expects these targets instead of Python3::*
# https://github.com/jrl-umi3218/jrl-cmakemodules/issues/708
add_library(Python::Module ALIAS Python3::Module)
add_executable(Python::Interpreter ALIAS Python3::Interpreter)

if(IS_ABSOLUTE ${PYTHON_SITELIB})
set(${PYWRAP}_INSTALL_DIR ${PYTHON_SITELIB}/${PROJECT_NAME})
Expand All @@ -14,11 +21,21 @@ else()
${CMAKE_INSTALL_PREFIX}/${PYTHON_SITELIB}/${PROJECT_NAME})
endif()

find_package(pybind11 CONFIG)
if(NOT pybind11_FOUND)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/external/pybind11)
add_subdirectory(external/pybind11
${CMAKE_CURRENT_BINARY_DIR}/external/pybind11)
cmake_policy(PUSH)
cmake_policy(SET CMP0074 NEW)
# Detect the installed nanobind package and import it into CMake
execute_process(
COMMAND "${Python_EXECUTABLE}" -m nanobind --cmake_dir
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE nanobind_ROOT)
find_package(nanobind CONFIG)
cmake_policy(POP)
if(NOT nanobind_FOUND)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/external/nanobind)
add_subdirectory(external/nanobind
${CMAKE_CURRENT_BINARY_DIR}/external/nanobind)
else()
message(STATUS "Found installed nanobind.")
endif()

add_custom_target(${PROJECT_NAME}_python)
Expand All @@ -29,14 +46,12 @@ file(GLOB_RECURSE PYWRAP_SOURCES ${CMAKE_CURRENT_LIST_DIR}/src/*.cpp)

# Add simd feature detectors for current intel CPU
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "(x86)|(X86)|(amd64)|(AMD64)")
python3_add_library(instructionset MODULE helpers/instruction-set.cpp)
nanobind_add_module(instructionset helpers/instruction-set.cpp)
add_dependencies(${PROJECT_NAME}_python instructionset)
target_link_libraries(instructionset PRIVATE proxsuite pybind11::module)
target_link_libraries(instructionset PRIVATE proxsuite)
set_target_properties(
instructionset
PROPERTIES OUTPUT_NAME instructionset
PREFIX ""
SUFFIX ${PYTHON_EXT_SUFFIX}
LIBRARY_OUTPUT_DIRECTORY
"${PROJECT_BINARY_DIR}/bindings/python/${PROJECT_NAME}"
LIBRARY_OUTPUT_DIRECTORY_RELEASE
Expand All @@ -58,6 +73,20 @@ if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "(x86)|(X86)|(amd64)|(AMD64)")
TARGETS instructionset
EXPORT ${TARGETS_EXPORT_NAME}
DESTINATION ${${PYWRAP}_INSTALL_DIR})
if(GENERATE_PYTHON_STUBS)
nanobind_add_stub(
instructionset_stub
MODULE
instructionset
OUTPUT
instructionset.pyi
PYTHON_PATH
$<TARGET_FILE_DIR:instructionset>
DEPENDS
instructionset)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/instructionset.pyi
DESTINATION ${${PYWRAP}_INSTALL_DIR})
endif()
endif()

function(list_filter list regular_expression dest_list)
Expand All @@ -72,12 +101,12 @@ function(list_filter list regular_expression dest_list)
endfunction(list_filter)

function(CREATE_PYTHON_TARGET target_name COMPILE_OPTIONS dependencies)
python3_add_library(${target_name} MODULE ${PYWRAP_SOURCES} ${PYWRAP_HEADERS})
nanobind_add_module(${target_name} ${PYWRAP_SOURCES} ${PYWRAP_HEADERS})
add_dependencies(${PROJECT_NAME}_python ${target_name})

target_link_libraries(${target_name} PUBLIC ${dependencies} pybind11::module)
target_link_libraries(${target_name} PUBLIC ${dependencies})
target_compile_options(${target_name} PRIVATE ${COMPILE_OPTIONS})
target_link_libraries(${target_name} PRIVATE proxsuite pybind11::module)
target_link_libraries(${target_name} PRIVATE proxsuite)
target_compile_definitions(${target_name}
PRIVATE PYTHON_MODULE_NAME=${target_name})

Expand All @@ -104,8 +133,6 @@ function(CREATE_PYTHON_TARGET target_name COMPILE_OPTIONS dependencies)
set_target_properties(
${target_name}
PROPERTIES OUTPUT_NAME ${target_name}
PREFIX ""
SUFFIX ${PYTHON_EXT_SUFFIX}
LIBRARY_OUTPUT_DIRECTORY
"${PROJECT_BINARY_DIR}/bindings/python/${PROJECT_NAME}"
LIBRARY_OUTPUT_DIRECTORY_RELEASE
Expand All @@ -126,6 +153,20 @@ function(CREATE_PYTHON_TARGET target_name COMPILE_OPTIONS dependencies)
endif()

install(TARGETS ${target_name} DESTINATION ${${PYWRAP}_INSTALL_DIR})
if(GENERATE_PYTHON_STUBS)
nanobind_add_stub(
${target_name}_stub
MODULE
${target_name}
OUTPUT
${target_name}.pyi
PYTHON_PATH
$<TARGET_FILE_DIR:${target_name}>
DEPENDS
${target_name})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${target_name}.pyi
DESTINATION ${${PYWRAP}_INSTALL_DIR})
endif()
endfunction()

if(CMAKE_CXX_COMPILER_ID MATCHES MSVC)
Expand Down
1 change: 1 addition & 0 deletions bindings/python/external/nanobind
Submodule nanobind added at 8a65e0
1 change: 0 additions & 1 deletion bindings/python/external/pybind11
Submodule pybind11 deleted from 849322
7 changes: 4 additions & 3 deletions bindings/python/helpers/instruction-set.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
//
// Copyright (c) 2022 INRIA
// Copyright (c) 2022-2024 INRIA
//

#include <pybind11/pybind11.h>
#include <nanobind/nanobind.h>
#include <nanobind/stl/string.h>

#include <proxsuite/helpers/instruction-set.hpp>

namespace proxsuite {
namespace helpers {
namespace python {

PYBIND11_MODULE(instructionset, m)
NB_MODULE(instructionset, m)
{
m.doc() = R"pbdoc(
CPU info library
Expand Down
Loading
Loading