Skip to content

Commit 08d8d6e

Browse files
Add RunLmpHDF5 (#267)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced dynamic selection of exploration operations based on configuration settings, enhancing configurability. - Added a new `RunLmpHDF5` option for improved data handling and output types. - **Improvements** - Enhanced the `RunLmp` class with new methods for better processing of model deviation files and output data storage options. - Improved type safety and error handling in the `TrajRenderLammps` class, including better management of temperature settings. - **Dependency Updates** - Updated the version requirement for the `pydflow` dependency to `>=1.8.95`. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: zjgemi <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 336d385 commit 08d8d6e

File tree

5 files changed

+40
-11
lines changed

5 files changed

+40
-11
lines changed

dpgen2/entrypoint/submit.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
RunCalyModelDevi,
111111
RunDPTrain,
112112
RunLmp,
113+
RunLmpHDF5,
113114
RunRelax,
114115
RunRelaxHDF5,
115116
SelectConfs,
@@ -187,7 +188,7 @@ def make_concurrent_learning_op(
187188
prep_run_explore_op = PrepRunLmp(
188189
"prep-run-lmp",
189190
PrepLmp,
190-
RunLmp,
191+
RunLmpHDF5 if explore_config["use_hdf5"] else RunLmp, # type: ignore
191192
prep_config=prep_explore_config,
192193
run_config=run_explore_config,
193194
upload_python_packages=upload_python_packages,

dpgen2/exploration/render/traj_render_lammps.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,17 @@ def _load_one_model_devi(self, fname, model_devi):
6363
dd = fname.get_data()
6464
else:
6565
dd = np.loadtxt(fname)
66-
if len(np.shape(dd)) == 1: # In case model-devi.out is 1-dimensional
67-
dd = dd.reshape((1, len(dd)))
66+
if (
67+
len(np.shape(dd)) == 1 # type: ignore
68+
): # In case model-devi.out is 1-dimensional
69+
dd = dd.reshape((1, len(dd))) # type: ignore
6870

69-
model_devi.add(DeviManager.MAX_DEVI_V, dd[:, 1])
70-
model_devi.add(DeviManager.MIN_DEVI_V, dd[:, 2])
71-
model_devi.add(DeviManager.AVG_DEVI_V, dd[:, 3])
72-
model_devi.add(DeviManager.MAX_DEVI_F, dd[:, 4])
73-
model_devi.add(DeviManager.MIN_DEVI_F, dd[:, 5])
74-
model_devi.add(DeviManager.AVG_DEVI_F, dd[:, 6])
71+
model_devi.add(DeviManager.MAX_DEVI_V, dd[:, 1]) # type: ignore
72+
model_devi.add(DeviManager.MIN_DEVI_V, dd[:, 2]) # type: ignore
73+
model_devi.add(DeviManager.AVG_DEVI_V, dd[:, 3]) # type: ignore
74+
model_devi.add(DeviManager.MAX_DEVI_F, dd[:, 4]) # type: ignore
75+
model_devi.add(DeviManager.MIN_DEVI_F, dd[:, 5]) # type: ignore
76+
model_devi.add(DeviManager.AVG_DEVI_F, dd[:, 6]) # type: ignore
7577

7678
def get_ele_temp(self, optional_outputs):
7779
ele_temp = []

dpgen2/op/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
)
3737
from .run_lmp import (
3838
RunLmp,
39+
RunLmpHDF5,
3940
)
4041
from .run_relax import (
4142
RunRelax,

dpgen2/op/run_lmp.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
Tuple,
1515
)
1616

17+
import numpy as np
1718
from dargs import (
1819
Argument,
1920
ArgumentEncoder,
@@ -26,6 +27,7 @@
2627
Artifact,
2728
BigParameter,
2829
FatalError,
30+
HDF5Datasets,
2931
OPIOSign,
3032
TransientError,
3133
)
@@ -200,7 +202,7 @@ def execute(
200202
ret_dict = {
201203
"log": work_dir / lmp_log_name,
202204
"traj": work_dir / lmp_traj_name,
203-
"model_devi": work_dir / lmp_model_devi_name,
205+
"model_devi": self.get_model_devi(work_dir / lmp_model_devi_name),
204206
}
205207
plm_output = (
206208
{"plm_output": work_dir / plm_output_name}
@@ -213,13 +215,17 @@ def execute(
213215

214216
return OPIO(ret_dict)
215217

218+
def get_model_devi(self, model_devi_file):
219+
return model_devi_file
220+
216221
@staticmethod
217222
def lmp_args():
218223
doc_lmp_cmd = "The command of LAMMPS"
219224
doc_teacher_model = "The teacher model in `Knowledge Distillation`"
220225
doc_shuffle_models = "Randomly pick a model from the group of models to drive theexploration MD simulation"
221226
doc_head = "Select a head from multitask"
222227
doc_use_ele_temp = "Whether to use electronic temperature, 0 for no, 1 for frame temperature, and 2 for atomic temperature"
228+
doc_use_hdf5 = "Use HDF5 to store trajs and model_devis"
223229
return [
224230
Argument("command", str, optional=True, default="lmp", doc=doc_lmp_cmd),
225231
Argument(
@@ -243,6 +249,13 @@ def lmp_args():
243249
Argument(
244250
"model_frozen_head", str, optional=True, default=None, doc=doc_head
245251
),
252+
Argument(
253+
"use_hdf5",
254+
bool,
255+
optional=True,
256+
default=False,
257+
doc=doc_use_hdf5,
258+
),
246259
]
247260

248261
@staticmethod
@@ -374,3 +387,15 @@ def merge_pimd_files():
374387
for model_devi_file in sorted(model_devi_files):
375388
with open(model_devi_file, "r") as f2:
376389
f.write(f2.read())
390+
391+
392+
class RunLmpHDF5(RunLmp):
393+
@classmethod
394+
def get_output_sign(cls):
395+
output_sign = super().get_output_sign()
396+
output_sign["traj"] = Artifact(HDF5Datasets)
397+
output_sign["model_devi"] = Artifact(HDF5Datasets)
398+
return output_sign
399+
400+
def get_model_devi(self, model_devi_file):
401+
return np.loadtxt(model_devi_file)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ classifiers = [
1717
dependencies = [
1818
'numpy',
1919
'dpdata>=0.2.20',
20-
'pydflow>=1.8.88',
20+
'pydflow>=1.8.95',
2121
'dargs>=0.3.1',
2222
'scipy',
2323
'lbg',

0 commit comments

Comments
 (0)