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

nanobind #537

Merged
merged 20 commits into from
Aug 28, 2023
Merged

nanobind #537

merged 20 commits into from
Aug 28, 2023

Conversation

pca006132
Copy link
Collaborator

Use nanobind instead of pybind11, which should support python ABI3 (with Python 3.12).

API changes: Python list is in general not accepted for int/float array arguments, users will need to use numpy (or tensorflow etc.) arrays, except for Vec3.

@Loosetooth what do you think about this? will this break your existing code?

@Loosetooth
Copy link
Contributor

My python is a bit rusty, haven't used it in years, so I can't immediately comment on the changes.
Also, I haven't used the python bindings at all, only the javascript / wasm bindings. Perhaps you wanted to tag someone else?

@pca006132
Copy link
Collaborator Author

Ahh sorry, I should tag @axel-angel

@codecov
Copy link

codecov bot commented Aug 25, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (1514c15) 91.50% compared to head (5f25d41) 91.50%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #537   +/-   ##
=======================================
  Coverage   91.50%   91.50%           
=======================================
  Files          35       35           
  Lines        4521     4521           
=======================================
  Hits         4137     4137           
  Misses        384      384           
Files Changed Coverage Δ
src/manifold/src/impl.cpp 96.44% <ø> (ø)
src/manifold/src/properties.cpp 83.66% <ø> (ø)
src/manifold/src/sort.cpp 90.58% <ø> (ø)
src/cross_section/src/cross_section.cpp 79.94% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Owner

@elalish elalish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great, especially since nanobind is reducing how much binding code we need to maintain. Considering we haven't made an official Python release yet, I'm not particularly concerned about potential breaking changes here, as long as it's easy for people to use.

if (manifolds.size() >= 1) {
// for some reason using Manifold() as the initial object
// will cause failure for python specifically
// unable to reproduce with c++ directly
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this was a pybind11 bug? Does it still repro?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh I did not check this

@@ -116,19 +153,18 @@ PYBIND11_MODULE(manifold3d, m) {
"Compute the convex hull enveloping a set of 3d points.")
.def(
"transform",
[](Manifold &self, py::array_t<float> &mat) {
auto mat_view = mat.unchecked<2>();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice that we can remove this - I take it nanobind doesn't do any checking by default?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it does check, the problem is that they only allows the use of ndarrays, e.g. numpy/tensorflow arrays, instead of doing explicit cast of python lists.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems pretty reasonable to me.

[](Manifold &self, py::array_t<float> &t) {
auto t_view = t.unchecked<1>();
if (t.ndim() != 1 || t.shape(0) != 3)
throw std::runtime_error("Invalid vector shape");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens now if the wrong shape array is input?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it will say that there is no appropriate function to call and print the type signature. (Vec3 requires a sequence with length 3, which is checked in the type caster I wrote above)

bindings/python/manifold3d.cpp Outdated Show resolved Hide resolved
@elalish
Copy link
Owner

elalish commented Aug 28, 2023

This looks like a good direction; should we go ahead and merge this?

@pca006132
Copy link
Collaborator Author

yeah I think we can use this instead of #521, but let me limit the python build wheel CI to tag/release first.

This reverts commit b3ede2a.
@elalish elalish mentioned this pull request Nov 3, 2023
cartesian-theatrics pushed a commit to SovereignShop/manifold that referenced this pull request Mar 11, 2024
* python stuff

* do not choose musllinux_1_2

* skip musl build

musllinux_1_1 is too old

* try musllinux_1_2

* pep-0632

* fix

* update

* fix CI

* skip emulated tests on mac

* use build frontend

* use scikit-build-core

* re-enable action

* minor changes

speed up compilation a bit

* use nanobind

* don't use SABIModule for older python versions

* fix build error

* fix find and replace error

* Revert "re-enable action"

This reverts commit b3ede2a.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants