From e74a6ac99351fd88d2e2ec020855e934f5db571a Mon Sep 17 00:00:00 2001 From: root <2000011006@stu.pku.edu.cn> Date: Mon, 23 Dec 2024 13:15:37 +0800 Subject: [PATCH] change var_name to property_name --- deepmd/pt/infer/deep_eval.py | 2 +- deepmd/pt/model/model/property_model.py | 2 +- deepmd/pt/model/task/fitting.py | 4 +--- deepmd/pt/model/task/property.py | 4 +--- deepmd/utils/out_stat.py | 20 ++++++++++++-------- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/deepmd/pt/infer/deep_eval.py b/deepmd/pt/infer/deep_eval.py index 233a8e7943..3259f8c6a2 100644 --- a/deepmd/pt/infer/deep_eval.py +++ b/deepmd/pt/infer/deep_eval.py @@ -204,7 +204,7 @@ def model_type(self) -> type["DeepEvalWrapper"]: return DeepGlobalPolar elif "wfc" in model_output_type: return DeepWFC - elif "property" in model_output_type: + elif self.dp.model["Default"].get_property_name() in model_output_type: return DeepProperty else: raise RuntimeError("Unknown model type") diff --git a/deepmd/pt/model/model/property_model.py b/deepmd/pt/model/model/property_model.py index 2da7995c80..e0db502aaf 100644 --- a/deepmd/pt/model/model/property_model.py +++ b/deepmd/pt/model/model/property_model.py @@ -76,7 +76,7 @@ def get_task_dim(self) -> int: @torch.jit.export def get_intensive(self) -> bool: """Get whether the property is intensive.""" - return self.model_output_def()["property"].intensive + return self.model_output_def()[self.get_property_name()].intensive @torch.jit.export def get_property_name(self) -> str: diff --git a/deepmd/pt/model/task/fitting.py b/deepmd/pt/model/task/fitting.py index 6eee56c8a0..4a4b8c0a5a 100644 --- a/deepmd/pt/model/task/fitting.py +++ b/deepmd/pt/model/task/fitting.py @@ -368,9 +368,7 @@ def set_case_embd(self, case_idx: int): ] def get_compute_stats_do_not_distinguish_types(self) -> bool: - """ - Get whether the fitting net computes stats which are not distinguished between different types of atoms. - """ + """Get whether the fitting net computes stats which are not distinguished between different types of atoms.""" return False def __setitem__(self, key, value) -> None: diff --git a/deepmd/pt/model/task/property.py b/deepmd/pt/model/task/property.py index f0cfa6f5d9..90bd66c0fb 100644 --- a/deepmd/pt/model/task/property.py +++ b/deepmd/pt/model/task/property.py @@ -127,9 +127,7 @@ def output_def(self) -> FittingOutputDef: ) def get_compute_stats_do_not_distinguish_types(self) -> bool: - """ - Get whether the fitting net computes stats which are not distinguished between different types of atoms. - """ + """Get whether the fitting net computes stats which are not distinguished between different types of atoms.""" return True @classmethod diff --git a/deepmd/utils/out_stat.py b/deepmd/utils/out_stat.py index 4198427414..5a64138a40 100644 --- a/deepmd/utils/out_stat.py +++ b/deepmd/utils/out_stat.py @@ -175,13 +175,17 @@ def compute_stats_do_not_distinguish_types( assert natoms.ndim == 2 assert output_redu.shape[0] == natoms.shape[0] # [nf,1] - computed_output_bias = np.repeat( - np.mean(output_redu, axis=0)[np.newaxis, :], ntypes, axis=0 - ) - output_std = np.std(output_redu, axis=0) - - computed_output_bias = computed_output_bias.reshape([natoms.shape[1]] + var_shape) # noqa: RUF005 - output_std = output_std.reshape(var_shape) - output_std = np.tile(output_std, (computed_output_bias.shape[0], 1)) + if intensive: + computed_output_bias = np.repeat( + np.mean(output_redu, axis=0)[np.newaxis, :], ntypes, axis=0 + ) + output_std = np.std(output_redu, axis=0) + + computed_output_bias = computed_output_bias.reshape([natoms.shape[1]] + var_shape) # noqa: RUF005 + output_std = output_std.reshape(var_shape) + output_std = np.tile(output_std, (computed_output_bias.shape[0], 1)) + else: + # TODO: implement extensive + pass return computed_output_bias, output_std