-
Notifications
You must be signed in to change notification settings - Fork 168
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
refactor: Add macro to simplify algorithm binding #1510
refactor: Add macro to simplify algorithm binding #1510
Conversation
Codecov Report
@@ Coverage Diff @@
## main #1510 +/- ##
=======================================
Coverage 48.54% 48.54%
=======================================
Files 381 381
Lines 20789 20789
Branches 9539 9539
=======================================
Hits 10092 10092
Misses 4112 4112
Partials 6585 6585 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
Existing python tests seem to fail with this change. Can you check if you can reproduce locally, @benjaminhuth? |
Yeah I already know what the problem is. Most writers/readers do not provide a However, it seems like that the I see three options there
I would go with the second option, because I think it is useful to have this accessor... What do you think @paulgessinger ? |
Yes I agree, adding the config accessor everywhere seems like the right thing to do. |
@paulgessinger This should be ready to go in now, could you have a look and approve? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good I think. If the output doesn't change, I'm happy.
While working with the python bindings, I thought its quite a lot of repetive boiler plate code to add an Algorithm to the python bindings. With the help of `Boost.Preprocessor` this can be simplified quite a lot: ```c++ ACTS_PYTHON_DECLARE_ALGORITHM( ActsExamples::FooAlgorithm, "FooAlgorithm", inputA, inputB, output) ``` expands to ```c++ { using Alg = ActsExamples::FooAlgorithm; using Config = Alg::Config; auto alg = py::class_<Alg, ActsExamples::BareAlgorithm, std::shared_ptr<Alg>>( mex, "FooAlgorithm") .def(py::init<const Config &, Acts::Logging::Level>(), py::arg("config"), py::arg("level")) .def_property_readonly("config", &Alg::config); auto c = py::class_<Config>(alg, "Config").def(py::init<>()); ACTS_PYTHON_STRUCT_BEGIN(c, Config); ACTS_PYTHON_MEMBER(inputA); ACTS_PYTHON_MEMBER(inputB); ACTS_PYTHON_MEMBER(output); ACTS_PYTHON_STRUCT_END(); } ``` This supports any number of arguments due to the preprocessor loops of Boost. Since we use macros anyways here to simplify declaration, I think this could be an acceptable use case of another macro. I have this already appied for the Exa.TrkX algorithm, but wanted to wait for feedback (@paulgessinger) before doing the rest of the algorithms.
While working with the python bindings, I thought its quite a lot of repetive boiler plate code to add an Algorithm to the python bindings. With the help of `Boost.Preprocessor` this can be simplified quite a lot: ```c++ ACTS_PYTHON_DECLARE_ALGORITHM( ActsExamples::FooAlgorithm, "FooAlgorithm", inputA, inputB, output) ``` expands to ```c++ { using Alg = ActsExamples::FooAlgorithm; using Config = Alg::Config; auto alg = py::class_<Alg, ActsExamples::BareAlgorithm, std::shared_ptr<Alg>>( mex, "FooAlgorithm") .def(py::init<const Config &, Acts::Logging::Level>(), py::arg("config"), py::arg("level")) .def_property_readonly("config", &Alg::config); auto c = py::class_<Config>(alg, "Config").def(py::init<>()); ACTS_PYTHON_STRUCT_BEGIN(c, Config); ACTS_PYTHON_MEMBER(inputA); ACTS_PYTHON_MEMBER(inputB); ACTS_PYTHON_MEMBER(output); ACTS_PYTHON_STRUCT_END(); } ``` This supports any number of arguments due to the preprocessor loops of Boost. Since we use macros anyways here to simplify declaration, I think this could be an acceptable use case of another macro. I have this already appied for the Exa.TrkX algorithm, but wanted to wait for feedback (@paulgessinger) before doing the rest of the algorithms.
While working with the python bindings, I thought its quite a lot of repetive boiler plate code to add an Algorithm to the python bindings. With the help of
Boost.Preprocessor
this can be simplified quite a lot:expands to
This supports any number of arguments due to the preprocessor loops of Boost. Since we use macros anyways here to simplify declaration, I think this could be an acceptable use case of another macro.
I have this already appied for the Exa.TrkX algorithm, but wanted to wait for feedback (@paulgessinger) before doing the rest of the algorithms.