-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
pydrake: Enable automated binding generation #7889
Comments
For reference #4486. "Requires a custom fork" is really the only real downside I see for pybind11, though it is a big one. Otherwise, I think we are still in good shape. Looking at the evolution of the Bazel internals, obviously there is going to be some good integration with CLIF at some point, but it is such an immature project externally to Google. |
Re-scoping this issue to focus on automated binding generation. |
FYI @thduynguyen |
Per f2f: I would like to have a Kitware go-to person for Will need to discuss this more in April (new contract). |
\cc @m-chaturvedi |
Per discussions in this Slack thread: @ggould-tri (and @jwnimmer-tri a while back) suggested having intermediate "starting point" bindings generated. This could be done with our current use of Python Subsequent steps could leverage (For |
FYI The Kitware tool of choice is CastXML which used for the bindings of the (template-heavy) ITK. |
@jamiesnape mentioned that he could whip together a proof-of-concept for us. |
I'll write up a wish list / loose "requirements doc" for this feature, e.g. features to preserve (possibly in spirals), features to add. |
As part of this, we should make sure we spend some time visiting each of the solutions listed above, and make sure we include SWIG in that evaluation. |
Just as an FYI: |
What features in particular do you like in CLIF? Obviously, I am biased, but writing out all detail in the |
It's not that I particularly like CLIF in it's current incantation (for the same reason as you mentioned - indirection via interface files). But wanted to record the convo and some related technologies. |
Also listed via recent commit to Not a lot of documentation, but will see how LLVM stuff gets interfaced (e.g. IR like XML as gccxml does, or directly via something else). EDIT: They use EDIT 2: Example posted here: |
Yet another binding project: Came across in this |
Hi @EricCousineau-TRI autopybind11 looks more similar to PyCLIF than I realized before I just look at their README: they also have an interface file, a C++ parser, code generator, and runtime. In PyCLIF's planned future the code generator + runtime will target pybind11. I'm also strongly considering replacing the existing C++ parser with something else; with what is wide open; CastXML looks interesting. When I'm done with that, too, really the only strong difference between autopybind11 and PyCLIF will be the syntax of the interface files. I can imagine that they could even be combined into one system. |
@EricCousineau-TRI Pardon for jumping in, but cppyy is not a ROOT project: it's standalone, and is directly installable with PyPI (https://pypi.org/project/cppyy/) and/or conda (https://anaconda.org/conda-forge/cppyy). Note that the conda release is behind (I don't control it). What happened with ROOT, and what you are linking above, is that cppyy was forked from PyROOT, with the ROOT team later re-integrating cppyy (the fork) back into PyROOT, replacing the old binder. But their version is crippled for backwards compatibility reasons. Those pythonizations are the ROOT-specific portions of the old PyROOT, ROOT-numpy integration etc. The rootpy project was an attempt to improve the "python" look-and-feel of PyROOT, but is dead AFAIK (the principal author left academia). As for gccxml, yes that is long gone and you can just pip-install cppyy for PyPy, getting the same backend (Cling). However, the bindings portion of the PyPy version (_cppyy) is well behind the CPython one (CPyCppyy). I'm catching up with this, but there simply has been (and is) more demand on the CPython side, so that has been prioritized. All the basics work with PyPy, but esp. things like automatic cross-inheritance and callbacks are not there yet, and the CPython version is also way better at handling auto-instantiation of complicated templates (think stuff you'll find in Eigen or boost). All parsing can be done at run-time by Cling. The cmake cppyy-generator is just there for precompiling and packaging; it's not material to the functioning of cppyy. Just The biggest caveat, compared to pybind11 or SWIG, is the dependency on Cling, and thus LLVM. See my thoughts on it here: https://cppyy.readthedocs.io/en/latest/philosophy.html#llvm-dependency |
@rwgk That sounds awesome - looking forward to it!!! For now, I'm playing with how Drake might consume @wlav Thanks for the info! I'll try to update our summaries to reflect what you've mentioned here. Regarding the philosophy on where to place the main overhead burden, I believe I understand what you wrote in terms of memory footprint for run-time vs. compile-time. As a data point, a user had tried out Cling via Jupyter, consuming Drake, here: The other fear here is that if caching is the route for optimizing the user experience, then we may run into Julia-esque problems, and it may be hard to integrate with the hermetic setup we have with Bazel (e.g. having to define possibly incremental caching layers for Bazel targets). I'll keep it in mind for the future, though! |
@EricCousineau-TRI The date on that bug report precedes this (long) report: https://bitbucket.org/wlav/cppyy/issues/38/interpreted-vs-compiled-code which has resolved many performance issues relating to templates. Further improvement is expected from precompiled modules (of the headers, not of the template instantiations), which isn't quite as problematic as caching, since these don't grow in size. It also allows, in theory, for distribution of binary representations of the headers, but I'm finding it fickle. It is also not for today, however, or at least not easily: it only works on Linux so far, so it's not enabled. Upstream promises to fix the final issues on MS Windows by the end of the summer. If they don't, then that time scale slides (and I'll have to put in effort myself to get what I want). In that case, it may not be there before the end of the year. Anyway, not trying to convince you; just wanted to add context to the comments made earlier in this thread about the old PyPy and PyROOT stuff. |
Makes sense, and thank you for the reference! |
As a side note, while trying to track down different bindings of Clang itself (beyond EDIT: Er, can hardly even find the source, noping outta that. |
The thing of note for Shiboken is that their "type system" includes the Perhaps this is the repo (mirror, anyway) you were looking for: https://github.com/qtproject/pyside-pyside-setup |
Thanks! I routed around there and come across some of the examples from Also, I just stumbled across this project, FTR I came across this when tinkering with writing |
FYI @wlav I've added an expanded writeup in |
That I'm thinking that the I read the changes to the writeup and just want to note that lazy binding can never be a performance drain: that is purely on the Python side and since everything is run-time in Python, you can only gain, unless in the rare case where you absolutely use every class and every function that was bound. (And even then, it'd surprise me if the difference were measurable in practical settings). Using Cling is a different matter: it is the inclusion of many header files in what is effectively a single translation unit that can kill performance. However, it is not fundamental to the approach. First, many projects that have large, complicated, sets of templates (e.g. Eigen, PCL, or boost for that matter), tend to subdivide the project into separate areas that tend to be used separately to make compilation simpler (e.g. Eigen/Dense v.s. Eigen/Sparse). It is not possible to keep this subdivision in Cling if all the parts are used (b/c of the single translation unit approach), but if not, then making separate python modules out of them, instead of putting all headers together as would be the default approach, does the trick. Second, I patched the underlying Clang and Cling to accept To be sure, I'm not disagreeing with the sentiment of the statement: the promise is to have your cake and eat it too, and it falls flat on that point. And if you can't have your cake, then there is no benefit to the Cling/LLVM dependency and memory overhead. (The calculus will change with modules, to be sure: in that case there will be more cake.) But the approach itself is not technically limiting performance. |
Updated overview with a brief motivational statement. Also, @wlav: Sorry for the delay, but thank you for following up! And yeah, the annotations in
FTR, I do like At the risk of introducing "yet another method", I would like to vie for adding another "approach" of bindings attribute association:
If the inline annotations are too verbose, or perhaps it's best to group a set of symbols, then these explicit associations can help to disambiguate symbols in the least verbose, and most explicit (and discoverable) format. |
Yes, you're right and I don't know the complexity of Drake, but am currently dealing with two very complex (modern) C++ libraries where annotations would not be straightforward. For example, But anyway, there recently was a kick-off meeting to abstract the bulk of Cling into ClangREPL, which would then become an "official" Clang project (e.g. lldb would benefit), and a All this is long term: that project has a span of 3 years, at the end of which it is expected to deliver seamless integration of C++, Python, and some other yet-to-be-determined language, in jupyter notebooks. So also Python entities available to Cling as C++ proxies (I did this long time ago as a proof-of-concept, still requiring casts to do type extraction, but there is no technical limitation to eg. do cross-inheritance back-and-forth as often as you like). Good things to come ... in 3 years. :) |
Ooh, all of that looks absolutely awesome!!! Is there a website / project / mailing list that I can subscribe to if I wanna keep tabs on this as well? |
The original RFC, and its follow-up thread, is here (among many other places): At the bottom is the Google group they intend to use, but it hasn't seen much activity yet (except for the initial kick-off meeting). The current focus of the main upstream devs is still Clang9, which is close to be released (I tried a port of cppyy already, and other then some initialization issues, it seems to work; that'll make a whole bunch of C++20 features available, although C++20 support as a whole isn't complete yet even in Clang master). |
FYI @rwgk Per recent convo, I've added a mention of FFIG here: https://gitlab.kitware.com/autopybind11/autopybind11/-/merge_requests/116 |
Closing out as "backlog unlikely to reach an actionable state within a reasonable timeframe". |
Motivation
Long story short, it's tedious to write bindings by hand. We have the current guidance, but even that is not comprehensive:
https://drake.mit.edu/doxygen_cxx/group__python__bindings.html
We have our bindings, they work, but they're a bit burdensome to write and update (and deprecated/delete).
We would like to eventually have a solution where Drake (and other) devs don't even have to think about their bindings. In the interim, though, it'd be nice to save thought for the more creative/critical aspects ("this doesn't fit my usage" or "I should add a keep alive here").
To that end, we want to be able to bootstrap (but no complete replace) manual writing of bindings. Eventually, we'd like these bindings to be completely automatic.
Design, Etc.
See Kitware-TRI shared Google Docs.
Alternatives
See options listed in "Alternative Comparison":
https://gitlab.kitware.com/autopybind11/autopybind11/-/blob/master/README.rst
(Permalink: https://gitlab.kitware.com/autopybind11/autopybind11/-/blob/0376168b2f40e5a3378ea09e90df95470c26d194/README.rst)
OLD:
Some possible alternatives:
pybind11
.pybind11
to: (a) handle AutoDiffXd and Symbolic matrixes, (b) handle unique_ptrs as arguments, (c) prevent Python derived class slicing,pybind11
bindingspybind11
.pybind11
.binder
: Uses LLVM for parsing, has interface files, etc.binder
unique_ptr
as input and outputbinder
shared_ptr
At present, my goal with
pybind11
is to provide a Pythonic view into the C++ implementation, not necessarily a pure Pythonic wrapping of Drake. Anything wanting to be purely Pythonic could wrap this implementation.EDIT: Keywords 'cause GitHub's search functionality is a bit stiff:
automatic automate pyclif binder parsing generate generated
The text was updated successfully, but these errors were encountered: