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

migrate ETS to C++ #757

Merged
merged 50 commits into from
Aug 30, 2024
Merged

migrate ETS to C++ #757

merged 50 commits into from
Aug 30, 2024

Conversation

jmoralez
Copy link
Member

@jmoralez jmoralez commented Jan 12, 2024

Contributes to #753 by moving the functions that used numba in the ETS model to C++. Several changes had to be made to the library for this to work:

  • Move the python package to a python folder. This is so that when running the tests from the root of the repository it uses the installed statsforecast package instead of the code from the statsforecast folder. With a regular python package these would be the same, however since we're now shipping a shared library these two are now different (the installed package has the shared library and the statsforecast folder doesn't).
  • The tests now build the wheels first for the platforms that we'll support (windows amd64, macos x864_64, macos arm64, linux x86_64, linux aarch64 (arm64)) and then run the tests installing from that. These wheels will be published to s3 on pushes to main so that people can install from those without needing a compiler (the install notebook has instructions on how to do this).
  • Updated the python-publish action to build the wheels for the same platforms as in the previous point.
  • Added pybind11 to the dev requirements, which is used to build the shared library.
  • Moved the restrict_to_bounds function and the results tuple from ETS to utils. These will be removed once we migrate all the models that use numba to C++.

Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@jmoralez jmoralez marked this pull request as ready for review January 17, 2024 23:32
@jmoralez jmoralez marked this pull request as draft January 19, 2024 23:59
@jmoralez jmoralez marked this pull request as draft August 27, 2024 22:47
@jmoralez
Copy link
Member Author

@AzulGarza I think this is ready now. The changes since you last reviewed are:

  • Switched to pybind11 to generate the python bindings. The main benefits are:

    • The overhead of calling a function is very low, which is great for objective functions that get called during numerical optimization.
    • The interchange between the two languages is easier, e.g. you can define that you want a double array and pybind11 will try to coerce the input to that if it isn't and raise an error otherwise, you can return tuples, etc.

    The downside is that we now have to build wheels for each python version instead of just one per os-architecture combination.

  • Restored the setup.py file and extended it to build the shared library. This is so that we don't have to learn CMake, we just use that script.

  • Updated the CONTRIBUTING.md file to use uv (since I deleted the conda environment files in fix ci #874 to have all dependencies in a single place) and added a section on how to rebuild the extension (I can extend on that if you want but it's just a matter of changing/creating the C++ files and rebuilding).

@jmoralez jmoralez marked this pull request as ready for review August 29, 2024 23:02
Copy link
Member

@AzulGarza AzulGarza left a comment

Choose a reason for hiding this comment

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

this is amazing, @jmoralez! congrats🎉 lgtm

@jmoralez jmoralez merged commit beb7fcf into main Aug 30, 2024
50 checks passed
@jmoralez jmoralez deleted the ets-cpp branch August 30, 2024 20:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants