Skip to content

Nanobind transition#24749

Open
rpoyner-tri wants to merge 465 commits into
RobotLocomotion:masterfrom
rpoyner-tri:nanobind-transition
Open

Nanobind transition#24749
rpoyner-tri wants to merge 465 commits into
RobotLocomotion:masterfrom
rpoyner-tri:nanobind-transition

Conversation

@rpoyner-tri

@rpoyner-tri rpoyner-tri commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

This is a review refresh from work done in #24513 towards #21572.


This change is Reviewable

@rpoyner-tri rpoyner-tri left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@rpoyner-tri partially reviewed 1 file.
Reviewable status: 15 unresolved discussions, LGTM missing from assignee jwnimmer-tri(platform), needs at least two assigned reviewers, labeled "do not merge", commits need curation (https://drake.mit.edu/reviewable.html#curated-commits), missing label for release notes (waiting on jwnimmer-tri).

@rpoyner-tri rpoyner-tri left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@rpoyner-tri reviewed all commit messages.
Reviewable status: 15 unresolved discussions, LGTM missing from assignee jwnimmer-tri(platform), needs at least two assigned reviewers, labeled "do not merge", commits need curation (https://drake.mit.edu/reviewable.html#curated-commits), missing label for release notes (waiting on jwnimmer-tri).

@jwnimmer-tri jwnimmer-tri left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@jwnimmer-tri reviewed 30 files and all commit messages, made 11 comments, and resolved 6 discussions.
Reviewable status: 10 unresolved discussions, LGTM missing from assignee jwnimmer-tri(platform), needs at least two assigned reviewers, labeled "do not merge", commits need curation (https://drake.mit.edu/reviewable.html#curated-commits), missing label for release notes (waiting on rpoyner-tri).


bindings/pydrake/geometry/geometry_py_render.cc line 138 at r7 (raw file):

This code has no tests.

Correction: has no tests of omitting the method in the Python subclass.

In-progress now at #24763.


bindings/pydrake/geometry/geometry_py_render.cc line 142 at r7 (raw file):

Previously, jwnimmer-tri (Jeremy Nimmer) wrote…

Working

This code has no tests.

Done. Removed in #24762.


bindings/pydrake/multibody/tree_py.cc line 1287 at r7 (raw file):

Previously, jwnimmer-tri (Jeremy Nimmer) wrote…

Working

This override (and the one below) are not covered by any unit tests. It was missed in #23255.

Even if I amend the current unit test to call plant.mutable_deformable_model().AddExternalForce(dut), the override is not ever called (even on the C++ side).

In-progress now at #24764.


bindings/pydrake/systems/analysis_py.cc line 298 at r7 (raw file):

Previously, jwnimmer-tri (Jeremy Nimmer) wrote…

Working

Cherry-picked in #24751.

Done.


bindings/pydrake/systems/framework_py_systems.cc line 340 at r7 (raw file):

This code has no tests.

Correction: has no tests of omitting the method in the Python subclass.

(The new test actually passes on this branch already, because for this particular NVI method, we bind the Do... method to be callable by Python. Its implementation is not a stub -- the derived class is always supposed to call the base class.)

In-progress now at #24763.


bindings/pydrake/systems/framework_py_systems.cc line 365 at r7 (raw file):

This code has no tests.

Correction: has no tests of omitting the method in the Python subclass.

(The new test actually passes on this branch already, because for this particular NVI method, we bind the Do... method to be callable by Python. Its implementation is not a stub -- the derived class is always supposed to call the base class.)

In-progress now at #24763.


bindings/pydrake/multibody/inverse_kinematics_py_differential.cc line 338 at r7 (raw file):

Previously, jwnimmer-tri (Jeremy Nimmer) wrote…

Working

Cherry-picked in #24751.

Done.


bindings/pydrake/multibody/plant_py.cc line 1694 at r7 (raw file):

Previously, jwnimmer-tri (Jeremy Nimmer) wrote…

Working

Cherry-picked in #24757.

Done


solvers/solver_options.cc line 65 at r1 (raw file):

Previously, jwnimmer-tri (Jeremy Nimmer) wrote…

Working

Cherry-picked in #24750.

Done.


systems/analysis/simulator.h line 277 at r1 (raw file):

Previously, jwnimmer-tri (Jeremy Nimmer) wrote…

Working

Cherry-picked in #24751.

Done.


a discussion (no related file):
Working

We need to do something about DRAKE_PYBIND11_CHECK_SIGNATURE_INFECTION. Probably just marking a TODO and circling back later.

@rpoyner-tri rpoyner-tri left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@rpoyner-tri made 1 comment.
Reviewable status: 10 unresolved discussions, LGTM missing from assignee jwnimmer-tri(platform), needs at least two assigned reviewers, labeled "do not merge", commits need curation (https://drake.mit.edu/reviewable.html#curated-commits), missing label for release notes (waiting on jwnimmer-tri).


a discussion (no related file):

Previously, rpoyner-tri (Rick Poyner (rico)) wrote…

I'm having a hard time linking the failures back to change of compiler. Nanobind makes some interesting choices for type maps. There is a "fast map" which is just doing some standard arithmetic hash on void pointer values. I could see that failing if we have ODR violations for type type_info. Then there is a "slow map" which actually extracts the string name of the type and computes std::hash<std::string_view>. Seems to me that the slow map should pretty much always work. And yet...

Aside: is there a reason to implement a full run-time string hash, and not rely on std::type_index or std::type_info::hash_code? Maybe MSVC is broken?

So, the unalias map mechanism in pydrake_pybind.h is not "the" under clang; the singleton implementation is failing and we get map-per-TU. This causes the bound_type lookup in the module_py.cc nice type override to be useless, etc., etc. I can think of fixes, but not sure what spellings are permissible. Let me get something working at all and then we can tweak it.

@jwnimmer-tri jwnimmer-tri left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@jwnimmer-tri made 1 comment.
Reviewable status: 10 unresolved discussions, LGTM missing from assignee jwnimmer-tri(platform), needs at least two assigned reviewers, labeled "do not merge", commits need curation (https://drake.mit.edu/reviewable.html#curated-commits), missing label for release notes (waiting on rpoyner-tri).


a discussion (no related file):

Previously, rpoyner-tri (Rick Poyner (rico)) wrote…

So, the unalias map mechanism in pydrake_pybind.h is not "the" under clang; the singleton implementation is failing and we get map-per-TU. This causes the bound_type lookup in the module_py.cc nice type override to be useless, etc., etc. I can think of fixes, but not sure what spellings are permissible. Let me get something working at all and then we can tweak it.

Ah, yeah, the ODR of that class was on my list of cleanups for common before we could land it. I was thinking to try to put its single definition in common/module_py.cc but I'm not sure the other modules would be able to resolve against that. We might need to put its storage into libdrake somehow (perhaps with type erasure), perhaps near the nice_type_name seam.

@rpoyner-tri rpoyner-tri left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@rpoyner-tri made 1 comment.
Reviewable status: 10 unresolved discussions, LGTM missing from assignee jwnimmer-tri(platform), needs at least two assigned reviewers, labeled "do not merge", commits need curation (https://drake.mit.edu/reviewable.html#curated-commits), missing label for release notes (waiting on jwnimmer-tri).


a discussion (no related file):

Previously, jwnimmer-tri (Jeremy Nimmer) wrote…

Ah, yeah, the ODR of that class was on my list of cleanups for common before we could land it. I was thinking to try to put its single definition in common/module_py.cc but I'm not sure the other modules would be able to resolve against that. We might need to put its storage into libdrake somehow (perhaps with type erasure), perhaps near the nice_type_name seam.

Still investigating. I'm tempted to steal an idea from cpp_param and store a global pointer in Python, perhaps via PyCapsule.

@jwnimmer-tri jwnimmer-tri left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@jwnimmer-tri reviewed 5 files and all commit messages, and made 1 comment.
Reviewable status: 10 unresolved discussions, LGTM missing from assignee jwnimmer-tri(platform), needs at least two assigned reviewers, labeled "do not merge", commits need curation (https://drake.mit.edu/reviewable.html#curated-commits), missing label for release notes (waiting on rpoyner-tri).


a discussion (no related file):

Previously, rpoyner-tri (Rick Poyner (rico)) wrote…

Still investigating. I'm tempted to steal an idea from cpp_param and store a global pointer in Python, perhaps via PyCapsule.

Sounds plausible!

@rpoyner-tri rpoyner-tri left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@rpoyner-tri made 1 comment and resolved 1 discussion.
Reviewable status: 9 unresolved discussions, LGTM missing from assignee jwnimmer-tri(platform), needs at least two assigned reviewers, labeled "do not merge", commits need curation (https://drake.mit.edu/reviewable.html#curated-commits), missing label for release notes (waiting on jwnimmer-tri).


a discussion (no related file):

Previously, jwnimmer-tri (Jeremy Nimmer) wrote…

Sounds plausible!

Pushed. WorksOnMyMachine(tm)!

@jwnimmer-tri

Copy link
Copy Markdown
Collaborator

Time for the YOLO test!

---------- Provisioned ----------
@drake-jenkins-bot linux-noble-clang-bazel-experimental-address-sanitizer please
@drake-jenkins-bot linux-noble-clang-bazel-experimental-coverage please
@drake-jenkins-bot linux-noble-clang-bazel-experimental-debug please
@drake-jenkins-bot linux-noble-clang-bazel-experimental-everything-address-sanitizer please
@drake-jenkins-bot linux-noble-clang-bazel-experimental-everything-debug please
@drake-jenkins-bot linux-noble-clang-bazel-experimental-everything-leak-sanitizer please
@drake-jenkins-bot linux-noble-clang-bazel-experimental-everything-thread-sanitizer please
@drake-jenkins-bot linux-noble-clang-bazel-experimental-everything-undefined-behavior-sanitizer please
@drake-jenkins-bot linux-noble-clang-bazel-experimental-everything-valgrind-memcheck please
@drake-jenkins-bot linux-noble-clang-bazel-experimental-thread-sanitizer please
@drake-jenkins-bot linux-noble-clang-bazel-experimental-undefined-behavior-sanitizer please
@drake-jenkins-bot linux-noble-clang-bazel-experimental-valgrind-memcheck please
@drake-jenkins-bot linux-noble-experimental-cache-server-health-check please
@drake-jenkins-bot linux-noble-gcc-bazel-experimental-coverage please
@drake-jenkins-bot linux-noble-gcc-bazel-experimental-everything-debug please
@drake-jenkins-bot linux-noble-gcc-cmake-experimental-debug please
@drake-jenkins-bot linux-noble-gcc-cmake-experimental-everything-debug please
@drake-jenkins-bot linux-noble-gcc-cmake-experimental-everything-release please
@drake-jenkins-bot linux-resolute-clang-bazel-experimental-everything-release please
@drake-jenkins-bot linux-resolute-gcc-bazel-experimental-everything-debug please
@drake-jenkins-bot linux-resolute-gcc-cmake-experimental-everything-release please
@drake-jenkins-bot mac-arm-sequoia-clang-bazel-experimental-everything-release please
@drake-jenkins-bot mac-arm-sequoia-clang-cmake-experimental-everything-release please
@drake-jenkins-bot mac-arm-sequoia-clang-cmake-experimental-packaging please
@drake-jenkins-bot mac-arm-sequoia-clang-cmake-experimental-release please
@drake-jenkins-bot mac-arm-sequoia-clang-wheel-experimental-release please
@drake-jenkins-bot mac-arm-tahoe-clang-bazel-experimental-everything-release please
@drake-jenkins-bot mac-arm-tahoe-clang-bazel-experimental-release please
@drake-jenkins-bot mac-arm-tahoe-clang-cmake-experimental-everything-release please
@drake-jenkins-bot mac-arm-tahoe-clang-cmake-experimental-release please

---------- Unprovisioned ----------
@drake-jenkins-bot linux-amd64v1-resolute-unprovisioned-gcc-bazel-experimental-everything-release please
@drake-jenkins-bot linux-amd64v1-resolute-unprovisioned-gcc-bazel-experimental-release please
@drake-jenkins-bot linux-amd64v1-resolute-unprovisioned-gcc-cmake-experimental-packaging please
@drake-jenkins-bot linux-arm64-noble-unprovisioned-gcc-bazel-experimental-everything-release please
@drake-jenkins-bot linux-arm64-noble-unprovisioned-gcc-bazel-experimental-release please
@drake-jenkins-bot linux-arm64-noble-unprovisioned-gcc-cmake-experimental-packaging please
@drake-jenkins-bot linux-arm64-noble-unprovisioned-gcc-wheel-experimental-release please
@drake-jenkins-bot linux-arm64-resolute-unprovisioned-gcc-bazel-experimental-everything-release please
@drake-jenkins-bot linux-arm64-resolute-unprovisioned-gcc-bazel-experimental-release please
@drake-jenkins-bot linux-arm64-resolute-unprovisioned-gcc-cmake-experimental-packaging please
@drake-jenkins-bot linux-noble-unprovisioned-clang-bazel-experimental-debug please
@drake-jenkins-bot linux-noble-unprovisioned-clang-bazel-experimental-everything-debug please
@drake-jenkins-bot linux-noble-unprovisioned-clang-bazel-experimental-everything-release please
@drake-jenkins-bot linux-noble-unprovisioned-clang-bazel-experimental-release please
@drake-jenkins-bot linux-noble-unprovisioned-gcc-bazel-experimental-debug please
@drake-jenkins-bot linux-noble-unprovisioned-gcc-bazel-experimental-documentation please
@drake-jenkins-bot linux-noble-unprovisioned-gcc-bazel-experimental-everything-debug please
@drake-jenkins-bot linux-noble-unprovisioned-gcc-bazel-experimental-everything-release please
@drake-jenkins-bot linux-noble-unprovisioned-gcc-bazel-experimental-mirror-to-s3 please
@drake-jenkins-bot linux-noble-unprovisioned-gcc-bazel-experimental-release please
@drake-jenkins-bot linux-noble-unprovisioned-gcc-cmake-experimental-debug please
@drake-jenkins-bot linux-noble-unprovisioned-gcc-cmake-experimental-everything-debug please
@drake-jenkins-bot linux-noble-unprovisioned-gcc-cmake-experimental-everything-release please
@drake-jenkins-bot linux-noble-unprovisioned-gcc-cmake-experimental-packaging please
@drake-jenkins-bot linux-noble-unprovisioned-gcc-cmake-experimental-release please
@drake-jenkins-bot linux-noble-unprovisioned-gcc-wheel-experimental-release please
@drake-jenkins-bot linux-resolute-unprovisioned-gcc-cmake-experimental-packaging please

@jwnimmer-tri

Copy link
Copy Markdown
Collaborator

The YOLO tests all passed! (Except for wheel builds, which are known to be unfinished.)

@jwnimmer-tri jwnimmer-tri left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@jwnimmer-tri reviewed 7 files and all commit messages, made 4 comments, and resolved 4 discussions.
Reviewable status: 5 unresolved discussions, LGTM missing from assignee jwnimmer-tri(platform), needs at least two assigned reviewers, labeled "do not merge", commits need curation (https://drake.mit.edu/reviewable.html#curated-commits), missing label for release notes.


bindings/pydrake/geometry/geometry_py_render.cc line 138 at r7 (raw file):

Previously, jwnimmer-tri (Jeremy Nimmer) wrote…

This code has no tests.

Correction: has no tests of omitting the method in the Python subclass.

In-progress now at #24763.

Done


bindings/pydrake/multibody/tree_py.cc line 1287 at r7 (raw file):

Previously, jwnimmer-tri (Jeremy Nimmer) wrote…

In-progress now at #24764.

Done


bindings/pydrake/systems/framework_py_systems.cc line 340 at r7 (raw file):

Previously, jwnimmer-tri (Jeremy Nimmer) wrote…

This code has no tests.

Correction: has no tests of omitting the method in the Python subclass.

(The new test actually passes on this branch already, because for this particular NVI method, we bind the Do... method to be callable by Python. Its implementation is not a stub -- the derived class is always supposed to call the base class.)

In-progress now at #24763.

Done


bindings/pydrake/systems/framework_py_systems.cc line 365 at r7 (raw file):

Previously, jwnimmer-tri (Jeremy Nimmer) wrote…

This code has no tests.

Correction: has no tests of omitting the method in the Python subclass.

(The new test actually passes on this branch already, because for this particular NVI method, we bind the Do... method to be callable by Python. Its implementation is not a stub -- the derived class is always supposed to call the base class.)

In-progress now at #24763.

Done

@rpoyner-tri rpoyner-tri left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@rpoyner-tri reviewed 4 files.
Reviewable status: 5 unresolved discussions, LGTM missing from assignee jwnimmer-tri(platform), needs at least two assigned reviewers, labeled "do not merge", commits need curation (https://drake.mit.edu/reviewable.html#curated-commits), missing label for release notes (waiting on jwnimmer-tri).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants