Skip to content

Fix atom self-image detection bug in Torch-based graph construction#164

Open
PascalSalzbrenner wants to merge 1 commit into
microsoft:mainfrom
PascalSalzbrenner:fix-self-image-bug
Open

Fix atom self-image detection bug in Torch-based graph construction#164
PascalSalzbrenner wants to merge 1 commit into
microsoft:mainfrom
PascalSalzbrenner:fix-self-image-bug

Conversation

@PascalSalzbrenner

@PascalSalzbrenner PascalSalzbrenner commented Jun 10, 2026

Copy link
Copy Markdown

Diagnosis: On the GPU / Torch / TorchSim path, torch.cdist sometimes returns the distance of an atom with itself (in the same unit cell, not with periodic images) incorrectly as ~0.011 instead of exactly 0. This happens for atoms far from the origin in large (>20 A) unit cells due to an accumulation of errors resulting from the float32 precision. Such an atom would incorrectly be marked as False in the is_self_loop test in line 250 of radius_graph_pbc.py. Then, when m3gnet computes the distances exactly, we get 0/0 divisions in the m3gnet.py graph construction. Mattersim then returns NaN for the structure's energy, forces, and stresses.

Fix: The simple fix is to base the is_self_loop test on quantities we know exactly (same index + offset == 0, ie same cell). I made this fix and added tests against regression as well as verifying periodic images are picked up correctly.

…e, resulting in failed self-interaction testing and causing the model to return NaN predictions
@PascalSalzbrenner

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree company="Microsoft"

@PascalSalzbrenner

Copy link
Copy Markdown
Author

Should address issue #162 and part 1 of issue #163

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant