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

feat pt : Support property fitting #3867

Merged
merged 86 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
1e610cf
3866
Chengqian-Zhang Jun 12, 2024
e30dfa0
Support intensive property fitting
Chengqian-Zhang Jun 13, 2024
50c8940
Solve conflict
Chengqian-Zhang Jun 13, 2024
b9a3f9a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 13, 2024
39d3d9c
Fix UT
Chengqian-Zhang Jun 13, 2024
6c24fb5
Merge branch '3866' of github.com:Chengqian-Zhang/deepmd-kit into 3866
Chengqian-Zhang Jun 13, 2024
b2ffadf
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 13, 2024
7ece19e
delete try except
Chengqian-Zhang Jun 13, 2024
5c44bba
Solve conflict
Chengqian-Zhang Jun 13, 2024
4295dd5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 13, 2024
0739bf1
Merge branch 'devel' into 3866
Chengqian-Zhang Jun 14, 2024
8ea3269
Add argcheck
Chengqian-Zhang Jun 14, 2024
512f438
Delete input.json
Chengqian-Zhang Jun 14, 2024
a5e29e6
Merge branch 'devel' into 3866
Chengqian-Zhang Jun 14, 2024
9228959
fix UT
Chengqian-Zhang Jun 14, 2024
c8974cb
fix UT
Chengqian-Zhang Jun 14, 2024
2540d29
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 14, 2024
792e0c7
Add example
Chengqian-Zhang Jun 14, 2024
8d121bf
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 14, 2024
ce4e80f
Add dp model and consistent UT
Chengqian-Zhang Jun 14, 2024
6034cac
Merge branch '3866' of github.com:Chengqian-Zhang/deepmd-kit into 3866
Chengqian-Zhang Jun 14, 2024
7f66234
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 14, 2024
1679bfa
Add property deep_eval
Chengqian-Zhang Jun 17, 2024
e2e0454
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 17, 2024
beae3ca
fix fitting-->Fitting
Chengqian-Zhang Jun 17, 2024
1481417
add beta doc in loss
Chengqian-Zhang Jun 17, 2024
be6d431
solve pre-commit
Chengqian-Zhang Jun 17, 2024
5bc6d73
Solve conversation
Chengqian-Zhang Jun 17, 2024
3e33f6f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 17, 2024
6e68bf8
Merge branch 'devel' into 3866
Chengqian-Zhang Jun 17, 2024
f239cce
Merge branch 'devel' into 3866
Chengqian-Zhang Jun 18, 2024
cff1ce0
Merge branch 'devel' into 3866
Chengqian-Zhang Jun 25, 2024
761a7dc
Merge branch 'devel' into 3866
Chengqian-Zhang Jun 26, 2024
c7c852b
change reduciable to reducible
Chengqian-Zhang Jun 26, 2024
8850742
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 26, 2024
ec25e31
Merge branch 'devel' into 3866
Chengqian-Zhang Jun 27, 2024
07e35a8
Add dp test
Chengqian-Zhang Jun 28, 2024
a1ab5ad
Merge branch '3866' of github.com:Chengqian-Zhang/deepmd-kit into 3866
Chengqian-Zhang Jun 28, 2024
8745744
Merge branch 'devel' into 3866
Chengqian-Zhang Jun 28, 2024
5d74917
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 28, 2024
4fb62e9
add get_intensive in atomic_model layer
Chengqian-Zhang Jun 28, 2024
6670877
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 28, 2024
286fa65
solv conversions
Chengqian-Zhang Jun 28, 2024
8430080
delete useless file
Chengqian-Zhang Jun 28, 2024
e367275
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 28, 2024
8094192
fix UT
Chengqian-Zhang Jun 28, 2024
fcaa14c
delete useless file
Chengqian-Zhang Jun 28, 2024
43dc706
Merge branch '3866' of github.com:Chengqian-Zhang/deepmd-kit into 3866
Chengqian-Zhang Jun 28, 2024
7915373
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 28, 2024
8701d10
Add property atomic_model and model in numpy
Chengqian-Zhang Jun 28, 2024
692ac97
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 28, 2024
73ba974
merge devel
Chengqian-Zhang Aug 8, 2024
504a4f2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 8, 2024
f681f60
delete example
Chengqian-Zhang Aug 8, 2024
467dfb3
Merge branch 'devel' into 3866
Chengqian-Zhang Aug 27, 2024
65ec9d7
change intensive operation to transform_output
Chengqian-Zhang Aug 27, 2024
0dafdb7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 27, 2024
4a827a4
modify bias computing part
Chengqian-Zhang Aug 27, 2024
ac679a9
Merge branch '3866' of github.com:Chengqian-Zhang/deepmd-kit into 3866
Chengqian-Zhang Aug 27, 2024
2502b89
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 27, 2024
8a2e228
Delete useless get_intensive() method
Chengqian-Zhang Aug 27, 2024
72dd1d7
Add bias_method parameter in fitting_net
Chengqian-Zhang Aug 27, 2024
d423b28
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 27, 2024
e1d3558
add reducible and intensive dependency
Chengqian-Zhang Aug 27, 2024
a865f23
fix UT
Chengqian-Zhang Aug 27, 2024
3fd5697
solve serialize UT error
Chengqian-Zhang Aug 27, 2024
3d3700d
rerun UT
Chengqian-Zhang Aug 27, 2024
d580348
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 27, 2024
4a3f84c
Merge branch 'devel' into 3866
Chengqian-Zhang Aug 28, 2024
11051ca
Add universal test
Chengqian-Zhang Aug 28, 2024
ae4b4a9
Merge branch '3866' of github.com:Chengqian-Zhang/deepmd-kit into 3866
Chengqian-Zhang Aug 28, 2024
633bf8e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 28, 2024
74b3533
rerun UT
Chengqian-Zhang Aug 28, 2024
b3031d0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 28, 2024
d5e03e9
Add doc and output_def UT
Chengqian-Zhang Aug 28, 2024
6870ecd
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 28, 2024
5b237ac
change type_map of example
Chengqian-Zhang Sep 1, 2024
9830fd8
delete prop option
Chengqian-Zhang Sep 1, 2024
d0f8949
change doc_metric
Chengqian-Zhang Sep 1, 2024
abd507e
change property example to dpa1
Chengqian-Zhang Sep 1, 2024
a8ef765
Add se_a UT in universal/dpmodel/atomic_model/
Chengqian-Zhang Sep 1, 2024
b105e34
Add dptest property UT
Chengqian-Zhang Sep 3, 2024
d22f6b4
Merge branch 'devel' into 3866
Chengqian-Zhang Sep 3, 2024
a5da5a7
Merge branch '3866' of github.com:Chengqian-Zhang/deepmd-kit into 3866
Chengqian-Zhang Sep 3, 2024
dde48fd
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 3, 2024
4d8934f
Merge branch 'devel' into 3866
Chengqian-Zhang Sep 4, 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
4 changes: 4 additions & 0 deletions deepmd/pt/loss/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
from .loss import (
TaskLoss,
)
from .property import (

Check warning on line 17 in deepmd/pt/loss/__init__.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/loss/__init__.py#L17

Added line #L17 was not covered by tests
PropertyLoss,
)
from .tensor import (
TensorLoss,
)
Expand All @@ -25,4 +28,5 @@
"TensorLoss",
"TaskLoss",
"DOSLoss",
"PropertyLoss",
]
159 changes: 159 additions & 0 deletions deepmd/pt/loss/property.py
Chengqian-Zhang marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
# SPDX-License-Identifier: LGPL-3.0-or-later
import logging
from typing import (

Check warning on line 3 in deepmd/pt/loss/property.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/loss/property.py#L2-L3

Added lines #L2 - L3 were not covered by tests
List,
)

import torch
import torch.nn.functional as F

Check warning on line 8 in deepmd/pt/loss/property.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/loss/property.py#L7-L8

Added lines #L7 - L8 were not covered by tests

from deepmd.pt.loss.loss import (

Check warning on line 10 in deepmd/pt/loss/property.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/loss/property.py#L10

Added line #L10 was not covered by tests
TaskLoss,
)
from deepmd.pt.utils import (

Check warning on line 13 in deepmd/pt/loss/property.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/loss/property.py#L13

Added line #L13 was not covered by tests
env,
)
from deepmd.utils.data import (

Check warning on line 16 in deepmd/pt/loss/property.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/loss/property.py#L16

Added line #L16 was not covered by tests
DataRequirementItem,
)

log = logging.getLogger(__name__)

Check warning on line 20 in deepmd/pt/loss/property.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/loss/property.py#L20

Added line #L20 was not covered by tests


class PropertyLoss(TaskLoss):
def __init__(

Check warning on line 24 in deepmd/pt/loss/property.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/loss/property.py#L23-L24

Added lines #L23 - L24 were not covered by tests
self,
task_dim,
loss_func: str = "smooth_mae",
metric: list = ["mae"],
Chengqian-Zhang marked this conversation as resolved.
Show resolved Hide resolved
beta: float = 1.00,
intensive: bool = False,
**kwargs,
):
r"""Construct a layer to compute loss on property.

Parameters
----------
task_dim : float
The output dimension of property fitting net.
loss_func : str
The loss function, such as "smooth_mae", "mae", "rmse".
metric : list
The metric such as mae, rmse which will be printed.
beta:
TODO
"""
super().__init__()
self.task_dim = task_dim
self.loss_func = loss_func
self.metric = metric
self.beta = beta
self.intensive = intensive

Check warning on line 51 in deepmd/pt/loss/property.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/loss/property.py#L46-L51

Added lines #L46 - L51 were not covered by tests

def forward(self, input_dict, model, label, natoms, learning_rate=0.0, mae=False):

Check warning on line 53 in deepmd/pt/loss/property.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/loss/property.py#L53

Added line #L53 was not covered by tests
"""Return loss on properties .

Parameters
----------
input_dict : dict[str, torch.Tensor]
Model inputs.
model : torch.nn.Module
Model to be used to output the predictions.
label : dict[str, torch.Tensor]
Labels.
natoms : int
The local atom number.

Returns
-------
model_pred: dict[str, torch.Tensor]
Model predictions.
loss: torch.Tensor
Loss for model to minimize.
more_loss: dict[str, torch.Tensor]
Other losses for display.
"""
model_pred = model(**input_dict)
assert label["property"].shape[-1] == self.task_dim
assert model_pred["property"].shape[-1] == self.task_dim
loss = torch.zeros(1, dtype=env.GLOBAL_PT_FLOAT_PRECISION, device=env.DEVICE)[0]
more_loss = {}

Check warning on line 80 in deepmd/pt/loss/property.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/loss/property.py#L76-L80

Added lines #L76 - L80 were not covered by tests

if not self.intensive:
label["property"] = label["property"] / natoms
model_pred["property"] = model_pred["property"] / natoms

Check warning on line 84 in deepmd/pt/loss/property.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/loss/property.py#L82-L84

Added lines #L82 - L84 were not covered by tests

# loss
if self.loss_func == "smooth_mae":
loss += F.smooth_l1_loss(

Check warning on line 88 in deepmd/pt/loss/property.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/loss/property.py#L87-L88

Added lines #L87 - L88 were not covered by tests
label["property"],
model_pred["property"],
reduction="sum",
beta=self.beta,
)
elif self.loss_func == "mae":
loss += F.l1_loss(

Check warning on line 95 in deepmd/pt/loss/property.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/loss/property.py#L94-L95

Added lines #L94 - L95 were not covered by tests
label["property"], model_pred["property"], reduction="sum"
)
elif self.loss_func == "mse":
loss += F.mse_loss(

Check warning on line 99 in deepmd/pt/loss/property.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/loss/property.py#L98-L99

Added lines #L98 - L99 were not covered by tests
label["property"],
model_pred["property"],
reduction="sum",
)
elif self.loss_func == "rmse":
loss += torch.sqrt(

Check warning on line 105 in deepmd/pt/loss/property.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/loss/property.py#L104-L105

Added lines #L104 - L105 were not covered by tests
F.mse_loss(
label["property"],
model_pred["property"],
reduction="mean",
)
)
else:
raise RuntimeError(f"Unknown loss function : {self.loss_func}")

Check warning on line 113 in deepmd/pt/loss/property.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/loss/property.py#L113

Added line #L113 was not covered by tests

# more loss
if "smooth_mae" in self.metric:
more_loss["smooth_mae"] = F.smooth_l1_loss(

Check warning on line 117 in deepmd/pt/loss/property.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/loss/property.py#L116-L117

Added lines #L116 - L117 were not covered by tests
label["property"],
model_pred["property"],
reduction="mean",
beta=self.beta,
).detach()
if "mae" in self.metric:
more_loss["mae"] = F.l1_loss(

Check warning on line 124 in deepmd/pt/loss/property.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/loss/property.py#L123-L124

Added lines #L123 - L124 were not covered by tests
label["property"],
model_pred["property"],
reduction="mean",
).detach()
if "mse" in self.metric:
more_loss["mse"] = F.mse_loss(

Check warning on line 130 in deepmd/pt/loss/property.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/loss/property.py#L129-L130

Added lines #L129 - L130 were not covered by tests
label["property"],
model_pred["property"],
reduction="mean",
).detach()
if "rmse" in self.metric:
more_loss["rmse"] = torch.sqrt(

Check warning on line 136 in deepmd/pt/loss/property.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/loss/property.py#L135-L136

Added lines #L135 - L136 were not covered by tests
F.mse_loss(
label["property"],
model_pred["property"],
reduction="mean",
)
).detach()

return model_pred, loss, more_loss

Check warning on line 144 in deepmd/pt/loss/property.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/loss/property.py#L144

Added line #L144 was not covered by tests

@property
def label_requirement(self) -> List[DataRequirementItem]:

Check warning on line 147 in deepmd/pt/loss/property.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/loss/property.py#L146-L147

Added lines #L146 - L147 were not covered by tests
"""Return data label requirements needed for this loss calculation."""
label_requirement = []
label_requirement.append(

Check warning on line 150 in deepmd/pt/loss/property.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/loss/property.py#L149-L150

Added lines #L149 - L150 were not covered by tests
DataRequirementItem(
"property",
ndof=self.task_dim,
atomic=False,
must=False,
high_prec=True,
)
)
return label_requirement

Check warning on line 159 in deepmd/pt/loss/property.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/loss/property.py#L159

Added line #L159 was not covered by tests
4 changes: 4 additions & 0 deletions deepmd/pt/model/atomic_model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,16 @@
from .polar_atomic_model import (
DPPolarAtomicModel,
)
from .property_atomic_model import (

Check warning on line 42 in deepmd/pt/model/atomic_model/__init__.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/model/atomic_model/__init__.py#L42

Added line #L42 was not covered by tests
DPPropertyAtomicModel,
)

__all__ = [
"BaseAtomicModel",
"DPAtomicModel",
"DPDOSAtomicModel",
"DPEnergyAtomicModel",
"DPPropertyAtomicModel",
"PairTabAtomicModel",
"LinearEnergyAtomicModel",
"DPPolarAtomicModel",
Expand Down
1 change: 1 addition & 0 deletions deepmd/pt/model/atomic_model/base_atomic_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ def change_out_bias(
stat_file_path=stat_file_path,
rcond=self.rcond,
preset_bias=self.preset_out_bias,
intensive=self.fitting_net.intensive,
)
self._store_out_stat(bias_out, std_out)
else:
Expand Down
14 changes: 14 additions & 0 deletions deepmd/pt/model/atomic_model/property_atomic_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# SPDX-License-Identifier: LGPL-3.0-or-later
from deepmd.pt.model.task.property import (

Check warning on line 2 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#L2

Added line #L2 was not covered by tests
PropertyFittingNet,
)

from .dp_atomic_model import (

Check warning on line 6 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#L6

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


class DPPropertyAtomicModel(DPAtomicModel):
def __init__(self, descriptor, fitting, type_map, **kwargs):
assert isinstance(fitting, PropertyFittingNet)
Chengqian-Zhang marked this conversation as resolved.
Show resolved Hide resolved
super().__init__(descriptor, fitting, type_map, **kwargs)

Check warning on line 14 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#L11-L14

Added lines #L11 - L14 were not covered by tests
5 changes: 5 additions & 0 deletions deepmd/pt/model/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@
from .polar_model import (
PolarModel,
)
from .property_model import (

Check warning on line 63 in deepmd/pt/model/model/__init__.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/model/model/__init__.py#L63

Added line #L63 was not covered by tests
PropertyModel,
)
from .spin_model import (
SpinEnergyModel,
SpinModel,
Expand Down Expand Up @@ -182,6 +185,8 @@
modelcls = DOSModel
elif fitting_net["type"] in ["ener", "direct_force_ener"]:
modelcls = EnergyModel
elif fitting_net["type"] in ["prop", "property"]:
Chengqian-Zhang marked this conversation as resolved.
Show resolved Hide resolved
modelcls = PropertyModel

Check warning on line 189 in deepmd/pt/model/model/__init__.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/model/model/__init__.py#L188-L189

Added lines #L188 - L189 were not covered by tests
else:
raise RuntimeError(f"Unknown fitting type: {fitting_net['type']}")

Expand Down
93 changes: 93 additions & 0 deletions deepmd/pt/model/model/property_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# SPDX-License-Identifier: LGPL-3.0-or-later
from typing import (

Check warning on line 2 in deepmd/pt/model/model/property_model.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/model/model/property_model.py#L2

Added line #L2 was not covered by tests
Dict,
Optional,
)

import torch

Check warning on line 7 in deepmd/pt/model/model/property_model.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/model/model/property_model.py#L7

Added line #L7 was not covered by tests

from deepmd.pt.model.atomic_model import (

Check warning on line 9 in deepmd/pt/model/model/property_model.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/model/model/property_model.py#L9

Added line #L9 was not covered by tests
DPPropertyAtomicModel,
)
from deepmd.pt.model.model.model import (

Check warning on line 12 in deepmd/pt/model/model/property_model.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/model/model/property_model.py#L12

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

from .dp_model import (

Check warning on line 16 in deepmd/pt/model/model/property_model.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/model/model/property_model.py#L16

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

Check warning on line 19 in deepmd/pt/model/model/property_model.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/model/model/property_model.py#L19

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

DPPropertyModel_ = make_model(DPPropertyAtomicModel)

Check warning on line 23 in deepmd/pt/model/model/property_model.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/model/model/property_model.py#L23

Added line #L23 was not covered by tests


@BaseModel.register("property")
class PropertyModel(DPModelCommon, DPPropertyModel_):
model_type = "property"

Check warning on line 28 in deepmd/pt/model/model/property_model.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/model/model/property_model.py#L26-L28

Added lines #L26 - L28 were not covered by tests

def __init__(

Check warning on line 30 in deepmd/pt/model/model/property_model.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/model/model/property_model.py#L30

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

Check warning on line 36 in deepmd/pt/model/model/property_model.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/model/model/property_model.py#L35-L36

Added lines #L35 - L36 were not covered by tests

def forward(

Check warning on line 38 in deepmd/pt/model/model/property_model.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/model/model/property_model.py#L38

Added line #L38 was not covered by tests
self,
coord,
atype,
box: Optional[torch.Tensor] = None,
fparam: Optional[torch.Tensor] = None,
aparam: Optional[torch.Tensor] = None,
do_atomic_virial: bool = False,
) -> Dict[str, torch.Tensor]:
model_ret = self.forward_common(

Check warning on line 47 in deepmd/pt/model/model/property_model.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/model/model/property_model.py#L47

Added line #L47 was not covered by tests
coord,
atype,
box,
fparam=fparam,
aparam=aparam,
do_atomic_virial=do_atomic_virial,
)
model_predict = {}
model_predict["atom_property"] = model_ret["property"]
model_predict["property"] = model_ret["property_redu"]
if self.atomic_model.fitting_net.intensive:
natoms = model_predict["atom_property"].shape[1]
model_predict["property"] = model_ret["property_redu"] / natoms
if "mask" in model_ret:
model_predict["mask"] = model_ret["mask"]
return model_predict

Check warning on line 63 in deepmd/pt/model/model/property_model.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/model/model/property_model.py#L55-L63

Added lines #L55 - L63 were not covered by tests
Chengqian-Zhang marked this conversation as resolved.
Show resolved Hide resolved

@torch.jit.export
def forward_lower(

Check warning on line 66 in deepmd/pt/model/model/property_model.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/model/model/property_model.py#L65-L66

Added lines #L65 - L66 were not covered by tests
self,
extended_coord,
extended_atype,
nlist,
mapping: Optional[torch.Tensor] = None,
fparam: Optional[torch.Tensor] = None,
aparam: Optional[torch.Tensor] = None,
do_atomic_virial: bool = False,
comm_dict: Optional[Dict[str, torch.Tensor]] = None,
):
model_ret = self.forward_common_lower(

Check warning on line 77 in deepmd/pt/model/model/property_model.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/model/model/property_model.py#L77

Added line #L77 was not covered by tests
extended_coord,
extended_atype,
nlist,
mapping,
fparam=fparam,
aparam=aparam,
do_atomic_virial=do_atomic_virial,
comm_dict=comm_dict,
)
model_predict = {}
model_predict["atom_property"] = model_ret["property"]
natoms = model_predict["atom_property"].shape[1]
Fixed Show fixed Hide fixed
Chengqian-Zhang marked this conversation as resolved.
Show resolved Hide resolved
model_predict["property"] = model_ret["property_redu"]
if "mask" in model_ret:
model_predict["mask"] = model_ret["mask"]
return model_predict

Check warning on line 93 in deepmd/pt/model/model/property_model.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/model/model/property_model.py#L87-L93

Added lines #L87 - L93 were not covered by tests
4 changes: 4 additions & 0 deletions deepmd/pt/model/task/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
from .polarizability import (
PolarFittingNet,
)
from .property import (

Check warning on line 27 in deepmd/pt/model/task/__init__.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/model/task/__init__.py#L27

Added line #L27 was not covered by tests
PropertyFittingNet,
)
from .type_predict import (
TypePredictNet,
)
Expand All @@ -39,4 +42,5 @@
"TypePredictNet",
"PolarFittingNet",
"DOSFittingNet",
"PropertyFittingNet",
]
Loading
Loading