Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions dpgen2/op/run_lmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def get_output_sign(cls):
"model_devi": Artifact(Path),
"plm_output": Artifact(Path, optional=True),
"optional_output": Artifact(Path, optional=True),
"extra_outputs": Artifact(List[Path]),
}
)

Expand Down Expand Up @@ -213,6 +214,10 @@ def execute(
if ele_temp is not None:
ret_dict["optional_output"] = work_dir / "job.json"

extra_outputs = []
for fname in config["extra_output_files"]:
extra_outputs += list(work_dir.glob(fname))
ret_dict["extra_outputs"] = extra_outputs # type: ignore
return OPIO(ret_dict)

def get_model_devi(self, model_devi_file):
Expand All @@ -226,6 +231,7 @@ def lmp_args():
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"
doc_extra_output_files = "Extra output file names, support wildcards"
return [
Argument("command", str, optional=True, default="lmp", doc=doc_lmp_cmd),
Argument(
Expand Down Expand Up @@ -256,6 +262,13 @@ def lmp_args():
default=False,
doc=doc_use_hdf5,
),
Argument(
"extra_output_files",
list,
optional=True,
default=[],
doc=doc_extra_output_files,
),
]

@staticmethod
Expand Down
5 changes: 5 additions & 0 deletions dpgen2/superop/prep_run_lmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def __init__(
"model_devis": OutputArtifact(),
"plm_output": OutputArtifact(),
"optional_outputs": OutputArtifact(),
"extra_outputs": OutputArtifact(),
}

super().__init__(
Expand Down Expand Up @@ -179,6 +180,7 @@ def _prep_run_lmp(
"model_devi",
"plm_output",
"optional_output",
"extra_outputs",
],
**template_slice_config,
),
Expand Down Expand Up @@ -217,5 +219,8 @@ def _prep_run_lmp(
prep_run_steps.outputs.artifacts[
"optional_outputs"
]._from = run_lmp.outputs.artifacts["optional_output"]
prep_run_steps.outputs.artifacts["extra_outputs"]._from = run_lmp.outputs.artifacts[
"extra_outputs"
]

return prep_run_steps
3 changes: 2 additions & 1 deletion dpgen2/utils/download_dpgen2_artifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ def add_output(
"prep-run-explore": DownloadDefinition()
.add_output("logs")
.add_output("trajs")
.add_output("model_devis"),
.add_output("model_devis")
.add_output("extra_outputs"),
"prep-run-fp": DownloadDefinition()
.add_input("confs")
.add_output("logs")
Expand Down
1 change: 1 addition & 0 deletions tests/mocked_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ def execute(
"log": work_dir / log,
"traj": work_dir / traj,
"model_devi": work_dir / model_devi,
"extra_outputs": [],
}
)

Expand Down
23 changes: 23 additions & 0 deletions tests/op/test_run_lmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,29 @@ def test_error(self, mocked_run):
]
mocked_run.assert_has_calls(calls)

def test_extra_outputs(self):
op = RunLmp()
out = op.execute(
OPIO(
{
"config": {
"command": "echo Hello > foo.txt",
"extra_output_files": ["foo.txt"],
},
"task_name": self.task_name,
"task_path": self.task_path,
"models": self.models,
}
)
)
work_dir = Path(self.task_name)
# check output
self.assertEqual(out["extra_outputs"], [work_dir / "foo.txt"])
self.assertEqual(
(work_dir / "foo.txt").read_text().strip(),
"Hello -i in.lammps -log log.lammps",
)


class TestRunLmpDist(unittest.TestCase):
lmp_config = """variable NSTEPS equal 1000
Expand Down
15 changes: 15 additions & 0 deletions tests/utils/test_dl_dpgen2_arti.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ def test_lmp_download(self, mocked_dl):
path=Path("iter-000001/prep-run-explore/outputs"),
skip_exists=True,
),
mock.call(
"arti-extra_outputs",
path=Path("iter-000001/prep-run-explore/outputs"),
skip_exists=True,
),
]
self.assertEqual(len(mocked_dl.call_args_list), len(expected))
for ii, jj in zip(mocked_dl.call_args_list, expected):
Expand Down Expand Up @@ -253,6 +258,11 @@ def test_update_finished_steps_exist_steps(self, mocked_dl):
path=Path("iter-000001/prep-run-explore/outputs"),
skip_exists=True,
),
mock.call(
"arti-extra_outputs",
path=Path("iter-000001/prep-run-explore/outputs"),
skip_exists=True,
),
]
self.assertEqual(len(mocked_dl.call_args_list), len(expected))
for ii, jj in zip(mocked_dl.call_args_list, expected):
Expand Down Expand Up @@ -315,6 +325,11 @@ def test_update_finished_steps_none_steps(self, mocked_dl):
path=Path("iter-000001/prep-run-explore/outputs"),
skip_exists=True,
),
mock.call(
"arti-extra_outputs",
path=Path("iter-000001/prep-run-explore/outputs"),
skip_exists=True,
),
]
for ii, jj in zip(mocked_dl.call_args_list, expected):
self.assertEqual(ii, jj)