Skip to content

Commit 04bb5e5

Browse files
ax3lTim Williams
andauthored
Fix NaN handling in electrostatic_sphere_eb MR analysis (#6807)
## 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 Co-authored-by: Tim Williams <tjwilliams@anl.gov>
1 parent bc30e14 commit 04bb5e5

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

Examples/Tests/electrostatic_sphere_eb/analysis_rz_mr.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@
2626
def find_first_non_zero_from_bottom_left(matrix):
2727
for i in range(matrix.shape[0]):
2828
for j in range(matrix.shape[1]):
29-
if (matrix[i][j] != 0) and (matrix[i][j] != np.nan):
29+
if (matrix[i][j] != 0) and (not np.isnan(matrix[i][j])):
3030
return (i, j)
3131
return i, j
3232

3333

3434
def find_first_non_zero_from_upper_right(matrix):
3535
for i in range(matrix.shape[0] - 1, -1, -1):
3636
for j in range(matrix.shape[1] - 1, -1, -1):
37-
if (matrix[i][j] != 0) and (matrix[i][j] != np.nan):
37+
if (matrix[i][j] != 0) and (not np.isnan(matrix[i][j])):
3838
return (i, j)
3939
return i, j
4040

0 commit comments

Comments
 (0)