Skip to content
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

Nanobind #99

Merged
merged 14 commits into from
Jun 17, 2024
Merged

Nanobind #99

merged 14 commits into from
Jun 17, 2024

Conversation

iglesias
Copy link
Collaborator

I thought next to be adding to this PR (1) a workflow to have the Python interface in the CI and (2) more of the parameters in nanobind_extension.cpp. I should also try using other of the DR methods from Python and consider if it could be nice (and easy) to have different combinations covered in the CI too.

And well also the bunch of TODO's I left ':-D

So, hmm, there could be a lot. I think I will continue pushing step by step and keep an eye how it can start getting integrated.

@iglesias iglesias requested a review from lisitsyn May 17, 2024 13:33
build_nanobind.sh Outdated Show resolved Hide resolved
Copy link
Owner

@lisitsyn lisitsyn left a comment

Choose a reason for hiding this comment

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

That's an amazing thing there. It looks much simpler than I thought.

CMakeLists.txt Show resolved Hide resolved
test_exception_unknown_method()
parameters = tapkee.ParametersSet()
method = parse_reduction_method('lle')
parameters.add(tapkee.Parameter.create('dimension reduction method', method))
Copy link
Owner

Choose a reason for hiding this comment

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

Could you add some numeric parameter too?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There's one for target_dimension now used from test_nanobind_extension.py.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Refactor to use e.g. pytest.

@iglesias
Copy link
Collaborator Author

Running in the CI looking good too!
https://github.com/iglesias/tapkee/actions/runs/9153626706/job/25162869366

I will update the workflow since it would be nice if the new job appears in the pull request too.

@iglesias iglesias marked this pull request as ready for review May 20, 2024 05:18
@iglesias
Copy link
Collaborator Author

We saw that it worked with nanobind and now know what to expect from it. It can be picked up at any moment when there's interest in having it with yesterday's new parse_* methods and templates.

@iglesias iglesias closed this May 21, 2024
@iglesias iglesias reopened this Jun 4, 2024
@iglesias
Copy link
Collaborator Author

iglesias commented Jun 4, 2024

I quickly merged the upstream changes in examples/go.py. Next, I recall from two weeks ago there had also been changes in the templates, so I expect the nanobind build to fail.

@iglesias
Copy link
Collaborator Author

iglesias commented Jun 4, 2024

I started updating the extension and got to this one:

src/python/nanobind_extension.cpp: In function ‘void nanobind_init_tapkee(nanobind::module_&)’:
src/python/nanobind_extension.cpp:38:10: error: no matching function for call to ‘nanobind::module_::def(const char [15], <unresolved overloaded function type>)’
   38 |     m.def("parse_multiple", &parse_multiple<DimensionReductionMethod>);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from venv-tapkee-nanobind/lib/python3.12/site-packages/nanobind/include/nanobind/nanobind.h:51:venv-tapkee-nanobind/lib/python3.12/site-packages/nanobind/include/nanobind/nb_func.h:255:10: note: candidate: ‘template<class Func, class ... Extra> nanobind::module_& nanobind::module_::def(const char*, Func&&, const Extra& ...)’
  255 | module_ &module_::def(const char *name_, Func &&f, const Extra &...extra) {
      |          ^~~~~~~
venv-tapkee-nanobind/lib/python3.12/site-packages/nanobind/include/nanobind/nb_func.h:255:10: note:   template argument deduction/substitution failed:
src/python/nanobind_extension.cpp:38:10: note:   couldn’t deduce template parameter ‘Func’
   38 |     m.def("parse_multiple", &parse_multiple<DimensionReductionMethod>)

@iglesias
Copy link
Collaborator Author

I started updating the extension and got to this one:

src/python/nanobind_extension.cpp: In function ‘void nanobind_init_tapkee(nanobind::module_&)’:
src/python/nanobind_extension.cpp:38:10: error: no matching function for call to ‘nanobind::module_::def(const char [15], <unresolved overloaded function type>)’
   38 |     m.def("parse_multiple", &parse_multiple<DimensionReductionMethod>);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from venv-tapkee-nanobind/lib/python3.12/site-packages/nanobind/include/nanobind/nanobind.h:51:venv-tapkee-nanobind/lib/python3.12/site-packages/nanobind/include/nanobind/nb_func.h:255:10: note: candidate: ‘template<class Func, class ... Extra> nanobind::module_& nanobind::module_::def(const char*, Func&&, const Extra& ...)’
  255 | module_ &module_::def(const char *name_, Func &&f, const Extra &...extra) {
      |          ^~~~~~~
venv-tapkee-nanobind/lib/python3.12/site-packages/nanobind/include/nanobind/nb_func.h:255:10: note:   template argument deduction/substitution failed:
src/python/nanobind_extension.cpp:38:10: note:   couldn’t deduce template parameter ‘Func’
   38 |     m.def("parse_multiple", &parse_multiple<DimensionReductionMethod>)

I am still working on other build errors after this one. For this one the DimensionReductionMethod is not the right template, it'd be a map.

@lisitsyn
Copy link
Owner

I started updating the extension and got to this one:

src/python/nanobind_extension.cpp: In function ‘void nanobind_init_tapkee(nanobind::module_&)’:
src/python/nanobind_extension.cpp:38:10: error: no matching function for call to ‘nanobind::module_::def(const char [15], <unresolved overloaded function type>)’
   38 |     m.def("parse_multiple", &parse_multiple<DimensionReductionMethod>);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from venv-tapkee-nanobind/lib/python3.12/site-packages/nanobind/include/nanobind/nanobind.h:51:venv-tapkee-nanobind/lib/python3.12/site-packages/nanobind/include/nanobind/nb_func.h:255:10: note: candidate: ‘template<class Func, class ... Extra> nanobind::module_& nanobind::module_::def(const char*, Func&&, const Extra& ...)’
  255 | module_ &module_::def(const char *name_, Func &&f, const Extra &...extra) {
      |          ^~~~~~~
venv-tapkee-nanobind/lib/python3.12/site-packages/nanobind/include/nanobind/nb_func.h:255:10: note:   template argument deduction/substitution failed:
src/python/nanobind_extension.cpp:38:10: note:   couldn’t deduce template parameter ‘Func’
   38 |     m.def("parse_multiple", &parse_multiple<DimensionReductionMethod>)

I am still working on other build errors after this one. For this one the DimensionReductionMethod is not the right template, it'd be a map.

I'd suggest to introduce some currying so that there is an additional parse_method that just fixes the first argument of parse_multiple. This way you won't have to call a templated function. What do you think?

@iglesias
Copy link
Collaborator Author

I'd suggest to introduce some currying so that there is an additional parse_method that just fixes the first argument of parse_multiple. This way you won't have to call a templated function. What do you think?

Yeah! I think that's a good idea. It'd also simplify the extension in avoiding to expose the maps.

@iglesias
Copy link
Collaborator Author

The extension is back: https://github.com/iglesias/tapkee/actions/runs/9535436521/job/26281156242

There was a funny interaction with the renaming from withParameters to with since, I guess, it's a reserved word in Python.

For next, it appears the branch cannot be rebased due to conflicts. I haven't looked into it yet.

@iglesias
Copy link
Collaborator Author

Ah, all right, I think I understand about the rebase now. It can be squashed at least, I think that's suitable for this one.
I think it can be considered in a state to be ready for merge, then, it enables using the chain interface nicely from Python as well as directly inputting np.arrays to embed 🎉

@lisitsyn
Copy link
Owner

Do you think we squash and merge or would you force-squash it?

@iglesias
Copy link
Collaborator Author

I can do it here right away.

@iglesias iglesias merged commit 04b33b5 into lisitsyn:main Jun 17, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants