Title: [Bug]: TorchSim backend returns NaN on some structures · Issue #162 · microsoft/mattersim · GitHub
Open Graph Title: [Bug]: TorchSim backend returns NaN on some structures · Issue #162 · microsoft/mattersim
X Title: [Bug]: TorchSim backend returns NaN on some structures · Issue #162 · microsoft/mattersim
Description: Contact Details gael.huynh@uclouvain.be Bug Description Some structures seems to return NaN when using the TorchSim backend while using Potential.predict_properties works perfectly fine. Note that this error only occurs for some structur...
Open Graph Description: Contact Details gael.huynh@uclouvain.be Bug Description Some structures seems to return NaN when using the TorchSim backend while using Potential.predict_properties works perfectly fine. Note that ...
X Description: Contact Details gael.huynh@uclouvain.be Bug Description Some structures seems to return NaN when using the TorchSim backend while using Potential.predict_properties works perfectly fine. Note that ...
Mail addresses
gael.huynh@uclouvain.be
Opengraph URL: https://github.com/microsoft/mattersim/issues/162
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: TorchSim backend returns NaN on some structures","articleBody":"### Contact Details\n\ngael.huynh@uclouvain.be\n\n### Bug Description\n\nSome structures seems to return NaN when using the TorchSim backend while using `Potential.predict_properties` works perfectly fine. Note that this error only occurs for some structures (see example below where only 1 structure presents this issue).\n\n### MatterSim Version\n\n1.2.5\n\n### Python Version\n\n3.12.12\n\n### Reproduction Steps\n\n1. Install dependencies `pip install mattersim==1.2.5`\n2. Run the code below\n3. The second structure should return NaN values when using the TorchSim backend\n\n```py\nimport numpy as np\nimport requests\nimport torch\nfrom mattersim.forcefield.potential import Potential\nfrom pymatgen.core import Structure\n\n\ndef fetch_alexandria_entry(id_string):\n url = f\"https://alexandria.icams.rub.de/pbe/v1/structures/{id_string}\"\n\n response = requests.get(url)\n response.raise_for_status()\n data = response.json()[\"data\"]\n attrs = data[\"attributes\"]\n\n return Structure(\n lattice=attrs[\"lattice_vectors\"],\n species=attrs[\"species_at_sites\"],\n coords=attrs[\"cartesian_site_positions\"],\n coords_are_cartesian=True,\n )\n\n\ndef direct_inference(model, structures):\n from mattersim.datasets.utils.build import build_dataloader\n from pymatgen.io.ase import AseAtomsAdaptor\n\n adapter = AseAtomsAdaptor()\n atoms = [adapter.get_atoms(struct) for struct in structures]\n\n dataloader = build_dataloader(atoms, only_inference=True)\n predictions = model.predict_properties(\n dataloader,\n include_forces=True,\n include_stresses=True,\n )\n\n return predictions\n\n\ndef torchsim_inference(model, structures):\n import torch_sim as ts\n from mattersim.torchsim import get_torchsim_wrapper\n\n device = \"cuda\" if torch.cuda.is_available() else \"cpu\"\n wrapper = get_torchsim_wrapper(model, device=device)\n\n state = ts.static(structures, model=wrapper)\n return state\n\n\ndef main():\n alexandria_ids = [\"agm003221802\", \"agm006228157\"]\n structures = [fetch_alexandria_entry(id) for id in alexandria_ids]\n\n model = Potential.from_checkpoint(\n load_path=\"mattersim-v1.0.0-1M\", load_training_state=False\n )\n\n results = torchsim_inference(model, structures)\n for i in range(len(structures)):\n for key, prop in results[i].items():\n if torch.isnan(prop).any():\n print(f\"NaN value found in {key} for structure {i} (TorchSim)\")\n\n results = direct_inference(model, structures)\n for i in range(len(structures)):\n for key, prop in zip([\"energy\", \"forces\", \"stress\"], results[i]):\n if np.isnan(prop).any():\n print(f\"NaN value found in {key} for structure {i} (ASE)\")\n\n\nif __name__ == \"__main__\":\n main()\n```\n\n### Expected Behavior\n\nI would expect the TorchSim backend to return the same values as `Potential.predict_properties` and to not return NaN values on valid structures.\n\n### Actual Behavior\n\nSome structures will return NaN properties when using TorchSim.\n\n### Error Logs\n\n```python\n\n```\n\n### Code of Conduct\n\n- [x] I agree to follow the project's Code of Conduct","author":{"url":"https://github.com/akwarii","@type":"Person","name":"akwarii"},"datePublished":"2026-06-09T09:47:36.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/162/mattersim/issues/162"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:b76386a8-ae66-e3f9-3106-f67a2c1ed89b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E8BA:3CD7FF:581D5B:7B65A5:6A4BCC93 |
| html-safe-nonce | c692419ee8bb08117a9307a5bf335dbec7288713453fe4297cd6577ebf3bcdf8 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFOEJBOjNDRDdGRjo1ODFENUI6N0I2NUE1OjZBNEJDQzkzIiwidmlzaXRvcl9pZCI6IjQ3MTI0MjMxNDU1Njg4NjE2MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 45f0fcfcdf5268d3bfbe51bde1674b70c7490b5cbb29f78b34d7d78cca30d932 |
| hovercard-subject-tag | issue:4620863512 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/mattersim/162/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3e32304d28e22080732db83a482b6fb2d930d83747dd0de1e752d8a0534e5866/microsoft/mattersim/issues/162 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3e32304d28e22080732db83a482b6fb2d930d83747dd0de1e752d8a0534e5866/microsoft/mattersim/issues/162 |
| og:image:alt | Contact Details gael.huynh@uclouvain.be Bug Description Some structures seems to return NaN when using the TorchSim backend while using Potential.predict_properties works perfectly fine. Note that ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | akwarii |
| hostname | github.com |
| expected-hostname | github.com |
| None | 14aa00ce5bdb34d0eefb5facbffd7de9e144c688d8a93ef8df902d5f94b51dd7 |
| turbo-cache-control | no-preview |
| go-import | github.com/microsoft/mattersim git https://github.com/microsoft/mattersim.git |
| octolytics-dimension-user_id | 6154722 |
| octolytics-dimension-user_login | microsoft |
| octolytics-dimension-repository_id | 853204060 |
| octolytics-dimension-repository_nwo | microsoft/mattersim |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 853204060 |
| octolytics-dimension-repository_network_root_nwo | microsoft/mattersim |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 58b8f89190447502561829f30862aa0a99d53367 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width