Skip to content

Import metatensor.torch as mts #675

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/metatrain/deprecated/pet/model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Any, Dict, List, Literal, Optional

import metatensor.torch
import metatensor.torch as mts
import torch
from metatensor.torch import Labels, TensorBlock, TensorMap
from metatomic.torch import (
Expand Down Expand Up @@ -219,7 +219,7 @@ def forward(
values=predictions,
)
if selected_atoms is not None:
block = metatensor.torch.slice_block(block, "samples", selected_atoms)
block = mts.slice_block(block, "samples", selected_atoms)
output_tmap = TensorMap(keys=empty_labels, blocks=[block])
if not outputs[output_name].per_atom:
output_tmap = sum_over_atoms(output_tmap)
Expand All @@ -238,7 +238,7 @@ def forward(
selected_atoms,
)
for output_name in additive_contributions:
output_quantities[output_name] = metatensor.torch.add(
output_quantities[output_name] = mts.add(
output_quantities[output_name],
additive_contributions[output_name],
)
Expand Down
6 changes: 3 additions & 3 deletions src/metatrain/experimental/nanopet/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from math import prod
from typing import Any, Dict, List, Literal, Optional

import metatensor.torch
import metatensor.torch as mts
import torch
from metatensor.torch import Labels, TensorBlock, TensorMap
from metatomic.torch import (
Expand Down Expand Up @@ -517,7 +517,7 @@ def forward(

if selected_atoms is not None:
for output_name, tmap in atomic_properties_tmap_dict.items():
atomic_properties_tmap_dict[output_name] = metatensor.torch.slice(
atomic_properties_tmap_dict[output_name] = mts.slice(
tmap, axis="samples", selection=selected_atoms
)

Expand All @@ -541,7 +541,7 @@ def forward(
selected_atoms,
)
for name in additive_contributions:
return_dict[name] = metatensor.torch.add(
return_dict[name] = mts.add(
return_dict[name],
additive_contributions[name],
)
Expand Down
12 changes: 4 additions & 8 deletions src/metatrain/experimental/nanopet/tests/test_functionality.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import metatensor.torch
import metatensor.torch as mts
import pytest
import torch
from jsonschema.exceptions import ValidationError
Expand Down Expand Up @@ -152,7 +152,7 @@ def test_prediction_subset_atoms():
system_far_away_dimer, model.requested_neighbor_lists()
)

selection_labels = metatensor.torch.Labels(
selection_labels = mts.Labels(
names=["system", "atom"],
values=torch.tensor([[0, 0], [0, 2], [0, 3]]),
)
Expand All @@ -168,13 +168,9 @@ def test_prediction_subset_atoms():
selected_atoms=selection_labels,
)

assert not metatensor.torch.allclose(
energy_monomer["energy"], energy_dimer["energy"]
)
assert not mts.allclose(energy_monomer["energy"], energy_dimer["energy"])

assert metatensor.torch.allclose(
energy_monomer["energy"], energy_monomer_in_dimer["energy"]
)
assert mts.allclose(energy_monomer["energy"], energy_monomer_in_dimer["energy"])

torch.set_default_dtype(default_dtype_before)

Expand Down
Loading