From 899aabaa0726e438715fb06ab5e824e724dd6c5d Mon Sep 17 00:00:00 2001 From: zjgemi Date: Thu, 17 Oct 2024 15:27:33 +0800 Subject: [PATCH 1/5] add RunLmpHDF5 Signed-off-by: zjgemi --- dpgen2/entrypoint/submit.py | 3 ++- dpgen2/op/__init__.py | 1 + dpgen2/op/run_lmp.py | 27 ++++++++++++++++++++++++++- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/dpgen2/entrypoint/submit.py b/dpgen2/entrypoint/submit.py index 76f944c6..a46b16dd 100644 --- a/dpgen2/entrypoint/submit.py +++ b/dpgen2/entrypoint/submit.py @@ -110,6 +110,7 @@ RunCalyModelDevi, RunDPTrain, RunLmp, + RunLmpHDF5, RunRelax, RunRelaxHDF5, SelectConfs, @@ -187,7 +188,7 @@ def make_concurrent_learning_op( prep_run_explore_op = PrepRunLmp( "prep-run-lmp", PrepLmp, - RunLmp, + RunLmpHDF5 if explore_config["use_hdf5"] else RunLmp, # type: ignore prep_config=prep_explore_config, run_config=run_explore_config, upload_python_packages=upload_python_packages, diff --git a/dpgen2/op/__init__.py b/dpgen2/op/__init__.py index c79c3946..f4fec3a2 100644 --- a/dpgen2/op/__init__.py +++ b/dpgen2/op/__init__.py @@ -36,6 +36,7 @@ ) from .run_lmp import ( RunLmp, + RunLmpHDF5, ) from .run_relax import ( RunRelax, diff --git a/dpgen2/op/run_lmp.py b/dpgen2/op/run_lmp.py index cca2acfd..64c34c9e 100644 --- a/dpgen2/op/run_lmp.py +++ b/dpgen2/op/run_lmp.py @@ -14,6 +14,7 @@ Tuple, ) +import numpy as np from dargs import ( Argument, ArgumentEncoder, @@ -26,6 +27,7 @@ Artifact, BigParameter, FatalError, + HDF5Datasets, OPIOSign, TransientError, ) @@ -200,7 +202,7 @@ def execute( ret_dict = { "log": work_dir / lmp_log_name, "traj": work_dir / lmp_traj_name, - "model_devi": work_dir / lmp_model_devi_name, + "model_devi": self.get_model_devi(work_dir / lmp_model_devi_name), } plm_output = ( {"plm_output": work_dir / plm_output_name} @@ -213,6 +215,9 @@ def execute( return OPIO(ret_dict) + def get_model_devi(self, model_devi_file): + return model_devi_file + @staticmethod def lmp_args(): doc_lmp_cmd = "The command of LAMMPS" @@ -220,6 +225,7 @@ def lmp_args(): doc_shuffle_models = "Randomly pick a model from the group of models to drive theexploration MD simulation" doc_head = "Select a head from multitask" doc_use_ele_temp = "Whether to use electronic temperature, 0 for no, 1 for frame temperature, and 2 for atomic temperature" + doc_use_hdf5 = "Use HDF5 to store trajs and model_devis" return [ Argument("command", str, optional=True, default="lmp", doc=doc_lmp_cmd), Argument( @@ -243,6 +249,13 @@ def lmp_args(): Argument( "model_frozen_head", str, optional=True, default=None, doc=doc_head ), + Argument( + "use_hdf5", + bool, + optional=True, + default=False, + doc=doc_use_hdf5, + ), ] @staticmethod @@ -374,3 +387,15 @@ def merge_pimd_files(): for model_devi_file in sorted(model_devi_files): with open(model_devi_file, "r") as f2: f.write(f2.read()) + + +class RunLmpHDF5(RunLmp): + @classmethod + def get_output_sign(cls): + output_sign = super().get_output_sign() + output_sign["traj"] = Artifact(HDF5Datasets) + output_sign["model_devi"] = Artifact(HDF5Datasets) + return output_sign + + def get_model_devi(self, model_devi_file): + return np.loadtxt(model_devi_file) From 47a551d207be8dfa8b280beb4d13247e8241a519 Mon Sep 17 00:00:00 2001 From: zjgemi Date: Fri, 18 Oct 2024 14:55:30 +0800 Subject: [PATCH 2/5] fix: pyright and upgrade dflow dependency Signed-off-by: zjgemi --- dpgen2/exploration/render/traj_render_lammps.py | 2 +- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dpgen2/exploration/render/traj_render_lammps.py b/dpgen2/exploration/render/traj_render_lammps.py index 28eb07f6..79ba32dc 100644 --- a/dpgen2/exploration/render/traj_render_lammps.py +++ b/dpgen2/exploration/render/traj_render_lammps.py @@ -60,7 +60,7 @@ def get_model_devi( def _load_one_model_devi(self, fname, model_devi): if isinstance(fname, HDF5Dataset): - dd = fname.get_data() + dd = fname.get_data() # type: ignore else: dd = np.loadtxt(fname) if len(np.shape(dd)) == 1: # In case model-devi.out is 1-dimensional diff --git a/pyproject.toml b/pyproject.toml index bd8c92f2..297ff8a7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,7 +17,7 @@ classifiers = [ dependencies = [ 'numpy', 'dpdata>=0.2.20', - 'pydflow>=1.8.88', + 'pydflow>=1.8.95', 'dargs>=0.3.1', 'scipy', 'lbg', From b25efde60bf568e2dea559a314b3dc974398cd64 Mon Sep 17 00:00:00 2001 From: zjgemi Date: Fri, 18 Oct 2024 15:25:16 +0800 Subject: [PATCH 3/5] fix pyright Signed-off-by: zjgemi --- .../exploration/render/traj_render_lammps.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/dpgen2/exploration/render/traj_render_lammps.py b/dpgen2/exploration/render/traj_render_lammps.py index 79ba32dc..1a3cc917 100644 --- a/dpgen2/exploration/render/traj_render_lammps.py +++ b/dpgen2/exploration/render/traj_render_lammps.py @@ -60,18 +60,18 @@ def get_model_devi( def _load_one_model_devi(self, fname, model_devi): if isinstance(fname, HDF5Dataset): - dd = fname.get_data() # type: ignore + dd = fname.get_data() else: dd = np.loadtxt(fname) - if len(np.shape(dd)) == 1: # In case model-devi.out is 1-dimensional - dd = dd.reshape((1, len(dd))) + if len(np.shape(dd)) == 1: # In case model-devi.out is 1-dimensional # type: ignore + dd = dd.reshape((1, len(dd))) # type: ignore - model_devi.add(DeviManager.MAX_DEVI_V, dd[:, 1]) - model_devi.add(DeviManager.MIN_DEVI_V, dd[:, 2]) - model_devi.add(DeviManager.AVG_DEVI_V, dd[:, 3]) - model_devi.add(DeviManager.MAX_DEVI_F, dd[:, 4]) - model_devi.add(DeviManager.MIN_DEVI_F, dd[:, 5]) - model_devi.add(DeviManager.AVG_DEVI_F, dd[:, 6]) + model_devi.add(DeviManager.MAX_DEVI_V, dd[:, 1]) # type: ignore + model_devi.add(DeviManager.MIN_DEVI_V, dd[:, 2]) # type: ignore + model_devi.add(DeviManager.AVG_DEVI_V, dd[:, 3]) # type: ignore + model_devi.add(DeviManager.MAX_DEVI_F, dd[:, 4]) # type: ignore + model_devi.add(DeviManager.MIN_DEVI_F, dd[:, 5]) # type: ignore + model_devi.add(DeviManager.AVG_DEVI_F, dd[:, 6]) # type: ignore def get_ele_temp(self, optional_outputs): ele_temp = [] From cae657725683b7fa549cbf5aab965476934382b5 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 18 Oct 2024 07:25:39 +0000 Subject: [PATCH 4/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- dpgen2/exploration/render/traj_render_lammps.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dpgen2/exploration/render/traj_render_lammps.py b/dpgen2/exploration/render/traj_render_lammps.py index 1a3cc917..4ee8cd47 100644 --- a/dpgen2/exploration/render/traj_render_lammps.py +++ b/dpgen2/exploration/render/traj_render_lammps.py @@ -63,7 +63,9 @@ def _load_one_model_devi(self, fname, model_devi): dd = fname.get_data() else: dd = np.loadtxt(fname) - if len(np.shape(dd)) == 1: # In case model-devi.out is 1-dimensional # type: ignore + if ( + len(np.shape(dd)) == 1 + ): # In case model-devi.out is 1-dimensional # type: ignore dd = dd.reshape((1, len(dd))) # type: ignore model_devi.add(DeviManager.MAX_DEVI_V, dd[:, 1]) # type: ignore From 5cf58f3c4b6acf67de809c1e89681aef79e85c85 Mon Sep 17 00:00:00 2001 From: zjgemi Date: Mon, 21 Oct 2024 10:12:11 +0800 Subject: [PATCH 5/5] fix pyright Signed-off-by: zjgemi --- dpgen2/exploration/render/traj_render_lammps.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dpgen2/exploration/render/traj_render_lammps.py b/dpgen2/exploration/render/traj_render_lammps.py index 4ee8cd47..d12a1f22 100644 --- a/dpgen2/exploration/render/traj_render_lammps.py +++ b/dpgen2/exploration/render/traj_render_lammps.py @@ -64,8 +64,8 @@ def _load_one_model_devi(self, fname, model_devi): else: dd = np.loadtxt(fname) if ( - len(np.shape(dd)) == 1 - ): # In case model-devi.out is 1-dimensional # type: ignore + len(np.shape(dd)) == 1 # type: ignore + ): # In case model-devi.out is 1-dimensional dd = dd.reshape((1, len(dd))) # type: ignore model_devi.add(DeviManager.MAX_DEVI_V, dd[:, 1]) # type: ignore