Skip to content

Commit

Permalink
test: add UTs for dp SeR (#3706)
Browse files Browse the repository at this point in the history
to resolve #3704
  • Loading branch information
anyangml committed Apr 25, 2024
1 parent d0cd9f3 commit 37c9540
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions source/tests/common/dpmodel/test_descriptor_se_r.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# SPDX-License-Identifier: LGPL-3.0-or-later
import unittest

import numpy as np

from deepmd.dpmodel.descriptor import (
DescrptSeR,
)

from .case_single_frame_with_nlist import (
TestCaseSingleFrameWithNlist,
)


class TestDescrptSeR(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
davg = rng.normal(size=(self.nt, nnei, 1))
dstd = rng.normal(size=(self.nt, nnei, 1))
dstd = 0.1 + np.abs(dstd)

em0 = DescrptSeR(self.rcut, self.rcut_smth, self.sel)
em0.davg = davg
em0.dstd = dstd
em1 = DescrptSeR.deserialize(em0.serialize())
mm0 = em0.call(self.coord_ext, self.atype_ext, self.nlist)
mm1 = em1.call(self.coord_ext, self.atype_ext, self.nlist)
for ii in [0, 4]:
np.testing.assert_allclose(mm0[ii], mm1[ii])

0 comments on commit 37c9540

Please sign in to comment.