Repository navigation
Fix NaNs in test_discrete_gradient on DOLFINx nightly - #268
Merged
Merged
Conversation
The MatrixCSR branch of test_discrete_gradient built one input vector on the column index map of DOLFINx's discrete gradient and passed it to the mult of both matrices. MatrixCSR.mult indexes the vector with the matrix's own column numbering, so the vector has to be on that matrix's column map. On DOLFINx nightly the two maps differ: discrete_gradient uses V's map as is, while create_matrix, which interpolation_matrix uses, adds ghosts in another order. scifem's matrix then read past the end of the vector. Those columns have zero coefficients, so the product was usually right, and NaN when the memory read held one, which is why the failures came and went, and only in parallel. Build `u` on each matrix's column map instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
Fixes the three
test_discrete_gradient[*-False-tetrahedron]failures ("nan location mismatch") on the DOLFINx nightly leg. The bug was in the test, not inscifem.interpolation.interpolation_matrix.The
MatrixCSRbranch of the test built one input vector on the column index map of DOLFINx'sdiscrete_gradient, and passed it to themultof both matrices.MatrixCSR.multindexes the vector with the matrix's own column numbering, so the vector must be on that matrix's column map. On nightly the two maps differ:dolfinx.fem.discrete_gradientuses V's map as is (e.g. 8 ghosts).dolfinx.fem.create_matrix, whichinterpolation_matrixuses, adds ghosts in a different order (9–10 ghosts; at degree 3, 117 vs 81).So scifem's matrix read past the end of the vector: column index 241 into a vector of length 206 on one rank. Those columns have zero coefficients, so the product was usually right. It became NaN whenever the memory read happened to hold one, which is why the failures were intermittent and only appeared under MPI.
The test now builds
uon each matrix's own column map.Testing
Locally on DOLFINx nightly, against scifem
main:test_discrete_gradient5 times each atmpirun -n 3and-n 4: the old test failed in 9 of 10 runs, the fixed test passed all 10.tests/test_interpolation.pypasses serially and at 4 ranks.🤖 Generated with Claude Code