Skip to content

Commit f53ce49

Browse files
HaoZekeCompRhysLuthaf
committed
Create a metatomic-torchsim package
It will hold the TorchSim <=> metatomic integration as a standalone module. Co-Authored-By: Rhys Goodall <rhys.goodall@outlook.com> Co-Authored-By: Guillaume Fraux <guillaume.fraux@epfl.ch>
1 parent a06e5b2 commit f53ce49

24 files changed

Lines changed: 1206 additions & 21 deletions

File tree

.github/workflows/build-wheels.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,9 @@ jobs:
207207
- name: build metatomic sdist and wheel
208208
run: python -m build . --outdir=dist/
209209

210+
- name: build metatomic_torchsim sdist and wheel
211+
run: python -m build python/metatomic_torchsim --outdir=dist/
212+
210213
- name: check sdist and wheels with twine
211214
run: twine check dist/*.tar.gz dist/*.whl
212215

@@ -279,6 +282,16 @@ jobs:
279282
env:
280283
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
281284

285+
- name: upload to GitHub release (metatomic-torchsim)
286+
if: startsWith(github.ref, 'refs/tags/metatomic-torchsim-v')
287+
uses: softprops/action-gh-release@v2
288+
with:
289+
files: |
290+
wheels/metatomic_torchsim-*
291+
prerelease: ${{ contains(github.ref, '-rc') }}
292+
env:
293+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
294+
282295
test-build-external:
283296
# This checks building the wheels with external libraries. This setup is
284297
# mainly used for the conda packages metatensor-*-python, which use the

.github/workflows/torch-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ jobs:
6464
python -m pip install tox coverage
6565
6666
- name: run tests
67-
run: tox
67+
run: tox -e lint,torch-tests,torch-tests-cxx,torch-install-tests-cxx,docs-tests
6868
env:
6969
PIP_EXTRA_INDEX_URL: https://download.pytorch.org/whl/cpu
7070
METATOMIC_TESTS_TORCH_VERSION: ${{ matrix.torch-version }}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: TorchSim integration
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
# Check all PR
8+
9+
concurrency:
10+
group: torchsim-tests-${{ github.ref }}
11+
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
12+
13+
jobs:
14+
tests:
15+
runs-on: ubuntu-24.04
16+
name: tests
17+
steps:
18+
- uses: actions/checkout@v6
19+
with:
20+
fetch-depth: 0
21+
22+
- name: setup Python
23+
uses: actions/setup-python@v6
24+
with:
25+
python-version: "3.13"
26+
27+
- name: Setup sccache
28+
uses: mozilla-actions/sccache-action@v0.0.9
29+
with:
30+
version: "v0.10.0"
31+
32+
- name: Setup sccache environnement variables
33+
run: |
34+
echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV
35+
echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV
36+
echo "CMAKE_C_COMPILER_LAUNCHER=sccache" >> $GITHUB_ENV
37+
echo "CMAKE_CXX_COMPILER_LAUNCHER=sccache" >> $GITHUB_ENV
38+
39+
- name: install tests dependencies
40+
run: |
41+
python -m pip install --upgrade pip
42+
python -m pip install tox coverage
43+
44+
- name: run tests
45+
run: tox -e torchsim-tests
46+
env:
47+
PIP_EXTRA_INDEX_URL: https://download.pytorch.org/whl/cpu
48+
49+
- name: combine Python coverage files
50+
shell: bash
51+
run: |
52+
coverage combine .tox/*/.coverage
53+
coverage xml
54+
55+
- name: upload to codecov.io
56+
uses: codecov/codecov-action@v5
57+
with:
58+
fail_ci_if_error: true
59+
files: coverage.xml
60+
token: ${{ secrets.CODECOV_TOKEN }}

docs/src/conf.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,16 +171,17 @@ def setup(app):
171171
"python": ("https://docs.python.org/3", None),
172172
"numpy": ("https://numpy.org/doc/stable/", None),
173173
"torch": ("https://docs.pytorch.org/docs/stable/", None),
174-
"featomic": ("https://metatensor.github.io/featomic/latest/", None),
174+
"featomic": ("http://docs.metatensor.org/featomic/latest/", None),
175175
"metatensor": ("https://docs.metatensor.org/latest/", None),
176176
"ase": ("https://ase-lib.org/", None),
177177
"matplotlib": ("https://matplotlib.org/stable/", None),
178+
"torch_sim": ("https://torchsim.github.io/torch-sim/", None),
178179
}
179180

180181
# sitemap/SEO settings
181-
html_baseurl = "https://docs.metatensor.org/metatomic/latest/" # prefix for the sitemap
182-
sitemap_url_scheme = "{link}" # avoids language settings
183-
html_extra_path = ["robots.txt"] # extra files to move
182+
html_baseurl = "https://docs.metatensor.org/metatomic/latest/" # prefix for the sitemap
183+
sitemap_url_scheme = "{link}" # avoids language settings
184+
html_extra_path = ["robots.txt"] # extra files to move
184185

185186
# -- Options for HTML output -------------------------------------------------
186187

docs/src/engines/torch-sim.rst

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,48 @@ torch-sim
88

99
* - Official website
1010
- How is metatomic supported?
11-
* - https://radical-ai.github.io/torch-sim/
12-
- In the official version
11+
* - https://torchsim.github.io/torch-sim/
12+
- Via the ``metatomic-torchsim`` package
1313

