diff --git a/deepmd/dpmodel/atomic_model/dp_atomic_model.py b/deepmd/dpmodel/atomic_model/dp_atomic_model.py index 3db0bb0c68..01b996b80e 100644 --- a/deepmd/dpmodel/atomic_model/dp_atomic_model.py +++ b/deepmd/dpmodel/atomic_model/dp_atomic_model.py @@ -1,5 +1,4 @@ # SPDX-License-Identifier: LGPL-3.0-or-later -import copy from typing import ( Optional, ) @@ -208,7 +207,7 @@ def serialize(self) -> dict: @classmethod def deserialize(cls, data) -> "DPAtomicModel": - data = copy.deepcopy(data) + data = data.copy() check_version_compatibility(data.pop("@version", 1), 2, 2) data.pop("@class") data.pop("type") diff --git a/deepmd/dpmodel/atomic_model/linear_atomic_model.py b/deepmd/dpmodel/atomic_model/linear_atomic_model.py index 2c7e029d53..243be6f2da 100644 --- a/deepmd/dpmodel/atomic_model/linear_atomic_model.py +++ b/deepmd/dpmodel/atomic_model/linear_atomic_model.py @@ -1,5 +1,4 @@ # SPDX-License-Identifier: LGPL-3.0-or-later -import copy from typing import ( Optional, Union, @@ -305,7 +304,7 @@ def serialize(self) -> dict: @classmethod def deserialize(cls, data: dict) -> "LinearEnergyAtomicModel": - data = copy.deepcopy(data) + data = data.copy() check_version_compatibility(data.pop("@version", 2), 2, 2) data.pop("@class", None) data.pop("type", None) @@ -418,7 +417,7 @@ def serialize(self) -> dict: @classmethod def deserialize(cls, data) -> "DPZBLLinearEnergyAtomicModel": - data = copy.deepcopy(data) + data = data.copy() check_version_compatibility(data.pop("@version", 1), 2, 2) models = [ BaseAtomicModel.get_class_by_type(model["type"]).deserialize(model) diff --git a/deepmd/dpmodel/atomic_model/pairtab_atomic_model.py b/deepmd/dpmodel/atomic_model/pairtab_atomic_model.py index c927089daf..ba7a85a3fe 100644 --- a/deepmd/dpmodel/atomic_model/pairtab_atomic_model.py +++ b/deepmd/dpmodel/atomic_model/pairtab_atomic_model.py @@ -1,5 +1,4 @@ # SPDX-License-Identifier: LGPL-3.0-or-later -import copy from typing import ( Optional, Union, @@ -174,7 +173,7 @@ def serialize(self) -> dict: @classmethod def deserialize(cls, data) -> "PairTabAtomicModel": - data = copy.deepcopy(data) + data = data.copy() check_version_compatibility(data.pop("@version", 1), 2, 2) data.pop("@class") data.pop("type") diff --git a/deepmd/dpmodel/descriptor/se_e2_a.py b/deepmd/dpmodel/descriptor/se_e2_a.py index 6c0efb94d4..63402b6f84 100644 --- a/deepmd/dpmodel/descriptor/se_e2_a.py +++ b/deepmd/dpmodel/descriptor/se_e2_a.py @@ -1,5 +1,4 @@ # SPDX-License-Identifier: LGPL-3.0-or-later -import copy import itertools from typing import ( Any, @@ -460,7 +459,7 @@ def serialize(self) -> dict: @classmethod def deserialize(cls, data: dict) -> "DescrptSeA": """Deserialize from dict.""" - data = copy.deepcopy(data) + data = data.copy() check_version_compatibility(data.pop("@version", 1), 2, 1) data.pop("@class", None) data.pop("type", None) diff --git a/deepmd/dpmodel/descriptor/se_r.py b/deepmd/dpmodel/descriptor/se_r.py index 0f646e143c..d652eb1420 100644 --- a/deepmd/dpmodel/descriptor/se_r.py +++ b/deepmd/dpmodel/descriptor/se_r.py @@ -1,5 +1,4 @@ # SPDX-License-Identifier: LGPL-3.0-or-later -import copy from typing import ( Any, Optional, @@ -388,7 +387,7 @@ def serialize(self) -> dict: @classmethod def deserialize(cls, data: dict) -> "DescrptSeR": """Deserialize from dict.""" - data = copy.deepcopy(data) + data = data.copy() check_version_compatibility(data.pop("@version", 1), 2, 1) data.pop("@class", None) data.pop("type", None) diff --git a/deepmd/dpmodel/descriptor/se_t.py b/deepmd/dpmodel/descriptor/se_t.py index 5bc5970a87..be587c77da 100644 --- a/deepmd/dpmodel/descriptor/se_t.py +++ b/deepmd/dpmodel/descriptor/se_t.py @@ -1,5 +1,4 @@ # SPDX-License-Identifier: LGPL-3.0-or-later -import copy import itertools from typing import ( Optional, @@ -388,7 +387,7 @@ def serialize(self) -> dict: @classmethod def deserialize(cls, data: dict) -> "DescrptSeT": """Deserialize from dict.""" - data = copy.deepcopy(data) + data = data.copy() check_version_compatibility(data.pop("@version", 1), 2, 1) data.pop("@class", None) data.pop("type", None) diff --git a/deepmd/dpmodel/fitting/dipole_fitting.py b/deepmd/dpmodel/fitting/dipole_fitting.py index cecba865d0..5988951445 100644 --- a/deepmd/dpmodel/fitting/dipole_fitting.py +++ b/deepmd/dpmodel/fitting/dipole_fitting.py @@ -1,5 +1,4 @@ # SPDX-License-Identifier: LGPL-3.0-or-later -import copy from typing import ( Any, Optional, @@ -156,7 +155,7 @@ def serialize(self) -> dict: @classmethod def deserialize(cls, data: dict) -> "GeneralFitting": - data = copy.deepcopy(data) + data = data.copy() check_version_compatibility(data.pop("@version", 1), 2, 1) var_name = data.pop("var_name", None) assert var_name == "dipole" diff --git a/deepmd/dpmodel/fitting/dos_fitting.py b/deepmd/dpmodel/fitting/dos_fitting.py index 32225ac6c0..cd70a35d06 100644 --- a/deepmd/dpmodel/fitting/dos_fitting.py +++ b/deepmd/dpmodel/fitting/dos_fitting.py @@ -1,5 +1,4 @@ # SPDX-License-Identifier: LGPL-3.0-or-later -import copy from typing import ( TYPE_CHECKING, Optional, @@ -73,7 +72,7 @@ def __init__( @classmethod def deserialize(cls, data: dict) -> "GeneralFitting": - data = copy.deepcopy(data) + data = data.copy() check_version_compatibility(data.pop("@version", 1), 2, 1) data["numb_dos"] = data.pop("dim_out") data.pop("tot_ener_zero", None) diff --git a/deepmd/dpmodel/fitting/ener_fitting.py b/deepmd/dpmodel/fitting/ener_fitting.py index 9a1eae0156..1b6e1d28b2 100644 --- a/deepmd/dpmodel/fitting/ener_fitting.py +++ b/deepmd/dpmodel/fitting/ener_fitting.py @@ -1,5 +1,4 @@ # SPDX-License-Identifier: LGPL-3.0-or-later -import copy from typing import ( TYPE_CHECKING, Any, @@ -73,7 +72,7 @@ def __init__( @classmethod def deserialize(cls, data: dict) -> "GeneralFitting": - data = copy.deepcopy(data) + data = data.copy() check_version_compatibility(data.pop("@version", 1), 2, 1) data.pop("var_name") data.pop("dim_out") diff --git a/deepmd/dpmodel/fitting/general_fitting.py b/deepmd/dpmodel/fitting/general_fitting.py index a027e1e59d..344dab7ff1 100644 --- a/deepmd/dpmodel/fitting/general_fitting.py +++ b/deepmd/dpmodel/fitting/general_fitting.py @@ -1,5 +1,4 @@ # SPDX-License-Identifier: LGPL-3.0-or-later -import copy from abc import ( abstractmethod, ) @@ -320,7 +319,7 @@ def serialize(self) -> dict: @classmethod def deserialize(cls, data: dict) -> "GeneralFitting": - data = copy.deepcopy(data) + data = data.copy() data.pop("@class") data.pop("type") variables = data.pop("@variables") diff --git a/deepmd/dpmodel/fitting/invar_fitting.py b/deepmd/dpmodel/fitting/invar_fitting.py index 3f8607109b..afae455441 100644 --- a/deepmd/dpmodel/fitting/invar_fitting.py +++ b/deepmd/dpmodel/fitting/invar_fitting.py @@ -1,5 +1,4 @@ # SPDX-License-Identifier: LGPL-3.0-or-later -import copy from typing import ( Any, Optional, @@ -179,7 +178,7 @@ def serialize(self) -> dict: @classmethod def deserialize(cls, data: dict) -> "GeneralFitting": - data = copy.deepcopy(data) + data = data.copy() check_version_compatibility(data.pop("@version", 1), 2, 1) return super().deserialize(data) diff --git a/deepmd/dpmodel/fitting/polarizability_fitting.py b/deepmd/dpmodel/fitting/polarizability_fitting.py index b972b45971..8cf3c4faaa 100644 --- a/deepmd/dpmodel/fitting/polarizability_fitting.py +++ b/deepmd/dpmodel/fitting/polarizability_fitting.py @@ -1,5 +1,4 @@ # SPDX-License-Identifier: LGPL-3.0-or-later -import copy from typing import ( Any, Optional, @@ -197,7 +196,7 @@ def serialize(self) -> dict: @classmethod def deserialize(cls, data: dict) -> "GeneralFitting": - data = copy.deepcopy(data) + data = data.copy() check_version_compatibility(data.pop("@version", 1), 3, 1) var_name = data.pop("var_name", None) assert var_name == "polar" diff --git a/deepmd/dpmodel/fitting/property_fitting.py b/deepmd/dpmodel/fitting/property_fitting.py index a1b6fe7638..2cb49c3236 100644 --- a/deepmd/dpmodel/fitting/property_fitting.py +++ b/deepmd/dpmodel/fitting/property_fitting.py @@ -1,5 +1,4 @@ # SPDX-License-Identifier: LGPL-3.0-or-later -import copy from typing import ( Optional, Union, @@ -111,7 +110,7 @@ def __init__( @classmethod def deserialize(cls, data: dict) -> "PropertyFittingNet": - data = copy.deepcopy(data) + data = data.copy() check_version_compatibility(data.pop("@version"), 2, 1) data.pop("dim_out") data.pop("var_name") diff --git a/deepmd/dpmodel/utils/network.py b/deepmd/dpmodel/utils/network.py index a81ddb69a6..9ae5fd2b40 100644 --- a/deepmd/dpmodel/utils/network.py +++ b/deepmd/dpmodel/utils/network.py @@ -4,7 +4,6 @@ See issue #2982 for more information. """ -import copy import itertools from typing import ( Callable, @@ -135,7 +134,7 @@ def deserialize(cls, data: dict) -> "NativeLayer": data : dict The dict to deserialize from. """ - data = copy.deepcopy(data) + data = data.copy() check_version_compatibility(data.pop("@version", 1), 1, 1) data.pop("@class", None) variables = data.pop("@variables") @@ -404,7 +403,7 @@ def deserialize(cls, data: dict) -> "LayerNorm": data : dict The dict to deserialize from. """ - data = copy.deepcopy(data) + data = data.copy() check_version_compatibility(data.pop("@version", 1), 1, 1) data.pop("@class", None) variables = data.pop("@variables") @@ -673,7 +672,7 @@ def deserialize(cls, data: dict) -> "EmbeddingNet": data : dict The dict to deserialize from. """ - data = copy.deepcopy(data) + data = data.copy() check_version_compatibility(data.pop("@version", 1), 2, 1) data.pop("@class", None) layers = data.pop("layers") @@ -778,7 +777,7 @@ def deserialize(cls, data: dict) -> "FittingNet": data : dict The dict to deserialize from. """ - data = copy.deepcopy(data) + data = data.copy() check_version_compatibility(data.pop("@version", 1), 1, 1) data.pop("@class", None) layers = data.pop("layers") diff --git a/deepmd/pt/model/atomic_model/base_atomic_model.py b/deepmd/pt/model/atomic_model/base_atomic_model.py index e26549581e..4730de53fa 100644 --- a/deepmd/pt/model/atomic_model/base_atomic_model.py +++ b/deepmd/pt/model/atomic_model/base_atomic_model.py @@ -1,6 +1,5 @@ # SPDX-License-Identifier: LGPL-3.0-or-later -import copy import logging from typing import ( Callable, @@ -331,7 +330,7 @@ def serialize(self) -> dict: @classmethod def deserialize(cls, data: dict) -> "BaseAtomicModel": - data = copy.deepcopy(data) + data = data.copy() variables = data.pop("@variables", None) variables = ( {"out_bias": None, "out_std": None} if variables is None else variables diff --git a/deepmd/pt/model/atomic_model/dp_atomic_model.py b/deepmd/pt/model/atomic_model/dp_atomic_model.py index 4f53fb69f9..1efac7fd1f 100644 --- a/deepmd/pt/model/atomic_model/dp_atomic_model.py +++ b/deepmd/pt/model/atomic_model/dp_atomic_model.py @@ -1,5 +1,4 @@ # SPDX-License-Identifier: LGPL-3.0-or-later -import copy import functools import logging from typing import ( @@ -149,7 +148,7 @@ def serialize(self) -> dict: @classmethod def deserialize(cls, data) -> "DPAtomicModel": - data = copy.deepcopy(data) + data = data.copy() check_version_compatibility(data.pop("@version", 1), 2, 1) data.pop("@class", None) data.pop("type", None) diff --git a/deepmd/pt/model/atomic_model/linear_atomic_model.py b/deepmd/pt/model/atomic_model/linear_atomic_model.py index 33c2eb6c59..318079ef68 100644 --- a/deepmd/pt/model/atomic_model/linear_atomic_model.py +++ b/deepmd/pt/model/atomic_model/linear_atomic_model.py @@ -1,5 +1,4 @@ # SPDX-License-Identifier: LGPL-3.0-or-later -import copy from typing import ( Callable, Optional, @@ -369,7 +368,7 @@ def serialize(self) -> dict: @classmethod def deserialize(cls, data: dict) -> "LinearEnergyAtomicModel": - data = copy.deepcopy(data) + data = data.copy() check_version_compatibility(data.pop("@version", 2), 2, 1) data.pop("@class", None) data.pop("type", None) @@ -563,7 +562,7 @@ def serialize(self) -> dict: @classmethod def deserialize(cls, data) -> "DPZBLLinearEnergyAtomicModel": - data = copy.deepcopy(data) + data = data.copy() check_version_compatibility(data.pop("@version", 1), 2, 1) models = [ BaseAtomicModel.get_class_by_type(model["type"]).deserialize(model) diff --git a/deepmd/pt/model/atomic_model/pairtab_atomic_model.py b/deepmd/pt/model/atomic_model/pairtab_atomic_model.py index 87e3027bc8..8cf76351b7 100644 --- a/deepmd/pt/model/atomic_model/pairtab_atomic_model.py +++ b/deepmd/pt/model/atomic_model/pairtab_atomic_model.py @@ -1,5 +1,4 @@ # SPDX-License-Identifier: LGPL-3.0-or-later -import copy from typing import ( Callable, Optional, @@ -195,7 +194,7 @@ def serialize(self) -> dict: @classmethod def deserialize(cls, data) -> "PairTabAtomicModel": - data = copy.deepcopy(data) + data = data.copy() check_version_compatibility(data.pop("@version", 1), 2, 1) tab = PairTab.deserialize(data.pop("tab")) data.pop("@class", None) diff --git a/deepmd/pt/model/model/dipole_model.py b/deepmd/pt/model/model/dipole_model.py index c83d1f0bf7..537a0fd6a4 100644 --- a/deepmd/pt/model/model/dipole_model.py +++ b/deepmd/pt/model/model/dipole_model.py @@ -1,7 +1,4 @@ # SPDX-License-Identifier: LGPL-3.0-or-later -from copy import ( - deepcopy, -) from typing import ( Optional, ) @@ -40,19 +37,19 @@ def __init__( def translated_output_def(self): out_def_data = self.model_output_def().get_data() output_def = { - "dipole": deepcopy(out_def_data["dipole"]), - "global_dipole": deepcopy(out_def_data["dipole_redu"]), + "dipole": out_def_data["dipole"], + "global_dipole": out_def_data["dipole_redu"], } if self.do_grad_r("dipole"): - output_def["force"] = deepcopy(out_def_data["dipole_derv_r"]) + output_def["force"] = out_def_data["dipole_derv_r"] output_def["force"].squeeze(-2) if self.do_grad_c("dipole"): - output_def["virial"] = deepcopy(out_def_data["dipole_derv_c_redu"]) + output_def["virial"] = out_def_data["dipole_derv_c_redu"] output_def["virial"].squeeze(-2) - output_def["atom_virial"] = deepcopy(out_def_data["dipole_derv_c"]) + output_def["atom_virial"] = out_def_data["dipole_derv_c"] output_def["atom_virial"].squeeze(-3) if "mask" in out_def_data: - output_def["mask"] = deepcopy(out_def_data["mask"]) + output_def["mask"] = out_def_data["mask"] return output_def def forward( diff --git a/deepmd/pt/model/model/dos_model.py b/deepmd/pt/model/model/dos_model.py index abfcd4a2b4..1be99624da 100644 --- a/deepmd/pt/model/model/dos_model.py +++ b/deepmd/pt/model/model/dos_model.py @@ -1,7 +1,4 @@ # SPDX-License-Identifier: LGPL-3.0-or-later -from copy import ( - deepcopy, -) from typing import ( Optional, ) @@ -40,11 +37,11 @@ def __init__( def translated_output_def(self): out_def_data = self.model_output_def().get_data() output_def = { - "atom_dos": deepcopy(out_def_data["dos"]), - "dos": deepcopy(out_def_data["dos_redu"]), + "atom_dos": out_def_data["dos"], + "dos": out_def_data["dos_redu"], } if "mask" in out_def_data: - output_def["mask"] = deepcopy(out_def_data["mask"]) + output_def["mask"] = out_def_data["mask"] return output_def def forward( diff --git a/deepmd/pt/model/model/dp_linear_model.py b/deepmd/pt/model/model/dp_linear_model.py index 4028d77228..9d11bca622 100644 --- a/deepmd/pt/model/model/dp_linear_model.py +++ b/deepmd/pt/model/model/dp_linear_model.py @@ -1,7 +1,4 @@ # SPDX-License-Identifier: LGPL-3.0-or-later -from copy import ( - deepcopy, -) from typing import ( Optional, ) @@ -42,19 +39,19 @@ def __init__( def translated_output_def(self): out_def_data = self.model_output_def().get_data() output_def = { - "atom_energy": deepcopy(out_def_data["energy"]), - "energy": deepcopy(out_def_data["energy_redu"]), + "atom_energy": out_def_data["energy"], + "energy": out_def_data["energy_redu"], } if self.do_grad_r("energy"): - output_def["force"] = deepcopy(out_def_data["energy_derv_r"]) + output_def["force"] = out_def_data["energy_derv_r"] output_def["force"].squeeze(-2) if self.do_grad_c("energy"): - output_def["virial"] = deepcopy(out_def_data["energy_derv_c_redu"]) + output_def["virial"] = out_def_data["energy_derv_c_redu"] output_def["virial"].squeeze(-2) - output_def["atom_virial"] = deepcopy(out_def_data["energy_derv_c"]) + output_def["atom_virial"] = out_def_data["energy_derv_c"] output_def["atom_virial"].squeeze(-3) if "mask" in out_def_data: - output_def["mask"] = deepcopy(out_def_data["mask"]) + output_def["mask"] = out_def_data["mask"] return output_def def forward( diff --git a/deepmd/pt/model/model/dp_zbl_model.py b/deepmd/pt/model/model/dp_zbl_model.py index 0f05e3e56d..eacc3cbb3b 100644 --- a/deepmd/pt/model/model/dp_zbl_model.py +++ b/deepmd/pt/model/model/dp_zbl_model.py @@ -1,7 +1,4 @@ # SPDX-License-Identifier: LGPL-3.0-or-later -from copy import ( - deepcopy, -) from typing import ( Optional, ) @@ -42,19 +39,19 @@ def __init__( def translated_output_def(self): out_def_data = self.model_output_def().get_data() output_def = { - "atom_energy": deepcopy(out_def_data["energy"]), - "energy": deepcopy(out_def_data["energy_redu"]), + "atom_energy": out_def_data["energy"], + "energy": out_def_data["energy_redu"], } if self.do_grad_r("energy"): - output_def["force"] = deepcopy(out_def_data["energy_derv_r"]) + output_def["force"] = out_def_data["energy_derv_r"] output_def["force"].squeeze(-2) if self.do_grad_c("energy"): - output_def["virial"] = deepcopy(out_def_data["energy_derv_c_redu"]) + output_def["virial"] = out_def_data["energy_derv_c_redu"] output_def["virial"].squeeze(-2) - output_def["atom_virial"] = deepcopy(out_def_data["energy_derv_c"]) + output_def["atom_virial"] = out_def_data["energy_derv_c"] output_def["atom_virial"].squeeze(-3) if "mask" in out_def_data: - output_def["mask"] = deepcopy(out_def_data["mask"]) + output_def["mask"] = out_def_data["mask"] return output_def def forward( diff --git a/deepmd/pt/model/model/ener_model.py b/deepmd/pt/model/model/ener_model.py index 82f429c4ab..8f7ee2094a 100644 --- a/deepmd/pt/model/model/ener_model.py +++ b/deepmd/pt/model/model/ener_model.py @@ -1,7 +1,4 @@ # SPDX-License-Identifier: LGPL-3.0-or-later -from copy import ( - deepcopy, -) from typing import ( Optional, ) @@ -40,19 +37,19 @@ def __init__( def translated_output_def(self): out_def_data = self.model_output_def().get_data() output_def = { - "atom_energy": deepcopy(out_def_data["energy"]), - "energy": deepcopy(out_def_data["energy_redu"]), + "atom_energy": out_def_data["energy"], + "energy": out_def_data["energy_redu"], } if self.do_grad_r("energy"): - output_def["force"] = deepcopy(out_def_data["energy_derv_r"]) + output_def["force"] = out_def_data["energy_derv_r"] output_def["force"].squeeze(-2) if self.do_grad_c("energy"): - output_def["virial"] = deepcopy(out_def_data["energy_derv_c_redu"]) + output_def["virial"] = out_def_data["energy_derv_c_redu"] output_def["virial"].squeeze(-2) - output_def["atom_virial"] = deepcopy(out_def_data["energy_derv_c"]) + output_def["atom_virial"] = out_def_data["energy_derv_c"] output_def["atom_virial"].squeeze(-3) if "mask" in out_def_data: - output_def["mask"] = deepcopy(out_def_data["mask"]) + output_def["mask"] = out_def_data["mask"] return output_def def forward( diff --git a/deepmd/pt/model/model/polar_model.py b/deepmd/pt/model/model/polar_model.py index 57379ba372..c37f0a32fc 100644 --- a/deepmd/pt/model/model/polar_model.py +++ b/deepmd/pt/model/model/polar_model.py @@ -1,7 +1,4 @@ # SPDX-License-Identifier: LGPL-3.0-or-later -from copy import ( - deepcopy, -) from typing import ( Optional, ) @@ -40,11 +37,11 @@ def __init__( def translated_output_def(self): out_def_data = self.model_output_def().get_data() output_def = { - "polar": deepcopy(out_def_data["polarizability"]), - "global_polar": deepcopy(out_def_data["polarizability_redu"]), + "polar": out_def_data["polarizability"], + "global_polar": out_def_data["polarizability_redu"], } if "mask" in out_def_data: - output_def["mask"] = deepcopy(out_def_data["mask"]) + output_def["mask"] = out_def_data["mask"] return output_def def forward( diff --git a/deepmd/pt/model/model/property_model.py b/deepmd/pt/model/model/property_model.py index 164331f44c..2ee13c3aa3 100644 --- a/deepmd/pt/model/model/property_model.py +++ b/deepmd/pt/model/model/property_model.py @@ -1,7 +1,4 @@ # SPDX-License-Identifier: LGPL-3.0-or-later -from copy import ( - deepcopy, -) from typing import ( Optional, ) @@ -40,11 +37,11 @@ def __init__( def translated_output_def(self): out_def_data = self.model_output_def().get_data() output_def = { - "atom_property": deepcopy(out_def_data["property"]), - "property": deepcopy(out_def_data["property_redu"]), + "atom_property": out_def_data["property"], + "property": out_def_data["property_redu"], } if "mask" in out_def_data: - output_def["mask"] = deepcopy(out_def_data["mask"]) + output_def["mask"] = out_def_data["mask"] return output_def def forward( diff --git a/deepmd/pt/model/model/spin_model.py b/deepmd/pt/model/model/spin_model.py index bc1bc81a74..d4d7ce1c45 100644 --- a/deepmd/pt/model/model/spin_model.py +++ b/deepmd/pt/model/model/spin_model.py @@ -554,9 +554,9 @@ def __init__( def translated_output_def(self): out_def_data = self.model_output_def().get_data() output_def = { - "atom_energy": deepcopy(out_def_data["energy"]), - "energy": deepcopy(out_def_data["energy_redu"]), - "mask_mag": deepcopy(out_def_data["mask_mag"]), + "atom_energy": out_def_data["energy"], + "energy": out_def_data["energy_redu"], + "mask_mag": out_def_data["mask_mag"], } if self.do_grad_r("energy"): output_def["force"] = deepcopy(out_def_data["energy_derv_r"]) diff --git a/deepmd/pt/model/task/dipole.py b/deepmd/pt/model/task/dipole.py index 79f9a0a86c..bc09fa4d0f 100644 --- a/deepmd/pt/model/task/dipole.py +++ b/deepmd/pt/model/task/dipole.py @@ -1,5 +1,4 @@ # SPDX-License-Identifier: LGPL-3.0-or-later -import copy import logging from typing import ( Callable, @@ -128,7 +127,7 @@ def serialize(self) -> dict: @classmethod def deserialize(cls, data: dict) -> "GeneralFitting": - data = copy.deepcopy(data) + data = data.copy() check_version_compatibility(data.pop("@version", 1), 2, 1) data.pop("var_name", None) return super().deserialize(data) diff --git a/deepmd/pt/model/task/dos.py b/deepmd/pt/model/task/dos.py index 4f69094b0d..531ad0a9f3 100644 --- a/deepmd/pt/model/task/dos.py +++ b/deepmd/pt/model/task/dos.py @@ -1,5 +1,4 @@ # SPDX-License-Identifier: LGPL-3.0-or-later -import copy import logging from typing import ( Optional, @@ -99,7 +98,7 @@ def output_def(self) -> FittingOutputDef: @classmethod def deserialize(cls, data: dict) -> "DOSFittingNet": - data = copy.deepcopy(data) + data = data.copy() check_version_compatibility(data.pop("@version", 1), 2, 1) data.pop("@class", None) data.pop("var_name", None) diff --git a/deepmd/pt/model/task/ener.py b/deepmd/pt/model/task/ener.py index ee8372c3ac..0d80006b94 100644 --- a/deepmd/pt/model/task/ener.py +++ b/deepmd/pt/model/task/ener.py @@ -1,5 +1,4 @@ # SPDX-License-Identifier: LGPL-3.0-or-later -import copy import logging from typing import ( Optional, @@ -78,7 +77,7 @@ def __init__( @classmethod def deserialize(cls, data: dict) -> "GeneralFitting": - data = copy.deepcopy(data) + data = data.copy() check_version_compatibility(data.pop("@version", 1), 2, 1) data.pop("var_name") data.pop("dim_out") diff --git a/deepmd/pt/model/task/fitting.py b/deepmd/pt/model/task/fitting.py index b983c574e3..470b420c89 100644 --- a/deepmd/pt/model/task/fitting.py +++ b/deepmd/pt/model/task/fitting.py @@ -1,5 +1,4 @@ # SPDX-License-Identifier: LGPL-3.0-or-later -import copy import logging from abc import ( abstractmethod, @@ -312,7 +311,7 @@ def serialize(self) -> dict: @classmethod def deserialize(cls, data: dict) -> "GeneralFitting": - data = copy.deepcopy(data) + data = data.copy() variables = data.pop("@variables") nets = data.pop("nets") obj = cls(**data) diff --git a/deepmd/pt/model/task/invar_fitting.py b/deepmd/pt/model/task/invar_fitting.py index b9be26cfdc..acdd5b0fda 100644 --- a/deepmd/pt/model/task/invar_fitting.py +++ b/deepmd/pt/model/task/invar_fitting.py @@ -1,5 +1,4 @@ # SPDX-License-Identifier: LGPL-3.0-or-later -import copy import logging from typing import ( Optional, @@ -141,7 +140,7 @@ def serialize(self) -> dict: @classmethod def deserialize(cls, data: dict) -> "GeneralFitting": - data = copy.deepcopy(data) + data = data.copy() check_version_compatibility(data.pop("@version", 1), 2, 1) return super().deserialize(data) diff --git a/deepmd/pt/model/task/polarizability.py b/deepmd/pt/model/task/polarizability.py index 512044efbd..7b7f92c3af 100644 --- a/deepmd/pt/model/task/polarizability.py +++ b/deepmd/pt/model/task/polarizability.py @@ -1,5 +1,4 @@ # SPDX-License-Identifier: LGPL-3.0-or-later -import copy import logging from typing import ( Optional, @@ -202,7 +201,7 @@ def serialize(self) -> dict: @classmethod def deserialize(cls, data: dict) -> "GeneralFitting": - data = copy.deepcopy(data) + data = data.copy() check_version_compatibility(data.pop("@version", 1), 3, 1) data.pop("var_name", None) return super().deserialize(data) diff --git a/deepmd/pt/model/task/property.py b/deepmd/pt/model/task/property.py index 4017f51468..0108b83dff 100644 --- a/deepmd/pt/model/task/property.py +++ b/deepmd/pt/model/task/property.py @@ -1,5 +1,4 @@ # SPDX-License-Identifier: LGPL-3.0-or-later -import copy import logging from typing import ( Optional, @@ -129,7 +128,7 @@ def output_def(self) -> FittingOutputDef: @classmethod def deserialize(cls, data: dict) -> "PropertyFittingNet": - data = copy.deepcopy(data) + data = data.copy() check_version_compatibility(data.pop("@version", 1), 2, 1) data.pop("dim_out") data.pop("var_name") diff --git a/deepmd/tf/model/model.py b/deepmd/tf/model/model.py index 51c66de65e..5e3f99bc2d 100644 --- a/deepmd/tf/model/model.py +++ b/deepmd/tf/model/model.py @@ -1,5 +1,4 @@ # SPDX-License-Identifier: LGPL-3.0-or-later -import copy from abc import ( ABC, abstractmethod, @@ -804,7 +803,7 @@ def deserialize(cls, data: dict, suffix: str = "") -> "Descriptor": Descriptor The deserialized descriptor """ - data = copy.deepcopy(data) + data = data.copy() check_version_compatibility(data.pop("@version", 2), 2, 1) descriptor = Descriptor.deserialize(data.pop("descriptor"), suffix=suffix) fitting = Fitting.deserialize(data.pop("fitting"), suffix=suffix) diff --git a/source/tests/consistent/io/test_io.py b/source/tests/consistent/io/test_io.py index ca213da13c..85c5210e94 100644 --- a/source/tests/consistent/io/test_io.py +++ b/source/tests/consistent/io/test_io.py @@ -91,8 +91,8 @@ def test_data_equal(self): prefix + backend.suffixes[suffix_idx], reference_data ) data = self.get_data_from_model(prefix + backend.suffixes[suffix_idx]) - data = copy.deepcopy(data) - reference_data = copy.deepcopy(self.data) + data = data.copy() + reference_data = self.data.copy() # some keys are not expected to be not the same for kk in [ "backend",