Skip to content

Commit

Permalink
Cluster scripts, auto_hotstart.py: added an option to remove previous…
Browse files Browse the repository at this point in the history
… hostart files (default) to save space.
  • Loading branch information
feiye-vims committed Oct 23, 2023
1 parent b98a2d8 commit ba42cdb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
21 changes: 15 additions & 6 deletions src/Utility/Cluster_files/auto_hotstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,25 @@
import subprocess
import glob
import re
from pathlib import Path

#----------input---------------------------------
#Used to automatically restart due to wall clock limit
#(1) Copy this script, run_test and run_comb into rundir
#(2) Inside rundir: prep inputs as before (ihot=1 or 2 is fine):
# The "hotstart.nc" (if it exists under ihot=1 or 2) will be overwritten by this script by symlinks;
# The "hotstart.nc" (if it exists under ihot=1 or 2) will be overwritten by this script by symlinks;
# so always use symlinks for this input.
#(3) Under the run dir, "python auto_hotstart.py >& scrn.out"
#Script will use the last part of current dir as runid

job_scheduler = 'slurm' # 'pbs' or 'slurm'

rundir = os.getcwd() # use os.getcwd if launch from rundir; otherwise specify a string yourself
rundir = os.getcwd() # use os.getcwd if launch from rundir; otherwise specify a string yourself, e.g.,
# rundir = '/sciclone/schism10/feiye/STOFS3D-v7/Runs/R02/'
last_stack = None # if None, the script will try to find the last stack number in the file "param.nml"
# make sure the run can finish the specified rnday in param.nml (i.e., the forcing covers the whole period);
# otherwise, change the "rnday" in param.nml or specify another number here

remove_old_hotstart = True # if True, remove all previous hotstart files, including the combined hotstart_it*.nc
#----------end input---------------------------------


Expand Down Expand Up @@ -54,7 +56,7 @@ def ReplaceJobName(fname, job_name, job_scheduler='slurm'):
match_found = True
modified_line = re.sub(pattern, replacement, line)
print(modified_line, end='')

if not match_found:
raise Exception(f'Job name specification not found in {fname}')

Expand Down Expand Up @@ -110,7 +112,7 @@ def Get_var_from_file(fname, var_name):
else:
raise Exception('job_scheduler must be either "slurm" or "pbs"')

run_id = os.path.basename(rundir)
run_id = Path(rundir).name
if len(run_id) > 8:
raise Exception('run_id must be 8 characters or less, otherwise it may be truncated by the job scheduler')
print(f'{my_print_decor}RUN job name : {run_id}{my_print_decor}', flush=True)
Expand Down Expand Up @@ -169,6 +171,13 @@ def Get_var_from_file(fname, var_name):
hot_combined = f'{rundir}/outputs/hotstart_it={hot_step}.nc'
print(f'{my_print_decor}{run_id} stopped, last hotstart to combine: {hot_combined}{my_print_decor}', flush=True)

if remove_old_hotstart: # remove all previous hotstart files, including the combined hotstart_it*.nc
all_hot_files = glob.glob(f"{rundir}/outputs/hotstart_*.nc")
current_hot_files = glob.glob(f"{rundir}/outputs/hotstart_*_{hot_step}.nc")
previous_hot_files = list(set(all_hot_files) - set(current_hot_files))
for previous_hot_file in previous_hot_files:
os.remove(previous_hot_file)

os.chdir(f'{rundir}/outputs/')
Replace_string_in_file(f'{rundir}/run_comb', '-i 0000', f'-i {hot_step}')

Expand All @@ -192,7 +201,7 @@ def Get_var_from_file(fname, var_name):
print(f'{my_print_decor}linking {hot_combined}{my_print_decor}', flush=True)
os.system(f'rm {rundir}/hotstart.nc')
os.symlink(hot_combined, f'{rundir}/hotstart.nc')

# dealing with the paired normal run
if rundir_normal != '':
if re.search(rf"{run_id_normal}\s+{user_name}\s+R", job_status) is not None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def main():

driver_print_prefix = '-----------------STOFS3D-ATL driver:---------------------\n'
# define the path where the model inputs are generated
model_input_path = '/sciclone/schism10/feiye/STOFS3D-v7/Inputs/I00/'
model_input_path = '/sciclone/schism10/feiye/STOFS3D-v7/Inputs/I01/'
# make the directory if it does not exist
try_mkdir(model_input_path)

Expand All @@ -235,8 +235,8 @@ def main():

# set a dict to indicate input files to be generated
input_files = {
'bctides': True,
'vgrid': False,
'bctides': False,
'vgrid': True,
'gr3': False,
'nudge_gr3': False,
'shapiro': False,
Expand Down

0 comments on commit ba42cdb

Please sign in to comment.