Fix NaN handling in electrostatic_sphere_eb MR analysis#6807
Merged
ax3l merged 1 commit intoBLAST-WarpX:developmentfrom Apr 28, 2026
Merged
Fix NaN handling in electrostatic_sphere_eb MR analysis#6807ax3l merged 1 commit intoBLAST-WarpX:developmentfrom
ax3l merged 1 commit intoBLAST-WarpX:developmentfrom
Conversation
The find_first_non_zero_from_bottom_left/upper_right helper functions used ``matrix[i][j] != np.nan`` to skip NaN values. Per IEEE 754, NaN != NaN is always True, so this check never filtered out NaN cells. On GPU platforms where openpmd outputs NaN for cells outside the refined patch (rather than zero), the analysis selected NaN regions as valid data, producing ``nan`` errors for level 1 and failing the assertion. Fix: replace ``!= np.nan`` with ``not np.isnan()``. With the fix, level 1 errors on A100 GPU are 0.029% (phi) and 0.083% (Er), well within the 0.4% tolerance. Co-Authored-By: Claude Opus 4.7 <[email protected]>
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
In IEEE floats,
np.nan != np.nanis alwaysTrue, so the old code was buggy:NaN is never equal to anything, including itself.
Original Description - Spotted by @zippylab
The find_first_non_zero_from_bottom_left/upper_right helper functions used
matrix[i][j] != np.nanto skip NaN values. Per IEEE 754, NaN != NaN is always True, so this check never filtered out NaN cells.On GPU platforms where openpmd outputs NaN for cells outside the refined patch (rather than zero), the analysis selected NaN regions as valid data, producing
nanerrors for level 1 and failing the assertion.Fix: replace
!= np.nanwithnot np.isnan().With the fix, level 1 errors on A100 GPU are 0.029% (phi) and 0.083% (Er), well within the 0.4% tolerance.
X-ref
Isolated from #6801