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

Remove Numba as a dependency #2841

Merged
merged 8 commits into from
Sep 9, 2024
Merged

Remove Numba as a dependency #2841

merged 8 commits into from
Sep 9, 2024

Conversation

namurphy
Copy link
Member

@namurphy namurphy commented Aug 28, 2024

Description

The purpose of this pull request is to test out dropping Numba as a dependency by dropping the numba.njit decorator from two formulary lite-functions. The lite-functions still exist as minimal functions that operate on NumPy arrays without any validations.

Motivation

It often takes Numba ∼3–5 months before it becomes compatible with a new release of Python each October. Depending on Numba has the following adverse consequences:

  • PlasmaPy is not able to run on the newest version of Python for a period of ∼3–5 months after the release of a new version of Python.
  • Packages that depend on PlasmaPy (like fiasco) likewise cannot be run on the newest version of Python for ∼3–5 months after a release.
  • The test suite for PlasmaPy cannot be run on release candidates for a new version of Python.

I did some timings (reported in this comment) and found that the performance gains from using Numba are ∼1–3% for the charged particle radiography tests, and that our full test suite runs ∼1% quicker without a Numba dependency.

My view is that we get enough performance gains from dropping units and validations for the lite-functions, and that the drawbacks from depending on Numba are much more significant than the slight performance gains.

Alternatives

I've been hoping we could Cythonize the lite functions so that we could drop the Numba dependency. However, we haven't had the capacity to complete this.

Related issues and pull requests

Closes #1342.

Related to #1098, #1145, #2104, #2256, #2372, #2634, #2786.

@namurphy namurphy added the prototype 🏗️ Trying out an implementation on a trial basis label Aug 28, 2024
@github-actions github-actions bot added docs PlasmaPy Docs at http://docs.plasmapy.org plasmapy.formulary Related to the plasmapy.formulary subpackage testing plasmapy.utils Related to the plasmapy.utils subpackage requirements Related to updating requirements contributor guide packaging Related to packaging or distribution documentation infrastructure python Pull requests that update Python code labels Aug 28, 2024
@namurphy namurphy added the run weekly tests in CI Add this label to PRs to additionally run weekly tests. label Aug 28, 2024
Copy link

codecov bot commented Aug 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.33%. Comparing base (1385eb4) to head (1b41756).
Report is 52 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2841      +/-   ##
==========================================
- Coverage   95.12%   94.33%   -0.79%     
==========================================
  Files         107      107              
  Lines        9617     9621       +4     
  Branches     2226     2228       +2     
==========================================
- Hits         9148     9076      -72     
- Misses        280      350      +70     
- Partials      189      195       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@namurphy
Copy link
Member Author

namurphy commented Aug 28, 2024

I ran the full test suite locally on my workstation with nox -s 'tests-all(3.12)' for both the main and denumbafy branches (with and without Numba, respectively). The overall test suite was a little bit quicker without Numba, while synthetic charged particle radiography tests were generally slightly slower.

test main (with Numba) denumbafy (without Numba)
Full suite 77.83 76.80 (-1%)
test_add_wire_mesh 18.97 19.14 (+1%)
test_multiple_grids 14.01 14.44 (+3%)
test_multiple_grids2 13.44 13.77 (+2%)
test_1D_deflections 3.40 3.35 (-1.5%)
test_run_options 2.40 2.38 (-1%)

@namurphy namurphy removed the run weekly tests in CI Add this label to PRs to additionally run weekly tests. label Aug 28, 2024
@namurphy
Copy link
Member Author

namurphy commented Aug 28, 2024

I did some timings to check the performance of jitted and non-jitted versions of plasma_frequency_lite. The relative differences in performance are high, but the absolute differences remain quite low.

inputs jitted not-jitted absolute difference
floats 295 ns 772 ns $4.77 × 10^{-7}$ s
1000-element arrays 3.22 μs 5.72 μs $2.5 × 10^{-6}$ s
100000-element arrays 226 μs 366 μs $1.4 × 10^{-4}$ s
10000000-element arrays 29.2 ms 77 ms $0.04$ s

@github-actions github-actions bot added the maintenance General updates to package infrastructure label Aug 28, 2024
Copy link
Member

@StanczakDominik StanczakDominik left a comment

Choose a reason for hiding this comment

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

Alas, so it is. Perhaps Numba's still better for end users instead of libraries 🫡

@namurphy
Copy link
Member Author

namurphy commented Sep 9, 2024

Alas, so it is. Perhaps Numba's still better for end users instead of libraries 🫡

It really is! Numba is a fantastic package, but the ∼3–5 month delays after a new release of Python outweigh the slight improvements in PlasmaPy's overall performance. The delays are also causing problems for fiasco which depends on PlasmaPy. Plus, depending on Numba also means that we can't test against Python beta releases and release candidates before the official release of Python. Sigh!

Also it is great as always to hear from you! I hope you have been doing really well!

@namurphy namurphy marked this pull request as ready for review September 9, 2024 16:55
@namurphy namurphy requested review from rocco8773 and a team as code owners September 9, 2024 16:55
@namurphy namurphy requested a review from pheuer September 9, 2024 16:55
Copy link
Member

@pheuer pheuer left a comment

Choose a reason for hiding this comment

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

I also approve - give the scope of PlasmaPy, I think these minor enhancements from njit are not worth the operational issues. Thanks for running the comprehensive timing comparisons!

@namurphy
Copy link
Member Author

namurphy commented Sep 9, 2024

Awesome, thank you! I'll go ahead and merge it. I suspect this will make @wtbarnes happy. 🙃

@namurphy namurphy merged commit 02ac744 into PlasmaPy:main Sep 9, 2024
19 checks passed
@namurphy namurphy deleted the denumbafy branch September 9, 2024 18:16
@github-actions github-actions bot removed the prototype 🏗️ Trying out an implementation on a trial basis label Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor guide docs PlasmaPy Docs at http://docs.plasmapy.org documentation infrastructure maintenance General updates to package infrastructure packaging Related to packaging or distribution plasmapy.formulary Related to the plasmapy.formulary subpackage plasmapy.utils Related to the plasmapy.utils subpackage python Pull requests that update Python code requirements Related to updating requirements testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handle Numba/LLVM delays for new Python versions
3 participants