Skip to content
Open
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
21 changes: 21 additions & 0 deletions ml_peg/models/get_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ def load_models(
MockCalc,
OrbCalc,
PetMadCalc,
SevenNetCalc,
UPETCalc,
)

if run_mock is None:
Expand Down Expand Up @@ -201,6 +203,25 @@ def load_models(
trained_on_dispersion=cfg.get("trained_on_dispersion", False),
dispersion_kwargs=cfg.get("dispersion_kwargs", {}),
)
case "UPETCalculator":

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we not want to replace PETMADCalculator?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we still use the old model?

@ElliottKasoar ElliottKasoar Jun 9, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be able to, yep, it's the same repo, just renamed. Models available are here: https://github.com/lab-cosmo/upet/blob/main/src/upet/_version.py#L1. You set the version e.g.

calculator = UPETCalculator(model="pet-mad-s", version="1.5.0", device="cuda") but v1.0.2 should also be available based on https://lab-cosmo.github.io/upet/latest/models.html

loaded_models[name] = UPETCalc(
module=cfg["module"],
class_name=cfg["class_name"],
device=cfg.get("device", "cpu"),
default_dtype=cfg.get("overwrite_dtype", None),
kwargs=cfg.get("kwargs", {}),
trained_on_dispersion=cfg.get("trained_on_dispersion", False),
dispersion_kwargs=cfg.get("dispersion_kwargs", {}),
)
case "SevenNetCalculator":
kwargs = cfg.get("kwargs", {})
loaded_models[name] = SevenNetCalc(
model=kwargs["model"],

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to pull this out when the key word is model anyway?

device=cfg.get("device", "cpu"),
kwargs={k: v for k, v in kwargs.items() if k != "model"},
trained_on_dispersion=cfg.get("trained_on_dispersion", False),
dispersion_kwargs=cfg.get("dispersion_kwargs", {}),
)
case _:
loaded_models[name] = GenericASECalc(
module=cfg["module"],
Expand Down
61 changes: 60 additions & 1 deletion ml_peg/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
import dataclasses
from typing import TYPE_CHECKING

from mlipx import GenericASECalculator as MlipxGenericASECalc
from mlipx.nodes.generic_ase import Device

from mlipx import GenericASECalculator as MlipxGenericASECalc

if TYPE_CHECKING:
from ase.calculators.calculator import Calculator
from ase.calculators.mixing import SumCalculator
Expand Down Expand Up @@ -283,3 +284,61 @@ def get_calculator(self, **kwargs) -> Calculator:
from ml_peg.models.mock import MockCalculator

return MockCalculator()


@dataclasses.dataclass(kw_only=True)
class UPETCalc(GenericASECalc):
"""Dataclass for upet (PET-MAD / PET-OAM) calculator."""

def get_calculator(self, precision="high", **kwargs) -> Calculator:
"""
Prepare and load the calculator.

Parameters
----------
precision
Level of precision to evaluate the model.
**kwargs
Any keyword arguments to pass to `get_calculator`.

Returns
-------
Calculator
Loaded upet ASE calculator.
"""
precision_map = {"low": "float32", "high": "float64"}
kwargs["dtype"] = precision_map[precision]

if self.default_dtype is not None:
kwargs["dtype"] = self.default_dtype

return MlipxGenericASECalc.get_calculator(self, **kwargs)


@dataclasses.dataclass(kw_only=True)
class SevenNetCalc(SumCalc):
"""Dataclass for SevenNet calculator."""

model: str
device: Device | None = None
kwargs: dict = dataclasses.field(default_factory=dict)

def get_calculator(self, **kwargs) -> Calculator:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work when we set precision? I don't think they've implemented anything yet (MDIL-SNU/SevenNet#138), and then precision will get passed to SevenNetCalculator

"""
Prepare and load the calculator.

Parameters
----------
**kwargs
Additional keyword arguments (ignored).

Returns
-------
Calculator
Loaded SevenNet ASE calculator.
"""
from sevenn.sevennet_calculator import SevenNetCalculator

device = Device.resolve_auto() if self.device == Device.AUTO else self.device
device_str = device.value if isinstance(device, Device) else (device or "cpu")
return SevenNetCalculator(model=self.model, device=device_str, **self.kwargs)
39 changes: 39 additions & 0 deletions ml_peg/models/models.yml
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,45 @@ pet-mad:
dispersion_kwargs:
xc: pbesol

pet-mad-1.5-s:
module: upet.calculator
class_name: UPETCalculator
device: "cpu"
trained_on_dispersion: false
level_of_theory: r2SCAN
kwargs:
model: "pet-mad-s"
version: "1.5.0"

pet-oam-xl:
module: upet.calculator
class_name: UPETCalculator
device: "cpu"
trained_on_dispersion: False
level_of_theory: PBE
kwargs:
model: "pet-oam-xl"
version: "1.0.0"

sevennet-l3i5:
module: sevenn.sevennet_calculator
class_name: SevenNetCalculator
device: "cpu"
trained_on_dispersion: false
level_of_theory: PBE
kwargs:
model: "7net-l3i5"

sevennet-omni-i12-mpa:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this one? From their list, the standard omni is recommended?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the one they submitted recently to matbench discovery so i assume its their model of choice. strange that one is reccomended. hmm we can discuss

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm odd

module: sevenn.sevennet_calculator
class_name: SevenNetCalculator
device: "cpu"
trained_on_dispersion: false
level_of_theory: PBE
kwargs:
model: "7net-omni"
modal: "mpa"

# mace-polar-1-s:
# module: mace.calculators
# class_name: mace_polar
Expand Down
10 changes: 10 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ pet-mad = [
uma = [
"fairchem-core == 2.19.0; python_version >= '3.11'",
]
upet = [

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we just want to replace pet-mad? It's essentially the same repo

"upet",
]
sevenn = [
"sevenn",
Comment on lines +77 to +80

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would pin these so we know exactly what version we are using, and can rely on their interfaces

]

[project.scripts]
ml_peg = "ml_peg.cli.cli:app"
Expand Down Expand Up @@ -206,6 +212,10 @@ conflicts = [
{ extra = "mattersim" },
{ extra = "grace" },
],
[
{ extra = "pet-mad" },
{ extra = "upet" },
],
]

constraint-dependencies = [
Expand Down
Loading
Loading