Skip to content

Commit

Permalink
dp model format for dp models.
Browse files Browse the repository at this point in the history
  • Loading branch information
Han Wang committed Jan 31, 2024
1 parent 8c82620 commit 27f14cd
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
4 changes: 4 additions & 0 deletions deepmd/model_format/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
from .dp_atomic_model import (
DPAtomicModel,
)
from .dp_model import (
DPModel,
)
from .env_mat import (
EnvMat,
)
Expand Down Expand Up @@ -40,6 +43,7 @@
)

__all__ = [
"DPModel",
"DPAtomicModel",
"InvarFitting",
"DescrptSeA",
Expand Down
2 changes: 1 addition & 1 deletion deepmd/model_format/atomic_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
Optional,
)

from deepmd.model_format import (
from .output_def import (
FittingOutputDef,
)

Expand Down
8 changes: 8 additions & 0 deletions deepmd/model_format/se_e2_a.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,14 @@ def get_dim_out(self):
"""Returns the output dimension of this descriptor."""
return self.neuron[-1] * self.axis_neuron

def get_rcut(self):
"""Returns cutoff radius."""
return self.rcut

def get_sel(self):
"""Returns cutoff radius."""
return self.sel

def distinguish_types(self):
"""Returns if the descriptor uses different nets for
different atomic types.
Expand Down
35 changes: 34 additions & 1 deletion source/tests/common/test_model_format_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from deepmd.model_format import (
DescrptSeA,
DPAtomicModel,
DPModel,
EmbeddingNet,
EnvMat,
FittingNet,
Expand Down Expand Up @@ -277,7 +278,7 @@ def test_zero_dim(self):
)


class TestDPModel(unittest.TestCase):
class TestSaveLoadDPModel(unittest.TestCase):
def setUp(self) -> None:
self.w = np.full((3, 2), 3.0)
self.b = np.full((3,), 4.0)
Expand Down Expand Up @@ -534,6 +535,38 @@ def test_self_consistency(
np.testing.assert_allclose(ret0["energy"], ret1["energy"])


class TestDPModel(unittest.TestCase, TestCaseSingleFrameWithNlist):
def setUp(self):
TestCaseSingleFrameWithNlist.setUp(self)

def test_self_consistency(
self,
):
rng = np.random.default_rng()
nf, nloc, nnei = self.nlist.shape
ds = DescrptSeA(
self.rcut,
self.rcut_smth,
self.sel,
)
ft = InvarFitting(
"energy",
self.nt,
ds.get_dim_out(),
1,
distinguish_types=ds.distinguish_types(),
)
type_map = ["foo", "bar"]
md0 = DPModel(ds, ft, type_map=type_map)
md1 = DPModel.deserialize(md0.serialize())

ret0 = md0.call_lower(self.coord_ext, self.atype_ext, self.nlist)
ret1 = md1.call_lower(self.coord_ext, self.atype_ext, self.nlist)

np.testing.assert_allclose(ret0["energy"], ret1["energy"])
np.testing.assert_allclose(ret0["energy_redu"], ret1["energy_redu"])


class TestRegion(unittest.TestCase):
def setUp(self):
self.cell = np.array(
Expand Down

0 comments on commit 27f14cd

Please sign in to comment.