Upgrade Pinocchio Python bindings to nanobind#2873
Draft
ManifoldFR wants to merge 204 commits intostack-of-tasks:develfrom
Draft
Upgrade Pinocchio Python bindings to nanobind#2873ManifoldFR wants to merge 204 commits intostack-of-tasks:develfrom
ManifoldFR wants to merge 204 commits intostack-of-tasks:develfrom
Conversation
6 tasks
d72f4ea to
99a76bd
Compare
bindings : add __bindings_framework__ variable to check bindings framework
add some typedefs
unittest/python/rpy : test for TypeError, for nanobind. unittest/python/rpy : import the correct AngleAxis examples/rpy : fix yet another permissive numpy shape error
…ing (if it already exists)
…ay module attributes - just define them in the __init__ :)
…ef) for output args - permissive for both C and F order numpy.ndarray
…st() here - doesn't exist for nanobind bindings
- nanobind is less permissive
99a76bd to
77b98c2
Compare
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This pull request adds a new set of Python bindings using the modern nanobind Python bindings framework.
The new set of bindings is a full replacement of the Boost.Python bindings, which will be deprecated in the next major version of Pinocchio.
This PR is the sequel to coal-library/coal#659 on the Coal library, and actually depends on the Coal nanobind bindings as well as nanoeigenpy.
Checklist
pre-commit run --all-filesorpixi run lintTask checklist
Math
Spatial
Multibody
JointModel/JointDataclass ModelPool...)Algorithm
computeAllTerms())updateGeometryPlacements()...)appendModel(),buildReducedModel(),findCommonAncestor(),transformJointIntoMimic())updateFramePlacement,framesForwardKinematics...)OpenMPExceptionexception OPTIONALomp_get_max_threads())Collision
expose-collision.cppin old bindings -class ComputeCollision, functionscomputeCollision[s]()...)GeometryModel/GeometryDatapoolParsers
Constraints
BinaryKinematicsConstraint{Model,Data}Base,PointConstraint{Model,Data}Base)Utilities
boost::variant(done inpinocchio/bindings/python-nb/utils/boost-variant.hpp)pinocchio/spatial) to numpy arrays using__array__()method, allowsCustom call policy to disallow the use of
JointMimic. nanobind has call policies.Serialization (pretty much everything missing)
Add Pixi feature and environment
Stubs (working)
Known limitations
doublescalar type (perhaps float).boost::python::convert::implicitstruct, which allows to define custom implicit converters between types. There are two avenues for creating implicit converters in nanobind:nb::implicitly_convertible/usenb::init_implicit},This allows defining the
coal.Transform3s->pinocchio::SE3conversion by registering an extra ctor, but the reverse is not possible.Other modified
pinocchio/visualize/meshcat_visualize.py- remove import ofDeprecatedWarning, replaced by Python built-inDeprecationWarningOther removed
pinocchio/deprecation.py- only used inmeshcat_visualizer.pythrough theDeprecatedWarningpinocchio/bindings/python/multibody/joint/joint.hppUpstream changes
Eigen::Tensorto nanobind 😄shared_ptr<>for BVH classes coal-library/coal#833 - Fix problems accessinggeometry.convexon some Coal BVH typesNotes
std::optionalwhereas we useboost::optionalelsewhere (for the bindings mostly):boost::optional:std::optional, and use it everywhere instead ofboost::optionalstd::string_viewwhere appropriate__repr__method nanobind implements when usingnb::bind_vectorto bind STL vectors uses the elements'__repr__, so a vector ofpinocchio.Modelhas a VERY long representation.__repr__from__str__on some classes.OpenMPExceptionexception in nanobind, inheriting from the mainline Python Exception class using:nb::type<OpenMPException>(m, "OpenMPException", PyExc_Exception);::what()__array__was factored into a new visitor (ToNumpyArrayVisitor). Properly supports copies and kwargs now.(n,1)NumPy arrays to Eigen types: it's not allowed, which means code as follows:Resolves #2616