From 61e3ca05b2e3654fd4cf42d54168a99f7408889c Mon Sep 17 00:00:00 2001 From: Anyang Peng <137014849+anyangml@users.noreply.github.com> Date: Tue, 12 Mar 2024 11:34:00 +0800 Subject: [PATCH 01/10] chore: refactor linear serialize --- .../dpmodel/atomic_model/dp_atomic_model.py | 2 +- .../atomic_model/linear_atomic_model.py | 35 +++++++++--------- .../atomic_model/pairtab_atomic_model.py | 2 +- .../pt/model/atomic_model/dp_atomic_model.py | 2 +- .../model/atomic_model/linear_atomic_model.py | 37 ++++++++++--------- .../atomic_model/pairtab_atomic_model.py | 2 +- 6 files changed, 40 insertions(+), 40 deletions(-) diff --git a/deepmd/dpmodel/atomic_model/dp_atomic_model.py b/deepmd/dpmodel/atomic_model/dp_atomic_model.py index 110aa26162..e9d8b8ac09 100644 --- a/deepmd/dpmodel/atomic_model/dp_atomic_model.py +++ b/deepmd/dpmodel/atomic_model/dp_atomic_model.py @@ -25,7 +25,7 @@ BaseAtomicModel, ) - +@BaseAtomicModel.register("standard") class DPAtomicModel(BaseAtomicModel): """Model give atomic prediction of some physical property. diff --git a/deepmd/dpmodel/atomic_model/linear_atomic_model.py b/deepmd/dpmodel/atomic_model/linear_atomic_model.py index ac2a73a381..b775c8d4d5 100644 --- a/deepmd/dpmodel/atomic_model/linear_atomic_model.py +++ b/deepmd/dpmodel/atomic_model/linear_atomic_model.py @@ -225,32 +225,30 @@ def fitting_output_def(self) -> FittingOutputDef: ] ) - @staticmethod - def serialize(models, type_map) -> dict: + def serialize(self) -> dict: return { "@class": "Model", "type": "linear", "@version": 1, - "models": [model.serialize() for model in models], - "model_name": [model.__class__.__name__ for model in models], - "type_map": type_map, + "models": [model.serialize() for model in self.models], + "type_map": self.type_map, } - @staticmethod - def deserialize(data) -> Tuple[List[BaseAtomicModel], List[str]]: + @classmethod + def deserialize(cls, data: dict) -> "LinearEnergyAtomicModel": data = copy.deepcopy(data) check_version_compatibility(data.pop("@version", 1), 1, 1) data.pop("@class") data.pop("type") - model_names = data["model_name"] - type_map = data["type_map"] + type_map = data.pop("type_map") models = [ - getattr(sys.modules[__name__], name).deserialize(model) - for name, model in zip(model_names, data["models"]) + BaseAtomicModel.get_class_by_type(model["type"]).deserialize(model) + for model in data["models"] ] - return models, type_map + data.pop("models") + return cls(models, type_map, **data) - @abstractmethod + # @abstractmethod def _compute_weight( self, extended_coord: np.ndarray, @@ -336,9 +334,9 @@ def serialize(self) -> dict: "@class": "Model", "type": "zbl", "@version": 1, - "models": LinearEnergyAtomicModel.serialize( - [self.dp_model, self.zbl_model], self.type_map - ), + "models": LinearEnergyAtomicModel( + models=[self.models[0], self.models[1]], type_map=self.type_map + ).serialize(), "sw_rmin": self.sw_rmin, "sw_rmax": self.sw_rmax, "smin_alpha": self.smin_alpha, @@ -355,10 +353,11 @@ def deserialize(cls, data) -> "DPZBLLinearEnergyAtomicModel": sw_rmin = data.pop("sw_rmin") sw_rmax = data.pop("sw_rmax") smin_alpha = data.pop("smin_alpha") - - ([dp_model, zbl_model], type_map) = LinearEnergyAtomicModel.deserialize( + linear_model = LinearEnergyAtomicModel.deserialize( data.pop("models") ) + dp_model, zbl_model = linear_model.models + type_map = linear_model.type_map return cls( dp_model=dp_model, diff --git a/deepmd/dpmodel/atomic_model/pairtab_atomic_model.py b/deepmd/dpmodel/atomic_model/pairtab_atomic_model.py index 46ec808ad4..bd2c1ccbdb 100644 --- a/deepmd/dpmodel/atomic_model/pairtab_atomic_model.py +++ b/deepmd/dpmodel/atomic_model/pairtab_atomic_model.py @@ -24,7 +24,7 @@ BaseAtomicModel, ) - +@BaseAtomicModel.register("pairtab") class PairTabAtomicModel(BaseAtomicModel): """Pairwise tabulation energy model. diff --git a/deepmd/pt/model/atomic_model/dp_atomic_model.py b/deepmd/pt/model/atomic_model/dp_atomic_model.py index ec08850524..7a3bf4ac72 100644 --- a/deepmd/pt/model/atomic_model/dp_atomic_model.py +++ b/deepmd/pt/model/atomic_model/dp_atomic_model.py @@ -32,7 +32,7 @@ log = logging.getLogger(__name__) - +@BaseAtomicModel.register("standard") class DPAtomicModel(torch.nn.Module, BaseAtomicModel): """Model give atomic prediction of some physical property. diff --git a/deepmd/pt/model/atomic_model/linear_atomic_model.py b/deepmd/pt/model/atomic_model/linear_atomic_model.py index 1649921270..d9ed15b7a6 100644 --- a/deepmd/pt/model/atomic_model/linear_atomic_model.py +++ b/deepmd/pt/model/atomic_model/linear_atomic_model.py @@ -260,30 +260,30 @@ def fitting_output_def(self) -> FittingOutputDef: ] ) - @staticmethod - def serialize(models, type_map) -> dict: + def serialize(self) -> dict: return { "@class": "Model", "@version": 1, "type": "linear", - "models": [model.serialize() for model in models], - "model_name": [model.__class__.__name__ for model in models], - "type_map": type_map, + "models": [model.serialize() for model in self.models], + "type_map": self.type_map, } - @staticmethod - def deserialize(data) -> Tuple[List[BaseAtomicModel], List[str]]: + @classmethod + def deserialize(cls, data: dict) -> "LinearEnergyAtomicModel": data = copy.deepcopy(data) check_version_compatibility(data.pop("@version", 1), 1, 1) - model_names = data["model_name"] - type_map = data["type_map"] + data.pop("@class") + data.pop("type") + type_map = data.pop("type_map") models = [ - getattr(sys.modules[__name__], name).deserialize(model) - for name, model in zip(model_names, data["models"]) + BaseAtomicModel.get_class_by_type(model["type"]).deserialize(model) + for model in data["models"] ] - return models, type_map + data.pop("models") + return cls(models, type_map, **data) - @abstractmethod + # @abstractmethod def _compute_weight( self, extended_coord, extended_atype, nlists_ ) -> List[torch.Tensor]: @@ -403,9 +403,9 @@ def serialize(self) -> dict: "@class": "Model", "@version": 1, "type": "zbl", - "models": LinearEnergyAtomicModel.serialize( - [self.models[0], self.models[1]], self.type_map - ), + "models": LinearEnergyAtomicModel( + models=[self.models[0], self.models[1]], type_map=self.type_map + ).serialize(), "sw_rmin": self.sw_rmin, "sw_rmax": self.sw_rmax, "smin_alpha": self.smin_alpha, @@ -420,10 +420,11 @@ def deserialize(cls, data) -> "DPZBLLinearEnergyAtomicModel": sw_rmin = data.pop("sw_rmin") sw_rmax = data.pop("sw_rmax") smin_alpha = data.pop("smin_alpha") - - [dp_model, zbl_model], type_map = LinearEnergyAtomicModel.deserialize( + linear_model = LinearEnergyAtomicModel.deserialize( data.pop("models") ) + dp_model, zbl_model = linear_model.models + type_map = linear_model.type_map data.pop("@class", None) data.pop("type", None) diff --git a/deepmd/pt/model/atomic_model/pairtab_atomic_model.py b/deepmd/pt/model/atomic_model/pairtab_atomic_model.py index db0a2efa4a..b9fcbfef8b 100644 --- a/deepmd/pt/model/atomic_model/pairtab_atomic_model.py +++ b/deepmd/pt/model/atomic_model/pairtab_atomic_model.py @@ -34,7 +34,7 @@ BaseAtomicModel, ) - +@BaseAtomicModel.register("pairtab") class PairTabAtomicModel(torch.nn.Module, BaseAtomicModel): """Pairwise tabulation energy model. From 0a2806c506f1f41a7a3e1da63764b34978d1236c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 12 Mar 2024 03:36:18 +0000 Subject: [PATCH 02/10] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- deepmd/dpmodel/atomic_model/dp_atomic_model.py | 1 + deepmd/dpmodel/atomic_model/linear_atomic_model.py | 8 +------- deepmd/dpmodel/atomic_model/pairtab_atomic_model.py | 1 + deepmd/pt/model/atomic_model/dp_atomic_model.py | 1 + deepmd/pt/model/atomic_model/linear_atomic_model.py | 8 +------- deepmd/pt/model/atomic_model/pairtab_atomic_model.py | 1 + 6 files changed, 6 insertions(+), 14 deletions(-) diff --git a/deepmd/dpmodel/atomic_model/dp_atomic_model.py b/deepmd/dpmodel/atomic_model/dp_atomic_model.py index e9d8b8ac09..4907483d1d 100644 --- a/deepmd/dpmodel/atomic_model/dp_atomic_model.py +++ b/deepmd/dpmodel/atomic_model/dp_atomic_model.py @@ -25,6 +25,7 @@ BaseAtomicModel, ) + @BaseAtomicModel.register("standard") class DPAtomicModel(BaseAtomicModel): """Model give atomic prediction of some physical property. diff --git a/deepmd/dpmodel/atomic_model/linear_atomic_model.py b/deepmd/dpmodel/atomic_model/linear_atomic_model.py index b775c8d4d5..abf0a038de 100644 --- a/deepmd/dpmodel/atomic_model/linear_atomic_model.py +++ b/deepmd/dpmodel/atomic_model/linear_atomic_model.py @@ -1,9 +1,5 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import copy -import sys -from abc import ( - abstractmethod, -) from typing import ( Dict, List, @@ -353,9 +349,7 @@ def deserialize(cls, data) -> "DPZBLLinearEnergyAtomicModel": sw_rmin = data.pop("sw_rmin") sw_rmax = data.pop("sw_rmax") smin_alpha = data.pop("smin_alpha") - linear_model = LinearEnergyAtomicModel.deserialize( - data.pop("models") - ) + linear_model = LinearEnergyAtomicModel.deserialize(data.pop("models")) dp_model, zbl_model = linear_model.models type_map = linear_model.type_map diff --git a/deepmd/dpmodel/atomic_model/pairtab_atomic_model.py b/deepmd/dpmodel/atomic_model/pairtab_atomic_model.py index bd2c1ccbdb..99b8ec1eff 100644 --- a/deepmd/dpmodel/atomic_model/pairtab_atomic_model.py +++ b/deepmd/dpmodel/atomic_model/pairtab_atomic_model.py @@ -24,6 +24,7 @@ BaseAtomicModel, ) + @BaseAtomicModel.register("pairtab") class PairTabAtomicModel(BaseAtomicModel): """Pairwise tabulation energy model. diff --git a/deepmd/pt/model/atomic_model/dp_atomic_model.py b/deepmd/pt/model/atomic_model/dp_atomic_model.py index 7a3bf4ac72..5bfe70a5e8 100644 --- a/deepmd/pt/model/atomic_model/dp_atomic_model.py +++ b/deepmd/pt/model/atomic_model/dp_atomic_model.py @@ -32,6 +32,7 @@ log = logging.getLogger(__name__) + @BaseAtomicModel.register("standard") class DPAtomicModel(torch.nn.Module, BaseAtomicModel): """Model give atomic prediction of some physical property. diff --git a/deepmd/pt/model/atomic_model/linear_atomic_model.py b/deepmd/pt/model/atomic_model/linear_atomic_model.py index d9ed15b7a6..f91c5e1d08 100644 --- a/deepmd/pt/model/atomic_model/linear_atomic_model.py +++ b/deepmd/pt/model/atomic_model/linear_atomic_model.py @@ -1,9 +1,5 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import copy -import sys -from abc import ( - abstractmethod, -) from typing import ( Dict, List, @@ -420,9 +416,7 @@ def deserialize(cls, data) -> "DPZBLLinearEnergyAtomicModel": sw_rmin = data.pop("sw_rmin") sw_rmax = data.pop("sw_rmax") smin_alpha = data.pop("smin_alpha") - linear_model = LinearEnergyAtomicModel.deserialize( - data.pop("models") - ) + linear_model = LinearEnergyAtomicModel.deserialize(data.pop("models")) dp_model, zbl_model = linear_model.models type_map = linear_model.type_map diff --git a/deepmd/pt/model/atomic_model/pairtab_atomic_model.py b/deepmd/pt/model/atomic_model/pairtab_atomic_model.py index b9fcbfef8b..90326956b0 100644 --- a/deepmd/pt/model/atomic_model/pairtab_atomic_model.py +++ b/deepmd/pt/model/atomic_model/pairtab_atomic_model.py @@ -34,6 +34,7 @@ BaseAtomicModel, ) + @BaseAtomicModel.register("pairtab") class PairTabAtomicModel(torch.nn.Module, BaseAtomicModel): """Pairwise tabulation energy model. From dec30f9bee07029d90546c31f99356982c0bb0f9 Mon Sep 17 00:00:00 2001 From: Anyang Peng <137014849+anyangml@users.noreply.github.com> Date: Tue, 12 Mar 2024 17:01:13 +0800 Subject: [PATCH 03/10] fix: restore pt backend --- .../model/atomic_model/linear_atomic_model.py | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/deepmd/pt/model/atomic_model/linear_atomic_model.py b/deepmd/pt/model/atomic_model/linear_atomic_model.py index bb29ad7f27..dfb4003e70 100644 --- a/deepmd/pt/model/atomic_model/linear_atomic_model.py +++ b/deepmd/pt/model/atomic_model/linear_atomic_model.py @@ -1,4 +1,5 @@ # SPDX-License-Identifier: LGPL-3.0-or-later +from abc import abstractmethod import copy from typing import ( Dict, @@ -256,13 +257,14 @@ def fitting_output_def(self) -> FittingOutputDef: ] ) - def serialize(self) -> dict: + @staticmethod + def serialize(models, type_map) -> dict: return { "@class": "Model", "@version": 1, "type": "linear", - "models": [model.serialize() for model in self.models], - "type_map": self.type_map, + "models": [model.serialize() for model in models], + "type_map": type_map, } @classmethod @@ -278,8 +280,17 @@ def deserialize(cls, data: dict) -> "LinearEnergyAtomicModel": ] data.pop("models") return cls(models, type_map, **data) + + @staticmethod + def _deserialize_models(data: dict) -> List[BaseAtomicModel]: + + models = [ + BaseAtomicModel.get_class_by_type(model["type"]).deserialize(model) + for model in data["models"] + ] + return models - # @abstractmethod + @abstractmethod def _compute_weight( self, extended_coord, extended_atype, nlists_ ) -> List[torch.Tensor]: @@ -398,9 +409,9 @@ def serialize(self) -> dict: "@class": "Model", "@version": 1, "type": "zbl", - "models": LinearEnergyAtomicModel( + "models": LinearEnergyAtomicModel.serialize( models=[self.models[0], self.models[1]], type_map=self.type_map - ).serialize(), + ), "sw_rmin": self.sw_rmin, "sw_rmax": self.sw_rmax, "smin_alpha": self.smin_alpha, @@ -415,9 +426,9 @@ def deserialize(cls, data) -> "DPZBLLinearEnergyAtomicModel": sw_rmin = data.pop("sw_rmin") sw_rmax = data.pop("sw_rmax") smin_alpha = data.pop("smin_alpha") - linear_model = LinearEnergyAtomicModel.deserialize(data.pop("models")) - dp_model, zbl_model = linear_model.models - type_map = linear_model.type_map + + dp_model, zbl_model = LinearEnergyAtomicModel._deserialize_models(data['models']) + type_map = data.pop("models")["type_map"] data.pop("@class", None) data.pop("type", None) From 0c557733eaa73bbfa517d6495ff955685f9d3da1 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 12 Mar 2024 09:01:44 +0000 Subject: [PATCH 04/10] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- deepmd/pt/model/atomic_model/linear_atomic_model.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/deepmd/pt/model/atomic_model/linear_atomic_model.py b/deepmd/pt/model/atomic_model/linear_atomic_model.py index dfb4003e70..e4d2545961 100644 --- a/deepmd/pt/model/atomic_model/linear_atomic_model.py +++ b/deepmd/pt/model/atomic_model/linear_atomic_model.py @@ -1,6 +1,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later -from abc import abstractmethod import copy +from abc import ( + abstractmethod, +) from typing import ( Dict, List, @@ -280,10 +282,9 @@ def deserialize(cls, data: dict) -> "LinearEnergyAtomicModel": ] data.pop("models") return cls(models, type_map, **data) - + @staticmethod def _deserialize_models(data: dict) -> List[BaseAtomicModel]: - models = [ BaseAtomicModel.get_class_by_type(model["type"]).deserialize(model) for model in data["models"] @@ -426,8 +427,10 @@ def deserialize(cls, data) -> "DPZBLLinearEnergyAtomicModel": sw_rmin = data.pop("sw_rmin") sw_rmax = data.pop("sw_rmax") smin_alpha = data.pop("smin_alpha") - - dp_model, zbl_model = LinearEnergyAtomicModel._deserialize_models(data['models']) + + dp_model, zbl_model = LinearEnergyAtomicModel._deserialize_models( + data["models"] + ) type_map = data.pop("models")["type_map"] data.pop("@class", None) From cf219250f8da2a8513de42a44aa4abd7e033c821 Mon Sep 17 00:00:00 2001 From: Anyang Peng <137014849+anyangml@users.noreply.github.com> Date: Tue, 12 Mar 2024 18:14:24 +0800 Subject: [PATCH 05/10] fix: remove interface --- .../atomic_model/linear_atomic_model.py | 4 +-- .../model/atomic_model/linear_atomic_model.py | 35 ++++++------------- 2 files changed, 13 insertions(+), 26 deletions(-) diff --git a/deepmd/dpmodel/atomic_model/linear_atomic_model.py b/deepmd/dpmodel/atomic_model/linear_atomic_model.py index abf0a038de..89720ab682 100644 --- a/deepmd/dpmodel/atomic_model/linear_atomic_model.py +++ b/deepmd/dpmodel/atomic_model/linear_atomic_model.py @@ -244,7 +244,6 @@ def deserialize(cls, data: dict) -> "LinearEnergyAtomicModel": data.pop("models") return cls(models, type_map, **data) - # @abstractmethod def _compute_weight( self, extended_coord: np.ndarray, @@ -252,7 +251,8 @@ def _compute_weight( nlists_: List[np.ndarray], ) -> np.ndarray: """This should be a list of user defined weights that matches the number of models to be combined.""" - raise NotImplementedError + nmodels= len(self.models) + return [np.ones(1)/nmodels for _ in range(nmodels)] def get_dim_fparam(self) -> int: """Get the number (dimension) of frame parameters of this atomic model.""" diff --git a/deepmd/pt/model/atomic_model/linear_atomic_model.py b/deepmd/pt/model/atomic_model/linear_atomic_model.py index e4d2545961..32fe3666f0 100644 --- a/deepmd/pt/model/atomic_model/linear_atomic_model.py +++ b/deepmd/pt/model/atomic_model/linear_atomic_model.py @@ -1,8 +1,5 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import copy -from abc import ( - abstractmethod, -) from typing import ( Dict, List, @@ -259,14 +256,13 @@ def fitting_output_def(self) -> FittingOutputDef: ] ) - @staticmethod - def serialize(models, type_map) -> dict: + def serialize(self) -> dict: return { "@class": "Model", "@version": 1, "type": "linear", - "models": [model.serialize() for model in models], - "type_map": type_map, + "models": [model.serialize() for model in self.models], + "type_map": self.type_map, } @classmethod @@ -283,20 +279,13 @@ def deserialize(cls, data: dict) -> "LinearEnergyAtomicModel": data.pop("models") return cls(models, type_map, **data) - @staticmethod - def _deserialize_models(data: dict) -> List[BaseAtomicModel]: - models = [ - BaseAtomicModel.get_class_by_type(model["type"]).deserialize(model) - for model in data["models"] - ] - return models - - @abstractmethod def _compute_weight( self, extended_coord, extended_atype, nlists_ ) -> List[torch.Tensor]: """This should be a list of user defined weights that matches the number of models to be combined.""" - raise NotImplementedError + + nmodels= len(self.models) + return [torch.ones(1)/nmodels for _ in range(nmodels)] def get_dim_fparam(self) -> int: """Get the number (dimension) of frame parameters of this atomic model.""" @@ -410,9 +399,9 @@ def serialize(self) -> dict: "@class": "Model", "@version": 1, "type": "zbl", - "models": LinearEnergyAtomicModel.serialize( + "models": LinearEnergyAtomicModel( models=[self.models[0], self.models[1]], type_map=self.type_map - ), + ).serialize(), "sw_rmin": self.sw_rmin, "sw_rmax": self.sw_rmax, "smin_alpha": self.smin_alpha, @@ -427,11 +416,9 @@ def deserialize(cls, data) -> "DPZBLLinearEnergyAtomicModel": sw_rmin = data.pop("sw_rmin") sw_rmax = data.pop("sw_rmax") smin_alpha = data.pop("smin_alpha") - - dp_model, zbl_model = LinearEnergyAtomicModel._deserialize_models( - data["models"] - ) - type_map = data.pop("models")["type_map"] + linear_model = LinearEnergyAtomicModel.deserialize(data.pop("models")) + dp_model, zbl_model = linear_model.models + type_map = linear_model.type_map data.pop("@class", None) data.pop("type", None) From 1bbaf6683f292f914c2b88b19b61130c66f04dda Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 12 Mar 2024 10:15:27 +0000 Subject: [PATCH 06/10] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- deepmd/dpmodel/atomic_model/linear_atomic_model.py | 4 ++-- deepmd/pt/model/atomic_model/linear_atomic_model.py | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/deepmd/dpmodel/atomic_model/linear_atomic_model.py b/deepmd/dpmodel/atomic_model/linear_atomic_model.py index 89720ab682..888b7f96b4 100644 --- a/deepmd/dpmodel/atomic_model/linear_atomic_model.py +++ b/deepmd/dpmodel/atomic_model/linear_atomic_model.py @@ -251,8 +251,8 @@ def _compute_weight( nlists_: List[np.ndarray], ) -> np.ndarray: """This should be a list of user defined weights that matches the number of models to be combined.""" - nmodels= len(self.models) - return [np.ones(1)/nmodels for _ in range(nmodels)] + nmodels = len(self.models) + return [np.ones(1) / nmodels for _ in range(nmodels)] def get_dim_fparam(self) -> int: """Get the number (dimension) of frame parameters of this atomic model.""" diff --git a/deepmd/pt/model/atomic_model/linear_atomic_model.py b/deepmd/pt/model/atomic_model/linear_atomic_model.py index 32fe3666f0..cfb1cf45d9 100644 --- a/deepmd/pt/model/atomic_model/linear_atomic_model.py +++ b/deepmd/pt/model/atomic_model/linear_atomic_model.py @@ -283,9 +283,8 @@ def _compute_weight( self, extended_coord, extended_atype, nlists_ ) -> List[torch.Tensor]: """This should be a list of user defined weights that matches the number of models to be combined.""" - - nmodels= len(self.models) - return [torch.ones(1)/nmodels for _ in range(nmodels)] + nmodels = len(self.models) + return [torch.ones(1) / nmodels for _ in range(nmodels)] def get_dim_fparam(self) -> int: """Get the number (dimension) of frame parameters of this atomic model.""" From eacd49c84ccc70f584377ce7be2978bdb75f157c Mon Sep 17 00:00:00 2001 From: Anyang Peng <137014849+anyangml@users.noreply.github.com> Date: Tue, 12 Mar 2024 22:23:32 +0800 Subject: [PATCH 07/10] chore: bump version --- deepmd/dpmodel/atomic_model/linear_atomic_model.py | 4 ++-- deepmd/pt/model/atomic_model/linear_atomic_model.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/deepmd/dpmodel/atomic_model/linear_atomic_model.py b/deepmd/dpmodel/atomic_model/linear_atomic_model.py index 888b7f96b4..1dc9e27ce3 100644 --- a/deepmd/dpmodel/atomic_model/linear_atomic_model.py +++ b/deepmd/dpmodel/atomic_model/linear_atomic_model.py @@ -329,7 +329,7 @@ def serialize(self) -> dict: { "@class": "Model", "type": "zbl", - "@version": 1, + "@version": 2, "models": LinearEnergyAtomicModel( models=[self.models[0], self.models[1]], type_map=self.type_map ).serialize(), @@ -343,7 +343,7 @@ def serialize(self) -> dict: @classmethod def deserialize(cls, data) -> "DPZBLLinearEnergyAtomicModel": data = copy.deepcopy(data) - check_version_compatibility(data.pop("@version", 1), 1, 1) + check_version_compatibility(data.pop("@version", 1), 2, 1) data.pop("@class") data.pop("type") sw_rmin = data.pop("sw_rmin") diff --git a/deepmd/pt/model/atomic_model/linear_atomic_model.py b/deepmd/pt/model/atomic_model/linear_atomic_model.py index cfb1cf45d9..a8c5b91791 100644 --- a/deepmd/pt/model/atomic_model/linear_atomic_model.py +++ b/deepmd/pt/model/atomic_model/linear_atomic_model.py @@ -396,7 +396,7 @@ def serialize(self) -> dict: dd.update( { "@class": "Model", - "@version": 1, + "@version": 2, "type": "zbl", "models": LinearEnergyAtomicModel( models=[self.models[0], self.models[1]], type_map=self.type_map @@ -411,7 +411,7 @@ def serialize(self) -> dict: @classmethod def deserialize(cls, data) -> "DPZBLLinearEnergyAtomicModel": data = copy.deepcopy(data) - check_version_compatibility(data.pop("@version", 1), 1, 1) + check_version_compatibility(data.pop("@version", 1), 2, 1) sw_rmin = data.pop("sw_rmin") sw_rmax = data.pop("sw_rmax") smin_alpha = data.pop("smin_alpha") From 05921072bfc78e5b001f5022772e699302cb20c0 Mon Sep 17 00:00:00 2001 From: Anyang Peng <137014849+anyangml@users.noreply.github.com> Date: Wed, 13 Mar 2024 09:12:08 +0800 Subject: [PATCH 08/10] fix: add dtype --- deepmd/pt/model/atomic_model/linear_atomic_model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deepmd/pt/model/atomic_model/linear_atomic_model.py b/deepmd/pt/model/atomic_model/linear_atomic_model.py index a8c5b91791..98fd9b40c4 100644 --- a/deepmd/pt/model/atomic_model/linear_atomic_model.py +++ b/deepmd/pt/model/atomic_model/linear_atomic_model.py @@ -284,7 +284,7 @@ def _compute_weight( ) -> List[torch.Tensor]: """This should be a list of user defined weights that matches the number of models to be combined.""" nmodels = len(self.models) - return [torch.ones(1) / nmodels for _ in range(nmodels)] + return [torch.ones(1, dtype=torch.float64, device=env.DEVICE) / nmodels for _ in range(nmodels)] def get_dim_fparam(self) -> int: """Get the number (dimension) of frame parameters of this atomic model.""" From b313b9ca79430899c33bcd2f11f20eda4200f056 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 13 Mar 2024 01:12:58 +0000 Subject: [PATCH 09/10] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- deepmd/pt/model/atomic_model/linear_atomic_model.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/deepmd/pt/model/atomic_model/linear_atomic_model.py b/deepmd/pt/model/atomic_model/linear_atomic_model.py index 98fd9b40c4..f7216f46ef 100644 --- a/deepmd/pt/model/atomic_model/linear_atomic_model.py +++ b/deepmd/pt/model/atomic_model/linear_atomic_model.py @@ -284,7 +284,10 @@ def _compute_weight( ) -> List[torch.Tensor]: """This should be a list of user defined weights that matches the number of models to be combined.""" nmodels = len(self.models) - return [torch.ones(1, dtype=torch.float64, device=env.DEVICE) / nmodels for _ in range(nmodels)] + return [ + torch.ones(1, dtype=torch.float64, device=env.DEVICE) / nmodels + for _ in range(nmodels) + ] def get_dim_fparam(self) -> int: """Get the number (dimension) of frame parameters of this atomic model.""" From 38c1d08925c67247ae7d65776b94998ae1188833 Mon Sep 17 00:00:00 2001 From: Anyang Peng <137014849+anyangml@users.noreply.github.com> Date: Wed, 13 Mar 2024 11:05:44 +0800 Subject: [PATCH 10/10] fix: type --- deepmd/dpmodel/atomic_model/linear_atomic_model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deepmd/dpmodel/atomic_model/linear_atomic_model.py b/deepmd/dpmodel/atomic_model/linear_atomic_model.py index 1dc9e27ce3..088cf34900 100644 --- a/deepmd/dpmodel/atomic_model/linear_atomic_model.py +++ b/deepmd/dpmodel/atomic_model/linear_atomic_model.py @@ -249,7 +249,7 @@ def _compute_weight( extended_coord: np.ndarray, extended_atype: np.ndarray, nlists_: List[np.ndarray], - ) -> np.ndarray: + ) -> List[np.ndarray]: """This should be a list of user defined weights that matches the number of models to be combined.""" nmodels = len(self.models) return [np.ones(1) / nmodels for _ in range(nmodels)]