-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #328 from apax-hub/dynamics_checks
added uncertainty checks to jax md
- Loading branch information
Showing
7 changed files
with
173 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from typing import Literal, Union | ||
|
||
import jax.numpy as jnp | ||
from pydantic import BaseModel, TypeAdapter | ||
|
||
|
||
class DynamicsCheckBase(BaseModel): | ||
def check(self, predictions): | ||
pass | ||
|
||
|
||
class EnergyUncertaintyCheck(DynamicsCheckBase, extra="forbid"): | ||
name: Literal["energy_uncertainty"] = "energy_uncertainty" | ||
threshold: float | ||
per_atom: bool = True | ||
|
||
def check(self, predictions): | ||
if "energy_uncertainty" not in predictions.keys(): | ||
m = "No energy uncertainty found. Are you using a model ensemble?" | ||
raise ValueError(m) | ||
|
||
energy_uncertainty = predictions["energy_uncertainty"] | ||
if self.per_atom: | ||
n_atoms = predictions["forces"].shape[0] | ||
energy_uncertainty = energy_uncertainty / n_atoms | ||
|
||
check_passed = jnp.all(energy_uncertainty < self.threshold) | ||
return check_passed | ||
|
||
|
||
class ForceUncertaintyCheck(DynamicsCheckBase, extra="forbid"): | ||
name: Literal["forces_uncertainty"] = "forces_uncertainty" | ||
threshold: float | ||
|
||
def check(self, predictions): | ||
if "forces_uncertainty" not in predictions.keys(): | ||
m = "No force uncertainties found. Are you using a model ensemble?" | ||
raise ValueError(m) | ||
|
||
forces_uncertainty = predictions["forces_uncertainty"] | ||
|
||
check_passed = jnp.all(forces_uncertainty < self.threshold) | ||
return check_passed | ||
|
||
|
||
DynamicsChecks = TypeAdapter( | ||
Union[EnergyUncertaintyCheck, ForceUncertaintyCheck] | ||
).validate_python |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
ensemble: | ||
name: nvt | ||
dt: 0.1 # fs time step | ||
temperature_schedule: | ||
name: piecewise | ||
T0: 5 # K | ||
values: [100, 200, 1000] | ||
steps: [10, 20, 30] | ||
|
||
duration: 100 # fs | ||
n_inner: 1 | ||
sampling_rate: 1 | ||
checkpoint_interval: 2 | ||
restart: True | ||
dynamics_checks: | ||
- name: forces_uncertainty | ||
threshold: 1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters