Skip to content
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

Chore: refactor dpmodel model #4296

Merged
merged 21 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
88f5079
chore: refactor dpmodel atomic model
anyangml Nov 1, 2024
de96159
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 1, 2024
ab3bd29
feat: expose dos/polar/dipole model in dpmodel
anyangml Nov 1, 2024
8e85e59
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 1, 2024
c5dab77
chore: refactor atomic model fitting assertion
anyangml Nov 1, 2024
58b987e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 1, 2024
a285d63
Merge branch 'devel' into chore/refactor-dpmodel-model
anyangml Nov 15, 2024
e2e9d60
chore: fix typo
anyangml Nov 15, 2024
47114ec
feat: try add dos consistent UT
anyangml Nov 15, 2024
48d8d6c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 15, 2024
81bd024
fix: UT para
anyangml Nov 15, 2024
7490529
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 15, 2024
c040df3
fix: UT res extract
anyangml Nov 15, 2024
8940dac
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 15, 2024
4802a9a
fix: add dos consistency UT
anyangml Nov 18, 2024
3355f50
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 18, 2024
5a11ff8
fix: expose more dpmodel interface
anyangml Nov 18, 2024
9071e73
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 18, 2024
1dc7fd9
chore: vectorize for loop
anyangml Nov 19, 2024
0afee21
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 19, 2024
33452bd
Merge branch 'devel' into chore/refactor-dpmodel-model
anyangml Nov 19, 2024
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
16 changes: 16 additions & 0 deletions deepmd/dpmodel/atomic_model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,18 @@
from .base_atomic_model import (
BaseAtomicModel,
)
from .dipole_atomic_model import (
DPDipoleAtomicModel,
)
from .dos_atomic_model import (
DPDOSAtomicModel,
)
from .dp_atomic_model import (
DPAtomicModel,
)
from .energy_atomic_model import (
DPEnergyAtomicModel,
)
from .linear_atomic_model import (
DPZBLLinearEnergyAtomicModel,
LinearEnergyAtomicModel,
Expand All @@ -30,12 +39,19 @@
from .pairtab_atomic_model import (
PairTabAtomicModel,
)
from .polar_atomic_model import (
DPPolarAtomicModel,
)

__all__ = [
"make_base_atomic_model",
"BaseAtomicModel",
"DPAtomicModel",
"DPEnergyAtomicModel",
"PairTabAtomicModel",
"LinearEnergyAtomicModel",
"DPZBLLinearEnergyAtomicModel",
"DPDOSAtomicModel",
"DPPolarAtomicModel",
"DPDipoleAtomicModel",
]
27 changes: 27 additions & 0 deletions deepmd/dpmodel/atomic_model/dipole_atomic_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# SPDX-License-Identifier: LGPL-3.0-or-later
import numpy as np

from deepmd.dpmodel.fitting.dipole_fitting import (
DipoleFitting,
)

from .dp_atomic_model import (
DPAtomicModel,
)


class DPDipoleAtomicModel(DPAtomicModel):
def __init__(self, descriptor, fitting, type_map, **kwargs):
if not isinstance(fitting, DipoleFitting):
raise TypeError(

Check warning on line 16 in deepmd/dpmodel/atomic_model/dipole_atomic_model.py

View check run for this annotation

Codecov / codecov/patch

deepmd/dpmodel/atomic_model/dipole_atomic_model.py#L15-L16

Added lines #L15 - L16 were not covered by tests
"fitting must be an instance of DipoleFitting for DPDipoleAtomicModel"
)
super().__init__(descriptor, fitting, type_map, **kwargs)

Check warning on line 19 in deepmd/dpmodel/atomic_model/dipole_atomic_model.py

View check run for this annotation

Codecov / codecov/patch

deepmd/dpmodel/atomic_model/dipole_atomic_model.py#L19

Added line #L19 was not covered by tests

def apply_out_stat(
self,
ret: dict[str, np.ndarray],
atype: np.ndarray,
):
# dipole not applying bias
return ret

Check warning on line 27 in deepmd/dpmodel/atomic_model/dipole_atomic_model.py

View check run for this annotation

Codecov / codecov/patch

deepmd/dpmodel/atomic_model/dipole_atomic_model.py#L27

Added line #L27 was not covered by tests
17 changes: 17 additions & 0 deletions deepmd/dpmodel/atomic_model/dos_atomic_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# SPDX-License-Identifier: LGPL-3.0-or-later
from deepmd.dpmodel.fitting.dos_fitting import (
DOSFittingNet,
)

from .dp_atomic_model import (
DPAtomicModel,
)


class DPDOSAtomicModel(DPAtomicModel):
def __init__(self, descriptor, fitting, type_map, **kwargs):
if not isinstance(fitting, DOSFittingNet):
raise TypeError(

Check warning on line 14 in deepmd/dpmodel/atomic_model/dos_atomic_model.py

View check run for this annotation

Codecov / codecov/patch

deepmd/dpmodel/atomic_model/dos_atomic_model.py#L14

Added line #L14 was not covered by tests
"fitting must be an instance of DOSFittingNet for DPDOSAtomicModel"
)
super().__init__(descriptor, fitting, type_map, **kwargs)
20 changes: 20 additions & 0 deletions deepmd/dpmodel/atomic_model/energy_atomic_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# SPDX-License-Identifier: LGPL-3.0-or-later
from deepmd.dpmodel.fitting.ener_fitting import (
EnergyFittingNet,
InvarFitting,
)
anyangml marked this conversation as resolved.
Show resolved Hide resolved

from .dp_atomic_model import (
DPAtomicModel,
)


class DPEnergyAtomicModel(DPAtomicModel):
def __init__(self, descriptor, fitting, type_map, **kwargs):
if not (
isinstance(fitting, EnergyFittingNet) or isinstance(fitting, InvarFitting)
):
raise TypeError(

Check warning on line 17 in deepmd/dpmodel/atomic_model/energy_atomic_model.py

View check run for this annotation

Codecov / codecov/patch

deepmd/dpmodel/atomic_model/energy_atomic_model.py#L17

Added line #L17 was not covered by tests
"fitting must be an instance of EnergyFittingNet or InvarFitting for DPEnergyAtomicModel"
)
super().__init__(descriptor, fitting, type_map, **kwargs)
61 changes: 61 additions & 0 deletions deepmd/dpmodel/atomic_model/polar_atomic_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# SPDX-License-Identifier: LGPL-3.0-or-later

import numpy as np

from deepmd.dpmodel.fitting.polarizability_fitting import (
PolarFitting,
)

from .dp_atomic_model import (
DPAtomicModel,
)


class DPPolarAtomicModel(DPAtomicModel):
def __init__(self, descriptor, fitting, type_map, **kwargs):
if not isinstance(fitting, PolarFitting):
raise TypeError(

Check warning on line 17 in deepmd/dpmodel/atomic_model/polar_atomic_model.py

View check run for this annotation

Codecov / codecov/patch

deepmd/dpmodel/atomic_model/polar_atomic_model.py#L16-L17

Added lines #L16 - L17 were not covered by tests
"fitting must be an instance of PolarFitting for DPPolarAtomicModel"
)
super().__init__(descriptor, fitting, type_map, **kwargs)

Check warning on line 20 in deepmd/dpmodel/atomic_model/polar_atomic_model.py

View check run for this annotation

Codecov / codecov/patch

deepmd/dpmodel/atomic_model/polar_atomic_model.py#L20

Added line #L20 was not covered by tests

def apply_out_stat(
self,
ret: dict[str, np.ndarray],
atype: np.ndarray,
):
"""Apply the stat to each atomic output.

Parameters
----------
ret
The returned dict by the forward_atomic method
atype
The atom types. nf x nloc

"""
out_bias, out_std = self._fetch_out_stat(self.bias_keys)

Check warning on line 37 in deepmd/dpmodel/atomic_model/polar_atomic_model.py

View check run for this annotation

Codecov / codecov/patch

deepmd/dpmodel/atomic_model/polar_atomic_model.py#L37

Added line #L37 was not covered by tests

if self.fitting_net.shift_diag:
nframes, nloc = atype.shape
dtype = out_bias[self.bias_keys[0]].dtype
for kk in self.bias_keys:
ntypes = out_bias[kk].shape[0]
temp = np.zeros(ntypes, dtype=dtype)
Dismissed Show dismissed Hide dismissed
for i in range(ntypes):
temp[i] = np.mean(np.diagonal(out_bias[kk][i].reshape(3, 3)))
anyangml marked this conversation as resolved.
Show resolved Hide resolved
anyangml marked this conversation as resolved.
Show resolved Hide resolved
modified_bias = temp[atype]

Check warning on line 47 in deepmd/dpmodel/atomic_model/polar_atomic_model.py

View check run for this annotation

Codecov / codecov/patch

deepmd/dpmodel/atomic_model/polar_atomic_model.py#L39-L47

Added lines #L39 - L47 were not covered by tests

# (nframes, nloc, 1)
modified_bias = (

Check warning on line 50 in deepmd/dpmodel/atomic_model/polar_atomic_model.py

View check run for this annotation

Codecov / codecov/patch

deepmd/dpmodel/atomic_model/polar_atomic_model.py#L50

Added line #L50 was not covered by tests
modified_bias[..., np.newaxis] * (self.fitting_net.scale[atype])
)

eye = np.eye(3, dtype=dtype)
eye = np.tile(eye, (nframes, nloc, 1, 1))

Check warning on line 55 in deepmd/dpmodel/atomic_model/polar_atomic_model.py

View check run for this annotation

Codecov / codecov/patch

deepmd/dpmodel/atomic_model/polar_atomic_model.py#L54-L55

Added lines #L54 - L55 were not covered by tests
# (nframes, nloc, 3, 3)
modified_bias = modified_bias[..., np.newaxis] * eye

Check warning on line 57 in deepmd/dpmodel/atomic_model/polar_atomic_model.py

View check run for this annotation

Codecov / codecov/patch

deepmd/dpmodel/atomic_model/polar_atomic_model.py#L57

Added line #L57 was not covered by tests

# nf x nloc x odims, out_bias: ntypes x odims
ret[kk] = ret[kk] + modified_bias
return ret

Check warning on line 61 in deepmd/dpmodel/atomic_model/polar_atomic_model.py

View check run for this annotation

Codecov / codecov/patch

deepmd/dpmodel/atomic_model/polar_atomic_model.py#L60-L61

Added lines #L60 - L61 were not covered by tests
7 changes: 5 additions & 2 deletions deepmd/dpmodel/atomic_model/property_atomic_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@


class DPPropertyAtomicModel(DPAtomicModel):
def __init__(self, descriptor, fitting, type_map, **kwargs) -> None:
assert isinstance(fitting, PropertyFittingNet)
def __init__(self, descriptor, fitting, type_map, **kwargs):
if not isinstance(fitting, PropertyFittingNet):
raise TypeError(

Check warning on line 14 in deepmd/dpmodel/atomic_model/property_atomic_model.py

View check run for this annotation

Codecov / codecov/patch

deepmd/dpmodel/atomic_model/property_atomic_model.py#L12-L14

Added lines #L12 - L14 were not covered by tests
"fitting must be an instance of PropertyFittingNet for DPPropertyAtomicModel"
)
super().__init__(descriptor, fitting, type_map, **kwargs)
31 changes: 31 additions & 0 deletions deepmd/dpmodel/model/dipole_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# SPDX-License-Identifier: LGPL-3.0-or-later


from deepmd.dpmodel.atomic_model import (

Check warning on line 4 in deepmd/dpmodel/model/dipole_model.py

View check run for this annotation

Codecov / codecov/patch

deepmd/dpmodel/model/dipole_model.py#L4

Added line #L4 was not covered by tests
DPDipoleAtomicModel,
)
from deepmd.dpmodel.model.model import (

Check warning on line 7 in deepmd/dpmodel/model/dipole_model.py

View check run for this annotation

Codecov / codecov/patch

deepmd/dpmodel/model/dipole_model.py#L7

Added line #L7 was not covered by tests
BaseModel,
)

from .dp_model import (

Check warning on line 11 in deepmd/dpmodel/model/dipole_model.py

View check run for this annotation

Codecov / codecov/patch

deepmd/dpmodel/model/dipole_model.py#L11

Added line #L11 was not covered by tests
DPModelCommon,
)
from .make_model import (

Check warning on line 14 in deepmd/dpmodel/model/dipole_model.py

View check run for this annotation

Codecov / codecov/patch

deepmd/dpmodel/model/dipole_model.py#L14

Added line #L14 was not covered by tests
make_model,
)

DPDipoleModel_ = make_model(DPDipoleAtomicModel)

Check warning on line 18 in deepmd/dpmodel/model/dipole_model.py

View check run for this annotation

Codecov / codecov/patch

deepmd/dpmodel/model/dipole_model.py#L18

Added line #L18 was not covered by tests


@BaseModel.register("dipole")
class DipoleModel(DPModelCommon, DPDipoleModel_):
model_type = "dipole"

Check warning on line 23 in deepmd/dpmodel/model/dipole_model.py

View check run for this annotation

Codecov / codecov/patch

deepmd/dpmodel/model/dipole_model.py#L21-L23

Added lines #L21 - L23 were not covered by tests
anyangml marked this conversation as resolved.
Show resolved Hide resolved

def __init__(

Check warning on line 25 in deepmd/dpmodel/model/dipole_model.py

View check run for this annotation

Codecov / codecov/patch

deepmd/dpmodel/model/dipole_model.py#L25

Added line #L25 was not covered by tests
self,
*args,
**kwargs,
):
DPModelCommon.__init__(self)
DPDipoleModel_.__init__(self, *args, **kwargs)

Check warning on line 31 in deepmd/dpmodel/model/dipole_model.py

View check run for this annotation

Codecov / codecov/patch

deepmd/dpmodel/model/dipole_model.py#L30-L31

Added lines #L30 - L31 were not covered by tests
30 changes: 30 additions & 0 deletions deepmd/dpmodel/model/dos_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# SPDX-License-Identifier: LGPL-3.0-or-later

from deepmd.dpmodel.atomic_model import (
DPDOSAtomicModel,
)
from deepmd.dpmodel.model.model import (
BaseModel,
)

from .dp_model import (
DPModelCommon,
)
from .make_model import (
make_model,
)

DPDOSModel_ = make_model(DPDOSAtomicModel)


@BaseModel.register("dos")
class DOSModel(DPModelCommon, DPDOSModel_):
model_type = "dos"

def __init__(
self,
*args,
**kwargs,
):
DPModelCommon.__init__(self)
DPDOSModel_.__init__(self, *args, **kwargs)
anyangml marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 3 additions & 3 deletions deepmd/dpmodel/model/ener_model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: LGPL-3.0-or-later
from deepmd.dpmodel.atomic_model.dp_atomic_model import (
DPAtomicModel,
from deepmd.dpmodel.atomic_model import (
DPEnergyAtomicModel,
)
from deepmd.dpmodel.model.base_model import (
BaseModel,
Expand All @@ -13,7 +13,7 @@
make_model,
)

DPEnergyModel_ = make_model(DPAtomicModel)
DPEnergyModel_ = make_model(DPEnergyAtomicModel)


@BaseModel.register("ener")
Expand Down
12 changes: 11 additions & 1 deletion deepmd/dpmodel/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
from deepmd.dpmodel.descriptor.base_descriptor import (
BaseDescriptor,
)
from deepmd.dpmodel.fitting.dos_fitting import (
DOSFittingNet,
)
from deepmd.dpmodel.fitting.ener_fitting import (
EnergyFittingNet,
)
Expand Down Expand Up @@ -54,8 +57,15 @@
mixed_types=descriptor.mixed_types(),
**data["fitting_net"],
)
elif fitting_type == "dos":
fitting = DOSFittingNet(
ntypes=descriptor.get_ntypes(),
dim_descrpt=descriptor.get_dim_out(),
mixed_types=descriptor.mixed_types(),
**data["fitting_net"],
)
else:
raise ValueError(f"Unknown fitting type {fitting_type}")
raise ValueError(f"Unknown fitting type {fitting_type}") # fix

Check warning on line 68 in deepmd/dpmodel/model/model.py

View check run for this annotation

Codecov / codecov/patch

deepmd/dpmodel/model/model.py#L68

Added line #L68 was not covered by tests
return EnergyModel(
descriptor=descriptor,
fitting=fitting,
Expand Down
30 changes: 30 additions & 0 deletions deepmd/dpmodel/model/polar_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# SPDX-License-Identifier: LGPL-3.0-or-later

from deepmd.dpmodel.atomic_model import (

Check warning on line 3 in deepmd/dpmodel/model/polar_model.py

View check run for this annotation

Codecov / codecov/patch

deepmd/dpmodel/model/polar_model.py#L3

Added line #L3 was not covered by tests
DPPolarAtomicModel,
)
from deepmd.dpmodel.model.model import (

Check warning on line 6 in deepmd/dpmodel/model/polar_model.py

View check run for this annotation

Codecov / codecov/patch

deepmd/dpmodel/model/polar_model.py#L6

Added line #L6 was not covered by tests
BaseModel,
)

from .dp_model import (

Check warning on line 10 in deepmd/dpmodel/model/polar_model.py

View check run for this annotation

Codecov / codecov/patch

deepmd/dpmodel/model/polar_model.py#L10

Added line #L10 was not covered by tests
DPModelCommon,
)
from .make_model import (

Check warning on line 13 in deepmd/dpmodel/model/polar_model.py

View check run for this annotation

Codecov / codecov/patch

deepmd/dpmodel/model/polar_model.py#L13

Added line #L13 was not covered by tests
make_model,
)

DPPolarModel_ = make_model(DPPolarAtomicModel)

Check warning on line 17 in deepmd/dpmodel/model/polar_model.py

View check run for this annotation

Codecov / codecov/patch

deepmd/dpmodel/model/polar_model.py#L17

Added line #L17 was not covered by tests


@BaseModel.register("polar")
class PolarModel(DPModelCommon, DPPolarModel_):
model_type = "polar"

Check warning on line 22 in deepmd/dpmodel/model/polar_model.py

View check run for this annotation

Codecov / codecov/patch

deepmd/dpmodel/model/polar_model.py#L20-L22

Added lines #L20 - L22 were not covered by tests
anyangml marked this conversation as resolved.
Show resolved Hide resolved

def __init__(

Check warning on line 24 in deepmd/dpmodel/model/polar_model.py

View check run for this annotation

Codecov / codecov/patch

deepmd/dpmodel/model/polar_model.py#L24

Added line #L24 was not covered by tests
self,
*args,
**kwargs,
):
DPModelCommon.__init__(self)
DPPolarModel_.__init__(self, *args, **kwargs)

Check warning on line 30 in deepmd/dpmodel/model/polar_model.py

View check run for this annotation

Codecov / codecov/patch

deepmd/dpmodel/model/polar_model.py#L29-L30

Added lines #L29 - L30 were not covered by tests
7 changes: 5 additions & 2 deletions deepmd/pt/model/atomic_model/dipole_atomic_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@


class DPDipoleAtomicModel(DPAtomicModel):
def __init__(self, descriptor, fitting, type_map, **kwargs) -> None:
assert isinstance(fitting, DipoleFittingNet)
def __init__(self, descriptor, fitting, type_map, **kwargs):
if not isinstance(fitting, DipoleFittingNet):
Fixed Show fixed Hide fixed
raise TypeError(

Check warning on line 17 in deepmd/pt/model/atomic_model/dipole_atomic_model.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/model/atomic_model/dipole_atomic_model.py#L17

Added line #L17 was not covered by tests
"fitting must be an instance of DipoleFittingNet for DPDipoleAtomicModel"
)
super().__init__(descriptor, fitting, type_map, **kwargs)

def apply_out_stat(
Expand Down
7 changes: 5 additions & 2 deletions deepmd/pt/model/atomic_model/dos_atomic_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@


class DPDOSAtomicModel(DPAtomicModel):
def __init__(self, descriptor, fitting, type_map, **kwargs) -> None:
assert isinstance(fitting, DOSFittingNet)
def __init__(self, descriptor, fitting, type_map, **kwargs):
if not isinstance(fitting, DOSFittingNet):
raise TypeError(

Check warning on line 14 in deepmd/pt/model/atomic_model/dos_atomic_model.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/model/atomic_model/dos_atomic_model.py#L14

Added line #L14 was not covered by tests
"fitting must be an instance of DOSFittingNet for DPDOSAtomicModel"
)
super().__init__(descriptor, fitting, type_map, **kwargs)
9 changes: 6 additions & 3 deletions deepmd/pt/model/atomic_model/energy_atomic_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@


class DPEnergyAtomicModel(DPAtomicModel):
def __init__(self, descriptor, fitting, type_map, **kwargs) -> None:
assert (
def __init__(self, descriptor, fitting, type_map, **kwargs):
if not (
isinstance(fitting, EnergyFittingNet)
or isinstance(fitting, EnergyFittingNetDirect)
or isinstance(fitting, InvarFitting)
)
):
raise TypeError(

Check warning on line 20 in deepmd/pt/model/atomic_model/energy_atomic_model.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/model/atomic_model/energy_atomic_model.py#L20

Added line #L20 was not covered by tests
"fitting must be an instance of EnergyFittingNet, EnergyFittingNetDirect or InvarFitting for DPEnergyAtomicModel"
)
super().__init__(descriptor, fitting, type_map, **kwargs)
7 changes: 5 additions & 2 deletions deepmd/pt/model/atomic_model/polar_atomic_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@


class DPPolarAtomicModel(DPAtomicModel):
def __init__(self, descriptor, fitting, type_map, **kwargs) -> None:
assert isinstance(fitting, PolarFittingNet)
def __init__(self, descriptor, fitting, type_map, **kwargs):
if not isinstance(fitting, PolarFittingNet):
raise TypeError(

Check warning on line 17 in deepmd/pt/model/atomic_model/polar_atomic_model.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/model/atomic_model/polar_atomic_model.py#L17

Added line #L17 was not covered by tests
"fitting must be an instance of PolarFittingNet for DPPolarAtomicModel"
)
super().__init__(descriptor, fitting, type_map, **kwargs)

def apply_out_stat(
Expand Down
7 changes: 5 additions & 2 deletions deepmd/pt/model/atomic_model/property_atomic_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@


class DPPropertyAtomicModel(DPAtomicModel):
def __init__(self, descriptor, fitting, type_map, **kwargs) -> None:
assert isinstance(fitting, PropertyFittingNet)
def __init__(self, descriptor, fitting, type_map, **kwargs):
if not isinstance(fitting, PropertyFittingNet):
raise TypeError(

Check warning on line 17 in deepmd/pt/model/atomic_model/property_atomic_model.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/model/atomic_model/property_atomic_model.py#L17

Added line #L17 was not covered by tests
"fitting must be an instance of PropertyFittingNet for DPPropertyAtomicModel"
)
super().__init__(descriptor, fitting, type_map, **kwargs)

def apply_out_stat(
Expand Down
Loading