Skip to content

Commit e3a1711

Browse files
authored
metatensor models have been renamed to metatomic models (#205)
1 parent 2c3a862 commit e3a1711

File tree

10 files changed

+105
-105
lines changed

10 files changed

+105
-105
lines changed

.github/workflows/docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
uv pip install ".[test,docs]" --system
3535
3636
- name: Install extras for tutorial generation
37-
run: uv pip install ".[graphpes,mace,metatensor]" --system
37+
run: uv pip install ".[graphpes,mace,metatomic]" --system
3838

3939
- name: Copy tutorials
4040
run: |

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
--ignore=tests/models/test_orb.py \
5050
--ignore=tests/models/test_sevennet.py \
5151
--ignore=tests/models/test_mattersim.py \
52-
--ignore=tests/models/test_metatensor.py \
52+
--ignore=tests/models/test_metatomic.py \
5353
--ignore=tests/test_optimizers_vs_ase.py \
5454
5555
- name: Upload coverage to Codecov
@@ -73,7 +73,7 @@ jobs:
7373
- { name: mace, test_path: "tests/test_elastic.py" }
7474
- { name: mace, test_path: "tests/test_optimizers_vs_ase.py" }
7575
- { name: mattersim, test_path: "tests/models/test_mattersim.py" }
76-
- { name: metatensor, test_path: "tests/models/test_metatensor.py" }
76+
- { name: metatomic, test_path: "tests/models/test_metatomic.py" }
7777
- { name: orb, test_path: "tests/models/test_orb.py" }
7878
- { name: sevenn, test_path: "tests/models/test_sevennet.py" }
7979
runs-on: ${{ matrix.os }}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ era. By rewriting the core primitives of atomistic simulation in Pytorch, it all
1414
orders of magnitude acceleration of popular machine learning potentials.
1515

1616
* Automatic batching and GPU memory management allowing significant simulation speedup
17-
* Support for MACE, Fairchem, SevenNet, ORB, MatterSim, graph-pes, and metatensor MLIP models
17+
* Support for MACE, Fairchem, SevenNet, ORB, MatterSim, graph-pes, and metatomic MLIP models
1818
* Support for classical lennard jones, morse, and soft-sphere potentials
1919
* Molecular dynamics integration schemes like NVE, NVT Langevin, and NPT Langevin
2020
* Relaxation of atomic positions and cell with gradient descent and FIRE

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
"fairchem",
6767
"mace",
6868
"mattersim",
69-
"metatensor",
69+
"metatomic",
7070
"orb",
7171
"sevennet",
7272
"graphpes",

docs/tutorials/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ versions of the tutorials can also be found in the `torch-sim /examples/tutorial
1919
low_level_tutorial
2020
hybrid_swap_tutorial
2121
using_graphpes_tutorial
22-
metatensor_tutorial
22+
metatomic_tutorial

examples/tutorials/metatensor_tutorial.py renamed to examples/tutorials/metatomic_tutorial.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
# <summary>Dependencies</summary>
44
# /// script
55
# dependencies = [
6-
# "metatrain[pet]==2025.6",
7-
# "metatensor-torch==0.7.6"
6+
# "metatrain[pet]==2025.7",
7+
# "metatomic-torch>=0.1.1,<0.2"
88
# ]
99
# ///
1010
# </details>
1111

1212

1313
# %% [markdown]
1414
"""
15-
# Using the PET-MAD model with metatensor
15+
# Using the PET-MAD model with TorchSim
1616
1717
This tutorial explains how to use the PET-MAD model (https://arxiv.org/abs/2503.14118)
18-
via TorchSim's metatensor interface.
18+
via TorchSim's metatomic interface.
1919
2020
## Loading the model
2121
@@ -26,9 +26,9 @@
2626
"""
2727

2828
# %%
29-
from torch_sim.models.metatensor import MetatensorModel
29+
from torch_sim.models.metatomic import MetatomicModel
3030

31-
model = MetatensorModel("pet-mad")
31+
model = MetatomicModel("pet-mad")
3232

3333
# %% [markdown]
3434
"""
@@ -68,6 +68,6 @@
6868
6969
Of course, in reality, you would want to run the simulation for much longer, probably
7070
save trajectories, and much more. However, this is all you need to get started with
71-
metatensor and PET-MAD. For more details on how to use TorchSim, you can refer to the
71+
metatomic and PET-MAD. For more details on how to use TorchSim, you can refer to the
7272
other tutorials in this section.
7373
"""

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ dependencies = [
3232
"tables>=3.10.2",
3333
"torch>=2",
3434
"tqdm>=4.67",
35-
"vesin-torch>=0.3.1",
36-
"vesin>=0.3.1",
35+
"vesin-torch>=0.3.7",
36+
"vesin>=0.3.7",
3737
]
3838

3939
[project.optional-dependencies]
@@ -48,7 +48,7 @@ test = [
4848
io = ["ase>=3.24", "phonopy>=2.37.0", "pymatgen>=2024.11.3"]
4949
mace = ["mace-torch>=0.3.12"]
5050
mattersim = ["mattersim>=0.1.2"]
51-
metatensor = ["metatensor-torch==0.7.6", "metatrain[pet]==2025.6"]
51+
metatomic = ["metatomic-torch>=0.1.1,<0.2", "metatrain[pet]==2025.7"]
5252
orb = ["orb-models>=0.5.2"]
5353
sevenn = ["sevenn>=0.11.0"]
5454
graphpes = ["graph-pes>=0.0.34", "mace-torch>=0.3.12"]

tests/models/test_metatensor.py

Lines changed: 0 additions & 66 deletions
This file was deleted.

tests/models/test_metatomic.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import pytest
2+
import torch
3+
4+
from tests.models.conftest import (
5+
consistency_test_simstate_fixtures,
6+
make_model_calculator_consistency_test,
7+
make_validate_model_outputs_test,
8+
)
9+
10+
11+
try:
12+
from metatomic.torch import ase_calculator
13+
from metatrain.utils.io import load_model
14+
15+
from torch_sim.models.metatomic import MetatomicModel
16+
except ImportError:
17+
pytest.skip("metatomic not installed", allow_module_level=True)
18+
19+
20+
@pytest.fixture
21+
def dtype() -> torch.dtype:
22+
"""Fixture to provide the default dtype for testing."""
23+
return torch.float32
24+
25+
26+
@pytest.fixture
27+
def metatomic_calculator(device: torch.device):
28+
"""Load a pretrained metatomic model for testing."""
29+
return ase_calculator.MetatomicCalculator(
30+
model=load_model(
31+
"https://huggingface.co/lab-cosmo/pet-mad/resolve/main/models/pet-mad-latest.ckpt"
32+
).export(),
33+
device=device,
34+
)
35+
36+
37+
@pytest.fixture
38+
def metatomic_model(device: torch.device) -> MetatomicModel:
39+
"""Create an MetatomicModel wrapper for the pretrained model."""
40+
return MetatomicModel(
41+
model="pet-mad",
42+
device=device,
43+
)
44+
45+
46+
def test_metatomic_initialization(device: torch.device) -> None:
47+
"""Test that the metatomic model initializes correctly."""
48+
model = MetatomicModel(
49+
model="pet-mad",
50+
device=device,
51+
)
52+
assert model.device == device
53+
assert model.dtype == torch.float32
54+
55+
56+
test_metatomic_consistency = make_model_calculator_consistency_test(
57+
test_name="metatomic",
58+
model_fixture_name="metatomic_model",
59+
calculator_fixture_name="metatomic_calculator",
60+
sim_state_names=consistency_test_simstate_fixtures,
61+
energy_atol=5e-5,
62+
)
63+
64+
test_metatomic_model_outputs = make_validate_model_outputs_test(
65+
model_fixture_name="metatomic_model",
66+
)

torch_sim/models/metatensor.py renamed to torch_sim/models/metatomic.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
"""Wrapper for metatensor-based models in TorchSim.
1+
"""Wrapper for metatomic-based models in TorchSim.
22
3-
This module provides a TorchSim wrapper of metatensor models for computing
3+
This module provides a TorchSim wrapper of metatomic models for computing
44
energies, forces, and stresses for atomistic systems, including batched computations
55
for multiple systems simultaneously.
66
7-
The MetatensorModel class adapts metatensor models to the ModelInterface protocol,
7+
The MetatomicModel class adapts metatomic models to the ModelInterface protocol,
88
allowing them to be used within the broader torch_sim simulation framework.
99
1010
Notes:
11-
This module depends on the metatensor-torch package.
11+
This module depends on the metatomic-torch package.
1212
"""
1313

1414
import traceback
@@ -17,15 +17,15 @@
1717
from typing import Any
1818

1919
import torch
20-
import vesin.torch.metatensor
20+
import vesin.metatomic
2121

2222
import torch_sim as ts
2323
from torch_sim.models.interface import ModelInterface
2424
from torch_sim.typing import StateDict
2525

2626

2727
try:
28-
from metatensor.torch.atomistic import (
28+
from metatomic.torch import (
2929
ModelEvaluationOptions,
3030
ModelOutput,
3131
System,
@@ -34,27 +34,27 @@
3434
from metatrain.utils.io import load_model
3535

3636
except ImportError as exc:
37-
warnings.warn(f"Metatensor import failed: {traceback.format_exc()}", stacklevel=2)
37+
warnings.warn(f"Metatomic import failed: {traceback.format_exc()}", stacklevel=2)
3838

39-
class MetatensorModel(torch.nn.Module, ModelInterface):
40-
"""Metatensor model wrapper for torch_sim.
39+
class MetatomicModel(torch.nn.Module, ModelInterface):
40+
"""Metatomic model wrapper for torch_sim.
4141
42-
This class is a placeholder for the MetatensorModel class.
43-
It raises an ImportError if metatensor is not installed.
42+
This class is a placeholder for the MetatomicModel class.
43+
It raises an ImportError if metatomic is not installed.
4444
"""
4545

4646
def __init__(self, err: ImportError = exc, *_args: Any, **_kwargs: Any) -> None:
4747
"""Dummy init for type checking."""
4848
raise err
4949

5050

51-
class MetatensorModel(torch.nn.Module, ModelInterface):
52-
"""Computes energies for a list of systems using a metatensor model.
51+
class MetatomicModel(torch.nn.Module, ModelInterface):
52+
"""Computes energies for a list of systems using a metatomic model.
5353
54-
This class wraps a metatensor model to compute energies, forces, and stresses for
54+
This class wraps a metatomic model to compute energies, forces, and stresses for
5555
atomic systems within the TorchSim framework. It supports batched calculations
5656
for multiple systems and handles the necessary transformations between
57-
TorchSim's data structures and metatensor's expected inputs.
57+
TorchSim's data structures and metatomic's expected inputs.
5858
5959
Attributes:
6060
...
@@ -70,14 +70,14 @@ def __init__(
7070
compute_forces: bool = True,
7171
compute_stress: bool = True,
7272
) -> None:
73-
"""Initialize the metatensor model for energy, force and stress calculations.
73+
"""Initialize the metatomic model for energy, force and stress calculations.
7474
75-
Sets up a metatensor model for energy, force, and stress calculations within
75+
Sets up a metatomic model for energy, force, and stress calculations within
7676
the TorchSim framework. The model can be initialized with atomic numbers
7777
and batch indices, or these can be provided during the forward pass.
7878
7979
Args:
80-
model (str | Path | None): Path to the metatensor model file or a
80+
model (str | Path | None): Path to the metatomic model file or a
8181
pre-defined model name. Currently only "pet-mad"
8282
(https://arxiv.org/abs/2503.14118) is supported as a pre-defined model.
8383
If None, defaults to "pet-mad".
@@ -155,7 +155,7 @@ def forward( # noqa: C901, PLR0915
155155
"""Compute energies, forces, and stresses for the given atomic systems.
156156
157157
Processes the provided state information and computes energies, forces, and
158-
stresses using the underlying metatensor model. Handles batched calculations for
158+
stresses using the underlying metatomic model. Handles batched calculations for
159159
multiple systems as well as constructing the necessary neighbor lists.
160160
161161
Args:
@@ -175,21 +175,21 @@ def forward( # noqa: C901, PLR0915
175175
state = ts.SimState(**state, masses=torch.ones_like(state["positions"]))
176176

177177
# Input validation is already done inside the forward method of the
178-
# MetatensorAtomisticModel class, so we don't need to do it again here.
178+
# AtomisticModel class, so we don't need to do it again here.
179179

180180
atomic_numbers = state.atomic_numbers
181181
cell = state.row_vector_cell
182182
positions = state.positions
183183
pbc = state.pbc
184184

185-
# Check dtype (metatensor models require a specific input dtype)
185+
# Check dtype (metatomic models require a specific input dtype)
186186
if positions.dtype != self._dtype:
187187
raise TypeError(
188188
f"Positions dtype {positions.dtype} does not match model dtype "
189189
f"{self._dtype}"
190190
)
191191

192-
# Compared to other models, metatensor models have two peculiarities:
192+
# Compared to other models, metatomic models have two peculiarities:
193193
# - different structures are fed to the models separately as a list of System
194194
# objects, and not as a single graph-like batch
195195
# - the model does not compute forces and stresses itself, but rather the
@@ -232,7 +232,7 @@ def forward( # noqa: C901, PLR0915
232232

233233
# move data to CPU because vesin only supports CPU for now
234234
systems = [system.to(device="cpu") for system in systems]
235-
vesin.torch.metatensor.compute_requested_neighbors(
235+
vesin.metatomic.compute_requested_neighbors(
236236
systems, system_length_unit="Angstrom", model=self._model
237237
)
238238
# move back to the proper device

0 commit comments

Comments
 (0)