Skip to content

Fix NaN handling in electrostatic_sphere_eb MR analysis#6807

Merged
ax3l merged 1 commit intoBLAST-WarpX:developmentfrom
ax3l:fix-es-nan
Apr 28, 2026
Merged

Fix NaN handling in electrostatic_sphere_eb MR analysis#6807
ax3l merged 1 commit intoBLAST-WarpX:developmentfrom
ax3l:fix-es-nan

Conversation

@ax3l
Copy link
Copy Markdown
Member

@ax3l ax3l commented Apr 27, 2026

Summary

In IEEE floats, np.nan != np.nan is always True, 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.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.

X-ref

Isolated from #6801

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]>
@ax3l ax3l requested a review from oshapoval April 27, 2026 15:46
@ax3l ax3l added bug Something isn't working component: tests Tests and CI bug: affects latest release Bug also exists in latest release version labels Apr 27, 2026
@ax3l ax3l requested a review from lucafedeli88 April 27, 2026 15:46
@ax3l ax3l added the component: Python Python layer label Apr 27, 2026
Copy link
Copy Markdown
Member

@lucafedeli88 lucafedeli88 left a comment

Choose a reason for hiding this comment

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

Thanks!

@ax3l ax3l merged commit 04bb5e5 into BLAST-WarpX:development Apr 28, 2026
47 of 48 checks passed
@ax3l ax3l deleted the fix-es-nan branch April 28, 2026 04:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug: affects latest release Bug also exists in latest release version bug Something isn't working component: Python Python layer component: tests Tests and CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants