Skip to content

Commit

Permalink
Fix bugs related to the customized lmp task group submission (#161)
Browse files Browse the repository at this point in the history
1. run customized command with dpgen run_command.
2. fix bug in run_command interface to dflow.utils.run_command: always
non-interactive. [reverted!`interactive` means the bashrc file would be
sourced, otherwise, not.]
3. optional parameters should be of type `Parameter`, `BigParameter`
cannot be indexed.
4. link plumed input file to lammps task dir. Output plumed if they
present.

---------

Co-authored-by: Han Wang <wang_han@iapcm.ac.cn>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people committed Aug 8, 2023
1 parent 3c790bd commit f4b4d06
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 16 deletions.
20 changes: 15 additions & 5 deletions dpgen2/exploration/task/customized_lmp_template_task_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
Union,
)

from dflow.python import (
FatalError,
)

from dpgen2.constants import (
lmp_conf_name,
lmp_input_name,
Expand Down Expand Up @@ -173,11 +177,17 @@ def _make_customized_task_group(
Path(ff).write_text(cc)
# run all customized shell commands
for ss in self.custom_shell_commands:
# run shell command with os.system
ret = os.system(ss)
# run shell command with dpgen2.utils.run_command
ret, out, err = run_command(ss, shell=True)
if ret != 0:
raise RuntimeError(
f"execution of {ss} returns a non-zero value {ret}"
raise FatalError(
f"customized shell command {ss} failed with return code {ret}\n",
"out msg",
out,
"\n",
"err msg",
err,
"\n",
)
# loop over all pattern matched result dirs
for ff in [
Expand All @@ -191,7 +201,7 @@ def _make_customized_task_group(
# no matched continue
if matched_ff is None:
logging.info(
"No output dir matches the patter {self.output_dir_pattern} "
f"Dir {ff} does not matches the patter {self.output_dir_pattern} "
)
continue
with set_directory(Path(matched_ff)):
Expand Down
2 changes: 1 addition & 1 deletion dpgen2/op/collect_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def get_input_sign(cls):
{
"name": str,
"type_map": List[str],
"optional_parameter": BigParameter(
"optional_parameter": Parameter(
dict,
default=CollectData.default_optional_parameter,
),
Expand Down
3 changes: 2 additions & 1 deletion dpgen2/op/run_dp_train.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
BigParameter,
FatalError,
OPIOSign,
Parameter,
TransientError,
)

Expand Down Expand Up @@ -60,7 +61,7 @@ def get_input_sign(cls):
{
"config": dict,
"task_name": BigParameter(str),
"optional_parameter": BigParameter(
"optional_parameter": Parameter(
dict,
default=RunDPTrain.default_optional_parameter,
),
Expand Down
34 changes: 25 additions & 9 deletions dpgen2/op/run_lmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
lmp_traj_name,
model_name_match_pattern,
model_name_pattern,
plm_output_name,
)
from dpgen2.utils import (
BinaryFileInput,
Expand Down Expand Up @@ -117,8 +118,9 @@ def execute(
task_name = ip["task_name"]
task_path = ip["task_path"]
models = ip["models"]
input_files = [lmp_conf_name, lmp_input_name]
input_files = [(Path(task_path) / ii).resolve() for ii in input_files]
# input_files = [lmp_conf_name, lmp_input_name]
# input_files = [(Path(task_path) / ii).resolve() for ii in input_files]
input_files = [ii.resolve() for ii in Path(task_path).iterdir()]
model_files = [Path(ii).resolve() for ii in models]
work_dir = Path(task_name)

Expand Down Expand Up @@ -150,16 +152,30 @@ def execute(
ret, out, err = run_command(command, shell=True)
if ret != 0:
raise TransientError(
"lmp failed\n", "out msg", out, "\n", "err msg", err, "\n"
"lmp failed\n",
"command was",
command,
"out msg",
out,
"\n",
"err msg",
err,
"\n",
)

return OPIO(
{
"log": work_dir / lmp_log_name,
"traj": work_dir / lmp_traj_name,
"model_devi": work_dir / lmp_model_devi_name,
}
ret_dict = {
"log": work_dir / lmp_log_name,
"traj": work_dir / lmp_traj_name,
"model_devi": work_dir / lmp_model_devi_name,
}
plm_output = (
{"plm_output": work_dir / plm_output_name}
if (work_dir / plm_output_name).is_file()
else {}
)
ret_dict.update(plm_output)

return OPIO(ret_dict)

@staticmethod
def lmp_args():
Expand Down

0 comments on commit f4b4d06

Please sign in to comment.