Make JIT source generation deterministic - #144
Merged
lmoresi merged 1 commit intoApr 28, 2026
Merged
Conversation
Sort unordered symbolic and code-generation collections before they affect emitted JIT C source. This prevents Python hash-randomized set/dict iteration from producing different source text on different MPI ranks. Preserve PETSc field ordering by sorting mesh variables by field_id before applying stable tie-breakers, then use deterministic ordering for constant extraction, free-symbol processing, UWexpression atom traversal, generated include headers, library directories, and library names. Add focused regression tests for the stable ordering helper, including field_id precedence and unordered symbol-container ordering. Validation: py_compile passed for _jitextension.py; tests/test_jit_deterministic_ordering.py passed; tests/test_jit_cache.py passed; Kramer spherical free-slip case2 cellsize 1/8 completed on 8 MPI ranks without PYTHONHASHSEED=0.
Member
|
Excellent discovery / fix ! |
lmoresi
approved these changes
Apr 28, 2026
lmoresi
left a comment
Member
There was a problem hiding this comment.
Yep, good catch. I thought that we'd fix things by not compiling across ranks, but this still leaves a problem if the cache cannot be located consistently
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR makes UW3 JIT source generation deterministic across MPI ranks by applying stable ordering when collecting symbols, constants, mesh variables, generated includes, and setup metadata.
Motivation
Some parallel runs can generate rank-dependent C source ordering from unordered Python collections. That can trigger JIT hash mismatches even when the mathematical expression is identical on all ranks.
Changes
field_idwhen sorting mesh variables.Validation
./uw python -m pytest tests/test_jit_deterministic_ordering.py tests/test_jit_cache.py -qPYTHONHASHSEED=0.Scope
This should not change solver mathematics. It only makes generated JIT source ordering stable across ranks.