-
Notifications
You must be signed in to change notification settings - Fork 49
Add upet and sevennet models #591
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -141,6 +141,8 @@ def load_models( | |
| MockCalc, | ||
| OrbCalc, | ||
| PetMadCalc, | ||
| SevenNetCalc, | ||
| UPETCalc, | ||
| ) | ||
|
|
||
| if run_mock is None: | ||
|
|
@@ -201,6 +203,25 @@ def load_models( | |
| trained_on_dispersion=cfg.get("trained_on_dispersion", False), | ||
| dispersion_kwargs=cfg.get("dispersion_kwargs", {}), | ||
| ) | ||
| case "UPETCalculator": | ||
| 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"], | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"], | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -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: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| """ | ||
| 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) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why this one? From their list, the standard omni is recommended?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -73,6 +73,12 @@ pet-mad = [ | |
| uma = [ | ||
| "fairchem-core == 2.19.0; python_version >= '3.11'", | ||
| ] | ||
| upet = [ | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||
|
|
@@ -206,6 +212,10 @@ conflicts = [ | |
| { extra = "mattersim" }, | ||
| { extra = "grace" }, | ||
| ], | ||
| [ | ||
| { extra = "pet-mad" }, | ||
| { extra = "upet" }, | ||
| ], | ||
| ] | ||
|
|
||
| constraint-dependencies = [ | ||
|
|
||
There was a problem hiding this comment.
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?There was a problem hiding this comment.
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?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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