-
Notifications
You must be signed in to change notification settings - Fork 7
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
Support nanobind #20
Support nanobind #20
Conversation
Just realized that I have not yet added tests for this. Will see if I can make that happen ASAP.
|
Hello David, Thanks a lot for this PR! Here are some quick advises about them:
Since integration tests are more important, let me give you some details on how they are implemented:
Thanks! |
Hello, I added your branch in the repository into a new nanobind branch . I performed a rebase on the main branch before doing so. The integration went smoothly. I only had to do a few changes, in three commits I added on top of yours:
I had to do a small fix, following the rebase, because I had added a "contiguous check". litgen/src/litgen/internal/adapt_function_params/_adapt_c_buffers.py Lines 402 to 419 in a3c6671
Status as of now:
As you know more than me about nanobind, could you have a look at this? Do not hesitate to ask for help, I'll be happy to answer questions and to provide help. |
Hum, setting up the integration test for two different binding types is a bit tricky, especially in the build scripts. Give me some time to have a look at it. |
Thanks! I should be able to join you on this weekend. 👍🏼 |
Hello, I added some more commits and reorganized the integration tests to account for nanobind and pybind11 working together in the integration_tests folder of the nanobind branch. I also added some information in the integration test Readme. Please read it, as it should help you understand the new folder structure and how to run the tests. just -l
Available recipes:
build_integration_tests_nanobind # Builds the integration tests for nanobind
build_integration_tests_pybind # Builds the integration tests for pybind
default # List all available commands
integration_tests # Runs all tests for pybind and nanobind (after building the integration tests)
integration_tests_nanobind # Runs all tests for nanobind, after building the integration tests
integration_tests_pybind # Runs all tests for pybind, after building the integration tests
mypy # Runs mypy on the top level folder (see mypy.ini)
pytest # Just runs pytest (requires that the integration tests have been built) Here is the current status I took some time to correct the compilation of all tests when using nanobind. This was a good occasion for me to look at what modifications you did (and I was pleased). What works now:
Status of the integration tests I made modifications in order to ensure that the tests do compile. I did not check and correct the python tests at the moment (i.e the tests that will check that the bindings do work as expected). Here is a quick recap of the failing tests as of now: > just integration_tests_nanobind
...
...
...
======================================================================================================== short test summary info =========================================================================================================
FAILED src/litgen/integration_tests/mylib/c_style_array_test.py::test_const_array2_add - TypeError: const_array2_add(): incompatible function arguments. The following argument types are supported:
FAILED src/litgen/integration_tests/mylib/c_style_buffer_to_pyarray_test.py::test_add_inside_buffer - Failed: DID NOT RAISE <class 'RuntimeError'>
FAILED src/litgen/integration_tests/mylib/c_style_buffer_to_pyarray_test.py::test_templated_mul_inside_buffer - AttributeError: module 'lg_mylib' has no attribute 'templated_mul_inside_buffer'
FAILED src/litgen/integration_tests/mylib/class_adapt_test.py::test_adapt_constructor - TypeError: __init__(): incompatible function arguments. The following argument types are supported:
FAILED src/litgen/integration_tests/mylib/class_adapt_test.py::test_modify_array_member_via_numpy_array - TypeError: __init__(): incompatible function arguments. The following argument types are supported:
FAILED src/litgen/integration_tests/mylib/mix_adapters_class_test.py::test_template_method - AttributeError: 'lg_mylib._lg_mylib.some_namespace.Blah' object has no attribute 'templated_mul_inside_buffer'
FAILED src/litgen/integration_tests/mylib/modifiable_immutable_test.py::test_adapt_modifiable_immutable_to_return - TypeError: Unable to convert function return value to a Python type! The signature was
FAILED src/litgen/integration_tests/mylib/return_value_policy_test.py::test_return_value_policy - AssertionError: assert 0 == 3
FAILED src/litgen/integration_tests/mylib/template_class_test.py::test_template_class_int - TypeError: __init__(): incompatible function arguments. The following argument types are supported:
FAILED src/litgen/integration_tests/mylib/template_class_test.py::test_template_class_string - TypeError: __init__(): incompatible function arguments. The following argument types are supported:
FAILED src/litgen/integration_tests/mylib/template_function_test.py::test_sum_vector_and_c_array - TypeError: sum_vector_and_c_array_int(): incompatible function arguments. The following argument types are supported:
FAILED src/litgen/integration_tests/mylib/template_function_test.py::test_sum_vector_and_c_array_method - TypeError: sum_vector_and_c_array_int(): incompatible function arguments. The following argument types are supported:
==================================================================================================== 12 failed, 224 passed in 10.76s =====================================================================================================
call_guard_tester
error: Recipe `integration_tests_nanobind` failed on line 25 with exit code 1 12 tests out of 224 fail. Seems reasonable. The road ahead Let me summarize here what remains to be done.
Please keep me informed on your progress, and do not hesitate to ask for help, or to inform me if you hit a road block or if you feel you do not have enough time. Many thanks for your help! |
Hey @pthom 👋🏼 I pulled your Here are my feedbacks/progress. 😃 Use
|
Hello @davidlatwe I do not have much time today, but to answer your question about which branch to use, you wrote:
I never used this too. However, it might work ;-) Could you integrate the changes from my nanobind branch to your nanobind branch and we will continue working on yours? Please note that I had done a rebase of your changes initially.
Sound like a good idea! |
697c60b
to
78c7ff5
Compare
With original C++ enum name preserved. E.g. `imgui.ImGuiWindowFlags_MenuBar` instead of `imgui.WindowFlags_.MenuBar`
This reverts commit e247b5f.
This allows excluding specific function. Use case: IMGUI_BUNDLE_PYTHON_UNSUPPORTED_API definition was added in ImGui source to opt-out un-bindable API. With this new option, we can achieve the same goal without having to alter source code.
This allows excluding specific class/struct method and member. Use case: IMGUI_BUNDLE_PYTHON_UNSUPPORTED_API definition was added in ImGui source to opt-out un-bindable API. With this new option, we can achieve the same goal without having to alter source code. E.g. ImVector.
…iguous check for nanobind
…ember_exclude_by_name_and_class__regex
Hi @pthom I have integrated your commit into this branch. It was done by these steps:
Before doing afore mentioned integration, I tried force-push your branch into this PR directly. But the git diff become un-readable so I did another force-push to correct it. About supporting Powershell for Will continue the nanobind tests as soon as I can. |
Hi David, I had a look at your changes and they look good. I pushed some small modifications:
Good job, Cheers! |
# The type checking must be done in two steps (at least) # - check the generic type (int, float, uint, etc) # - check the size of the type (int8, int16, int32, int64, etc) # Knowing that for a given ndarray: # ndarray::dtype() returns a # struct dtype { # uint8_t code = 0; # uint8_t bits = 0; # uint16_t lanes = 0; # }; # and that the code is defined as: # enum class dtype_code : uint8_t { Int = 0, UInt = 1, Float = 2, Bfloat = 4, Complex = 5, Bool = 6 };
Added a lambda _nanobind_buffer_type_to_letter_code that will compute the letter code for the buffer type
… pybind or nanobind
Hello again, I had another look at the failing tests, and as I was suspecting, the code to adapt c buffers is quite complex (and a bit fragile). Making it compatible for pybind together with nanobind is not an easy at all, especially because the ndarray API was completely rewritten for nanobind. I am working on some corrections on this part, I will keep you informed. |
Hi David, Big thanks for all the great work on this PR! Since the last steps were a bit complex (and needed testing on multiple platforms), I went ahead and wrapped up the remaining tasks to get this PR fully completed. I hope you’re not discouraged by this — I mainly stepped in because I’m juggling quite a few projects (imgui-bundle, litgen, hello-imgui, cvnp, etc.) and wanted to get this feature integrated into imgui-bundle for some upcoming experiments. I will merge this PR now, and you will see that the documentation site, now shows bindings for both pybind11 and nanobind. I’m also planning to propose an update to the nanobind documentation site to mention litgen as a compatible generator. Your work here has really made an impact! Please do not hesitate to add comments in this PR: if you feel more changes are needed, we may pursue it, or open a new PR. Also, I hope to be able to exchange with you concerning your other open PR on imgui_bundle nanobind support! Thanks again! 😊 PS: you will see that I added a thank you note in the README Best, |
See wjakob/nanobind#780 where I propose an update to the nanobind doc |
Hey @pthom , big thanks for all the kind words and your recognition! ❤️ ❤️
Not at all! My progress was a bit slow due to my limited resources these days, so I am really glad that you were able to push it forward. And yeah, I will move on to the other PR on Cheers! 🍻 |
Hi @pthom ,
Thank you for this awesome project. This pull request enabled us to generate ImGui binding with nanobind.
In latest 2 commits, we were even able to generate binding from original ImGui source (non-docking) without the need to patch
IMGUI_BUNDLE_PYTHON_UNSUPPORTED_API
:At this moment, I have only tested with these two ImGui source:
Did not have all API binding tested, but works in our project so far.
🚨This commit 656a99c bumped version to
0.999.0
, we need a proper version for this before merge.