14-
Supported model outputs
14+
How to install the code
1515
^^^^^^^^^^^^^^^^^^^^^^^
1616

17-
Only the :ref:`energy <energy-output>` output is supported.
17+
Install the integration package from PyPI:
1818

19-
How to install the code
19+
.. code-block:: bash
20+
21+
pip install metatomic-torchsim
22+
23+
For the full TorchSim documentation, see https://torchsim.github.io/torch-sim/.
24+
25+
Supported model outputs
2026
^^^^^^^^^^^^^^^^^^^^^^^
2127

22-
The code is available in the ``torch-sim`` package, see the corresponding
23-
`installation instructions <https://radical-ai.github.io/torch-sim/user/introduction.html#installation>`_.
28+
Only the :ref:`energy <energy-output>` output is supported. Forces and stresses
29+
are derived via autograd.
2430

2531
How to use the code
2632
^^^^^^^^^^^^^^^^^^^
2733

28-
You can find the documentation for metatomic models in torch-sim `here
29-
<https://radical-ai.github.io/torch-sim/tutorials/metatomic_tutorial.html>`_,
30-
and generic documentation on torch-sim `there
31-
<radical-ai.github.io/torch-sim/>`_.
34+
.. code-block:: python
35+
36+
import ase.build
37+
import torch_sim as ts
38+
from metatomic_torchsim import MetatomicModel
39+
40+
model = MetatomicModel("model.pt", device="cpu")
41+
42+
atoms = ase.build.bulk("Si", "diamond", a=5.43, cubic=True)
43+
sim_state = ts.initialize_state(atoms, device=model.device, dtype=model.dtype)
44+
45+
results = model(sim_state)
46+
print(results["energy"]) # shape [1]
47+
print(results["forces"]) # shape [n_atoms, 3]
48+
print(results["stress"]) # shape [1, 3, 3]
49+
50+
API documentation
51+
-----------------
52+
53+
.. autoclass:: metatomic_torchsim.MetatomicModel
54+
:show-inheritance:
55+
:members:

docs/src/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ This library focuses on exporting and importing fully working, already trained
1717
models. If you want to train existing architectures with new data or re-use
1818
existing trained models, look into the metatrain_ project instead.
1919

20-
.. _metatrain: https://github.com/lab-cosmo/metatrain
20+
.. _metatrain: https://github.com/metatensor/metatrain
2121

2222
.. grid::
2323

metatomic-torch/CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ a changelog](https://keepachangelog.com/en/1.1.0/) format. This project follows
55
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
<!-- Possible sections for each package:
8-
98
### Added
109
1110
### Fixed

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ filterwarnings = [
6767
"ignore:`torch.jit.script` is deprecated. Please switch to `torch.compile` or `torch.export`:DeprecationWarning",
6868
"ignore:`torch.jit.save` is deprecated. Please switch to `torch.export`:DeprecationWarning",
6969
"ignore:.*vesin.metatomic was only tested with metatomic.torch >=0.1.3,<0.2.*:UserWarning",
70+
"ignore:`torch.jit.load` is deprecated. Please switch to `torch.export`.:DeprecationWarning",
7071
]
7172

7273
### ======================================================================== ###
@@ -77,7 +78,7 @@ ignore = ["B018", "B904"]
7778

7879
[tool.ruff.lint.isort]
7980
lines-after-imports = 2
80-
known-first-party = ["metatomic"]
81+
known-first-party = ["metatomic", "metatomic_torchsim", "metatomic_lj_test"]
8182
known-third-party = ["torch"]
8283

8384
[tool.ruff.format]
@@ -88,4 +89,5 @@ docstring-code-format = true
8889
[tool.uv.pip]
8990
reinstall-package = [
9091
"metatomic-torch",
92+
"metatomic-torchsim",
9193
]

python/metatomic_torch/pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,10 @@ python_files = ["*.py"]
5858
testpaths = ["tests"]
5959
filterwarnings = [
6060
"error",
61+
# TorchScript deprecation warnings
6162
"ignore:`torch.jit.script` is deprecated. Please switch to `torch.compile` or `torch.export`:DeprecationWarning",
6263
"ignore:`torch.jit.save` is deprecated. Please switch to `torch.export`:DeprecationWarning",
6364
"ignore:`torch.jit.load` is deprecated. Please switch to `torch.export`:DeprecationWarning",
65+
# There is a circular dependency between metatomic-torch and vesin.metatomic
6466
"ignore:.*vesin.metatomic was only tested with metatomic.torch >=0.1.3,<0.2.*:UserWarning",
6567
]

python/metatomic_torch/tests/ase_calculator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
import ase.calculators.lj
1010
import ase.md
1111
import ase.units
12-
import metatomic_lj_test
1312
import numpy as np
1413
import pytest
1514
import torch
1615
from ase.calculators.calculator import PropertyNotImplementedError
1716
from ase.md.velocitydistribution import MaxwellBoltzmannDistribution
1817
from metatensor.torch import Labels, TensorBlock, TensorMap
1918

19+
import metatomic_lj_test
2020
from metatomic.torch import (
2121
AtomisticModel,
2222
ModelCapabilities,

0 commit comments

Comments
 (0)