Skip to content

Commit e176e9c

Browse files
Skip completed LAMMPS tasks in hti/ti run (#101)
* Skip completed LAMMPS tasks in hti/ti run * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 6e7ec61 commit e176e9c

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

dpti/hti.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,6 +1409,20 @@ def hti_phase_trans_analyze(job, jdata=None):
14091409
return if_phase_trans
14101410

14111411

1412+
def _is_completed_lammps_task(task_work_path):
1413+
log_file = os.path.join(task_work_path, "log.lammps")
1414+
if not os.path.isfile(log_file):
1415+
return False
1416+
try:
1417+
with open(log_file, errors="ignore") as fp:
1418+
lines = [line.strip() for line in fp if line.strip()]
1419+
if not lines:
1420+
return False
1421+
return lines[0].startswith("LAMMPS") and lines[-1].startswith("Total wall time")
1422+
except OSError:
1423+
return False
1424+
1425+
14121426
def run_task(task_dir, machine_file, task_name, no_dp=False):
14131427
if task_name == "00" or task_name == "01" or task_name == "02":
14141428
job_work_dir_ = glob.glob(os.path.join(task_dir, task_name + "*"))
@@ -1420,6 +1434,10 @@ def run_task(task_dir, machine_file, task_name, no_dp=False):
14201434
job_work_dir = task_dir
14211435
task_dir_list = glob.glob(os.path.join(job_work_dir, "task*"))
14221436
task_dir_list = sorted(task_dir_list)
1437+
task_dir_list = [ii for ii in task_dir_list if not _is_completed_lammps_task(ii)]
1438+
if len(task_dir_list) == 0:
1439+
print("# all tasks already completed; nothing to submit")
1440+
return
14231441
work_base_dir = os.getcwd()
14241442
with open(machine_file) as f:
14251443
mdata = json.load(f)

dpti/ti.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,9 +905,27 @@ def compute_task(job, inte_method, Eo, Eo_err, To, scheme="simpson"):
905905
return info
906906

907907

908+
def _is_completed_lammps_task(task_work_path):
909+
log_file = os.path.join(task_work_path, "log.lammps")
910+
if not os.path.isfile(log_file):
911+
return False
912+
try:
913+
with open(log_file, errors="ignore") as fp:
914+
lines = [line.strip() for line in fp if line.strip()]
915+
if not lines:
916+
return False
917+
return lines[0].startswith("LAMMPS") and lines[-1].startswith("Total wall time")
918+
except OSError:
919+
return False
920+
921+
908922
def run_task(task_name, machine_file):
909923
task_dir_list = glob.glob(os.path.join(task_name, "task.*"))
910924
task_dir_list = sorted(task_dir_list)
925+
task_dir_list = [ii for ii in task_dir_list if not _is_completed_lammps_task(ii)]
926+
if len(task_dir_list) == 0:
927+
print("# all tasks already completed; nothing to submit")
928+
return
911929
work_base_dir = os.getcwd()
912930
with open(machine_file) as f:
913931
mdata = json.load(f)

0 commit comments

Comments
 (0)