Skip to content

numba / dask defensive hardening - #1804

Open
cmdupuis3 wants to merge 19 commits into
UXARRAY:mainfrom
cmdupuis3:cmd/h1h2
Open

cmdupuis3 wants to merge 19 commits into
UXARRAY:mainfrom
cmdupuis3:cmd/h1h2

Conversation

@cmdupuis3

@cmdupuis3 cmdupuis3 commented Oct 5, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #1805

Overview

Adds a few guards to prevent regressions during chunking refactor. These guards cover stale numba caches via inline="always", and possible regressions if using fastmath in accuracy-sensitive code regions.

These cover H1 and H2 of #1789

PR Checklist

General

  • An issue is created and linked
  • Added appropriate labels (if your uxarray repo permissions allow it)
  • Filled out Overview and Expected Usage (if applicable) sections

Testing & Benchmarking

  • There is adequate test coverage of changes from this PR (add new tests if needed)
  • If this PR could affect performance, ran ASV benchmarks and confirmed they show expected behavior (add a new benchmark if necessary)

Documentation and Examples

  • Docstrings updated with any function changes, and included in all new functions
  • User (public) functions added to docs/api.rst; internal (private) function names start with an underscore (_)

AI Disclosure

AI Usage: Claude Opus 5.5

  • I have tested and take responsibility for all AI-generated content in my PR.

cmdupuis3 and others added 2 commits October 5, 2026 13:02
Add a test that forbids fastmath anywhere code from uxarray.utils.computing
is compiled, and requires error_model="numpy" on acc_sqrt_re, _accux_gca,
_accux_constlat and every kernel they are inlined into. An inline="always"
callee is compiled with its caller's flags, so the test follows numba's
inline call chains rather than only checking the definitions.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cmdupuis3 cmdupuis3 self-assigned this Oct 5, 2026
@cmdupuis3 cmdupuis3 linked an issue Oct 5, 2026 that may be closed by this pull request
@cmdupuis3 cmdupuis3 added accuracy Related to mathematical accuracy of operations, such as numerical precision or rounding errors CI Continuous Integration testing Test Cases labels Oct 5, 2026

@jayeshkrishna jayeshkrishna left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

It looks to me that you are trying to test for two scenarios (to defend against flags ignored during inlining),

  • If a function calls an inline function with error_model == numpy then make sure that the function also uses error_model == numpy (to avoid error_model in the inlined function being ignored)
  • If a function calls an inline function make sure that the function does not use fastmath (to avoid fastmath being used for the inline function)

IMO, Changing some variable/function names and adding more comments would improve the readability of the code

The change to cleanup numba cache looks good, you might want to change the warning message to the user.

Some suggested comments are in the review comments ("Comment: ...")

Comment thread ci/clean_numba_cache.py Resolved
Comment thread test/grid/geometry/test_numba_flags.py Resolved
Comment thread test/grid/geometry/test_numba_flags.py Resolved
Comment thread test/grid/geometry/test_numba_flags.py Resolved
Comment thread test/grid/geometry/test_numba_flags.py Resolved
Comment thread test/grid/geometry/test_numba_flags.py Resolved
Comment thread test/grid/geometry/test_numba_flags.py Resolved
Comment thread test/grid/geometry/test_numba_flags.py Resolved
Comment thread test/grid/geometry/test_numba_flags.py Resolved
Comment thread test/grid/geometry/test_numba_flags.py Resolved
@cmdupuis3

Copy link
Copy Markdown
Collaborator Author

pre-commit.ci autofix

pre-commit-ci Bot and others added 7 commits October 23, 2026 19:55
- Rename _compiled_into to _get_inlined_funcs_in_call_tree.
- Move the NUMPY_ERROR_MODEL_KERNELS presence check from the fixture into
  test_numpy_error_model, with a message, and add a matching guard to
  test_no_fastmath so neither test can pass vacuously.
- Explain why NUMPY_ERROR_MODEL_KERNELS lists the source kernels by hand.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Explain why inlined EFT kernels need error_model="numpy" and no fastmath,
with verified acc_sqrt_re examples, and correct the claim that sqrt of a
negative raises under the default error model (only division does).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cmdupuis3

Copy link
Copy Markdown
Collaborator Author

@jayeshkrishna The documentation should be better now, take a look

@cmdupuis3
cmdupuis3 marked this pull request as ready for review November 16, 2026 23:00
Comment thread test/grid/geometry/test_numba_flags.py Resolved
cmdupuis3 and others added 2 commits November 17, 2026 13:48
Say why fastmath is rejected, what the offender entries are (kernels or
module:line of a non-False fastmath keyword) and how to fix it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@Sevans711 Sevans711 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Overall the changes here look pretty reasonable, and are pretty low-risk since they are all focused on improving developer experience (and tightening up testing). Before approving, I do have one sizeable concern though: What is the motivation for auto-clearing the cache during pre-commit?

I usually run pre-commit run --all-files locally, so I think this might wipe the relevant cached files for me every time I run that. It also wipes the cache after I've already made most of the changes; I don't always remember to run pre-commit before calling pytest. Local testing showed that pytest test/grid alone takes roughly 90 seconds right after running ci/clean_numba_cache.py, but <20 seconds on a "warm" run, so aggressively auto-clearing the cache has a real downside. In practice I'm concerned that including the cache clearing in pre-commit would end up slowing down my future pytest runs on unrelated work more often than it saves me from a stale cache while debugging relevant pieces of the code. Auto-clearing the cache also won't help anyone pulling my changes onto their machine locally (e.g. swapping into a PR branch for local testing) because they will still have a stale cache. It also doesn't help the online CI, which always starts with no cache.

That being said, I do think there's a good amount of value in the test_numba_flags.py tests being added here, in creating the python ci/clean_numba_cache.py script, and in adding the documentation reminding developers to run this script when working on relevant numba methods. Locally I had been using a custom version of it (mine looked something like find ../uxarray -type f \( -name "*.nbc" -o -name "*.nbi" \) -delete), but it will be quite nice to have a documented and "canonical" way to do this instead.

I would be happy to approve if the auto cache clearing was removed from pre-commit. If you additionally want protection against a stale cache for local pytest runs so that you can catch issues before they hit the online CI in a PR, perhaps a good way to proceed could be to save hashes for the relevant files during conftest.py, and run python ci/clean_numba_cache.py only if those hashes have changed?

(Claude helped me with some of the local testing and figuring out what to focus on in this review, but I wrote the review text myself)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

accuracy Related to mathematical accuracy of operations, such as numerical precision or rounding errors CI Continuous Integration testing Test Cases

Projects

None yet

Development

Successfully merging this pull request may close these issues.

numba cache and fastmath regression hardening

3 participants