[pydrake] Port the common-init module to nanobind - #24783
Conversation
a52d2f5 to
5d74370
Compare
5d74370 to
95c57c6
Compare
jwnimmer-tri
left a comment
There was a problem hiding this comment.
+a:@rpoyner-tri for co-author / co-feature review, please, when time allows.
@jwnimmer-tri reviewed 29 files and all commit messages, and made 4 comments.
Reviewable status: LGTM missing from assignee rpoyner-tri(platform), needs at least two assigned reviewers (waiting on rpoyner-tri).
bindings/pydrake/symbolic_types_pybind.h line 39 at r1 (raw file):
const uint8_t var_type = static_cast<uint8_t>(hi); if (var_type > static_cast<uint8_t>(Variable::Type::RANDOM_EXPONENTIAL)) { return std::nullopt;
FYI nanobind requires its type-casters to be noexcept, so we can't provide a more specific error message for invalid arguments like we had with pybind11. Instead, the user will be get a TypeError on the call. The test has been updated to reflect this.
bindings/pydrake/common/BUILD.bazel line 420 at r1 (raw file):
drake_py_unittest( name = "eigen_pybind_test", # TODO(#21572) Remove this opt-out.
FYI This pull request only ports the essential components of the init module and any helper libraries required by it.
Higher-layer helper modules that are only needed by other modules in pydrake remain as future work, with TODOs on their tests.
bindings/pydrake/common/serialize_pybind.h line 151 at r1 (raw file):
}; if constexpr (std::is_same_v<T, bool>) { return type_of(py::bool_(false));
FYI The nanobind default constructors for primitives like bool_, int_, float_ etc construct None rather than 0, so we need to pass a non-None value here.
All other parts of pydrake depend on this module, so it needs to be the first thing ported. Co-authored-by: Rick Poyner (rico) <rick.poyner@tri.global>
95c57c6 to
d5b001c
Compare
All other parts of pydrake depend on this module, so it needs to be the first thing ported.
Towards #21572.
This change is