Skip to content

Upstream metatomic TorchSim model#167

Open
CompRhys wants to merge 18 commits intometatensor:mainfrom
CompRhys:main
Open

Upstream metatomic TorchSim model#167
CompRhys wants to merge 18 commits intometatensor:mainfrom
CompRhys:main

Conversation

@CompRhys
Copy link

Move the torchsim model upstream.

@Luthaf
Copy link
Member

Luthaf commented Feb 26, 2026

Thanks @CompRhys! We had a chat about this 1h ago, and plan to create a separate metatomic-torchsim (and metatomic-ase, …) python package that would live in this repository but have a separate version number and release schedule. This might take us a couple of weeks to do, how urgent is getting this code out of torchsim for you?

@HaoZeke in the mean time can you help bringing this PR in a state where it supports all the same features as the other engine integrations?

@HaoZeke
Copy link
Member

HaoZeke commented Feb 26, 2026

Thanks @CompRhys! We had a chat about this 1h ago, and plan to create a separate metatomic-torchsim (and metatomic-ase, …) python package that would live in this repository but have a separate version number and release schedule. This might take us a couple of weeks to do, how urgent is getting this code out of torchsim for you?

In the same vein, @CompRhys, would you be OK with me making changes to this PR? I'd like to setup the python package first.

@HaoZeke in the mean time can you help bringing this PR in a state where it supports all the same features as the other engine integrations?

Yup, in the package 😁

@CompRhys
Copy link
Author

Not urgent. We just cut a 0.5.2 release and so will be a while till we cut 0.5.3. Hopefully this could land in that release. The big switch also relies on there being new releases with the upstreamed interfaces for orb-models and sevenn.

Please feel free to take this over or delete!

CompRhys and others added 6 commits March 1, 2026 22:46
Introduces the metatomic-torchsim package at python/metatomic_torchsim/,
providing a ModelInterface adapter that bridges metatomic's list-of-System
convention to TorchSim's batched SimState. Supports all model loading
paths (.pt, .ckpt, pet-mad, AtomisticModel, ScriptModule), autograd
forces, strain-trick stress, and vesin/nvalchemi neighbor lists.

Adds root extras_require["torchsim"] pointing to the subpackage.
Covers initialization, forward pass (energy/forces/stress), batching,
batch consistency, forces sum to zero, StateDict input, wrong dtype
error, model loading paths (.pt file, bad path, wrong type, non-
AtomisticModel ScriptModule), single-atom system, energy-only mode,
check_consistency flag, finite-difference force validation, and stress
tensor symmetry.
Adds build-metatomic-torchsim (wheel build), torchsim-tests (pytest
with LJ test model), and torchsim-docs (Sphinx with shibuya theme).
Sphinx docs with shibuya theme, MyST markdown, and autoapi. Follows
Diataxis structure: getting started tutorial, how-to guides for model
loading and batched simulations, architecture explanation, and
auto-generated API reference. Includes changelog via MyST include
directive.
Points to the standalone metatomic-torchsim package with install
instructions and a minimal usage snippet.
@HaoZeke HaoZeke requested a review from Luthaf March 2, 2026 01:55
HaoZeke and others added 4 commits March 2, 2026 03:22
Make metatrain and torch_sim imports optional in torchsim module so
docs-tests can collect doctests without crashing on missing deps.
Guard test imports and skip when dependencies are unavailable.
Fix ruff formatting (quotes, blank lines, line wrapping).
Add test_torchsim.py with 20 tests exercising the inline
MetatomicModel wrapper using the LJ test model (no metatrain needed).
Coverage is collected separately and combined with torch-tests by the
CI coverage combine step.

Also accept AtomisticModel and ScriptModule instances directly in
MetatomicModel.__init__, matching the standalone package and ASE
calculator APIs.
Two issues: (1) torch-sim-atomistic requires Python >= 3.11 but the
torchsim-torch-tests env was in the default envlist, failing on Python
3.10 matrix entries. (2) Batch tests used systems with different atom
counts (32 vs 4) which the LJ test model cannot handle.

Remove torchsim-torch-tests from the default tox envlist and run it as
a separate CI step gated on Python >= 3.11. Fix batch tests to use
same-sized supercells (different lattice parameters) instead of mixing
supercell with unit cell.
@CompRhys
Copy link
Author

CompRhys commented Mar 3, 2026

We decided to drop support for StateDict, I am confused about why there are two implementations so removed it from both both lmk if there are any issues

CompRhys and others added 2 commits March 3, 2026 09:25
Remove the inline torchsim wrapper from metatomic-torch entirely. Engine
wrappers belong in standalone packages (metatomic-torchsim), not inside
the core package. Deletes the module, tests, tox env, and CI step.

Also cleans up the residual dict-to-SimState fallback in the standalone
package forward() method and fixes batch tests to use same-sized
supercells (the LJ test model cannot batch different-sized systems).
@HaoZeke
Copy link
Member

HaoZeke commented Mar 3, 2026

We decided to drop support for StateDict, I am confused about why there are two implementations so removed it from both both lmk if there are any issues

Sorry about that, the inline one should have been removed, since we now split into the standalone metatomic-torchsim. I think we should be able to merge this next week or so.

@HaoZeke HaoZeke marked this pull request as ready for review March 3, 2026 23:43
@CompRhys
Copy link
Author

CompRhys commented Mar 4, 2026

Thanks! look's great please let me know if there's anything I can help with.

HaoZeke added 2 commits March 4, 2026 12:10
Torch 2.10 changed torch.jit.save to always pass _extra_files to
m.save(), even when empty. AtomisticModel.save() did not accept this
kwarg, causing TypeError on macOS CI.

Accept **kwargs in AtomisticModel.save() for forward compatibility.
Use lj_model.save() directly in torchsim test instead of torch.jit.save.
torchsim-tests ran pytest without --cov, so 414 lines of _calculator.py
showed as 0% covered in codecov, dropping project below the 75% threshold.
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.

3 participants