Browse Source

Enabled running of int2lm (I2LM) via available scripts

experiments/run-int2lm
Sven Karsten 2 years ago
parent
commit
ef80dc3c18
  1. 12
      scripts/run/create_work_directory_I2LM.py
  2. 22
      scripts/run/move_results_I2LM.py
  3. 11
      scripts/run/mpi_task_after1.py
  4. 8
      scripts/run/mpi_task_after2.py
  5. 15
      scripts/run/run.py

12
scripts/run/create_work_directory_I2LM.py

@ -48,6 +48,8 @@ def create_work_directory_I2LM(IOW_ESM_ROOT, # root directory of IOW ESM
starthours = (my_startdate - my_initdate).days*24
finalhours = (my_enddate - my_initdate).days*24
# int2lm needs hours in start time, since we allow at maximum a daily resolution in job run time
# we will always start from hour zero
start_date = start_date + '00'
change_in_namelist.change_in_namelist(filename=full_directory+'/INPUT',
@ -66,9 +68,8 @@ def create_work_directory_I2LM(IOW_ESM_ROOT, # root directory of IOW ESM
after='&DATA', before='/END', start_of_line='yncglob_institution',
new_value = '=\''+institution+'\',')
# STEP 2: Read model options file
print('opening: ' + full_directory + '/model_settings.py')
exec(open(full_directory + '/model_settings.py').read(), globals())
# STEP 2: Read local options file
exec(open(full_directory + '/local_settings.py').read(), globals())
change_in_namelist.change_in_namelist(filename=full_directory+'/INPUT',
after='&DATA', before='/END', start_of_line='ylmext_lfn',
@ -98,8 +99,9 @@ def create_work_directory_I2LM(IOW_ESM_ROOT, # root directory of IOW ESM
change_in_namelist.change_in_namelist(filename=full_directory+'/INPUT',
after='&DATA', before='/END', start_of_line='ylm_cat',
new_value = '=\'' + output_dir +'\',')
os.mkdir(output_dir)
if not os.path.isdir(output_dir):
os.mkdir(output_dir)
change_in_namelist.change_in_namelist(filename=full_directory+'/INPUT',
after='&DATA', before='/END', start_of_line='yncglob_source',

22
scripts/run/move_results_I2LM.py

@ -0,0 +1,22 @@
# This script will fill the required files into the work directory for a CCLM model.
# The function is called from create_work_directories.py
import os
import shutil
def move_results_I2LM(workdir, # work directory of this model instance
outputdir, # directory for output
hotstartdir, # directory for hotstarts
start_date):
# STEP 1: CREATE DIRECTORIES IF REQUIRED
if (not os.path.isdir(outputdir)):
os.makedirs(outputdir)
if (not os.path.isdir(hotstartdir)):
os.makedirs(hotstartdir)
# STEP 2: MOVE OUTPUT
os.system('mv '+workdir+'/'+start_date+' '+outputdir+'/.')
# STEP 3: MOVE HOTSTART
# there is no real hotstart file, the existence of the hotstart folder marks where we stopped

11
scripts/run/mpi_task_after1.py

@ -47,7 +47,8 @@ if firstinnode[my_id]:
###############################################################################################
local_workdir_base = os.environ["IOW_ESM_LOCAL_WORKDIR_BASE"]
global_workdir_base = os.environ["IOW_ESM_GLOBAL_WORKDIR_BASE"]
end_date = os.environ["IOW_ESM_END_DATE"]
end_date = os.environ["IOW_ESM_END_DATE"]
start_date = os.environ["IOW_ESM_START_DATE"]
############################################
# STEP 5: Check if the model run succeeded #
@ -75,6 +76,14 @@ if firstinnode[my_id]:
failfile = open(global_workdir_base+'/failed_'+my_model+'.txt', 'w')
failfile.writelines('Model '+my_model+' failed and did not reach the end date '+end_date+'\n')
failfile.close()
if my_model[0:5]=='I2LM_':
if firstthread[my_id]: # only the first thread must write a hotstart file
lastfile = local_workdir_base+'/'+my_model+'/'+str(start_date)+'/lbfd'+str(end_date)+'00.nc'
if not files_exist(lastfile): # this does not exist -> run failed
print('run failed because no file exists:'+lastfile)
failfile = open(global_workdir_base+'/failed_'+my_model+'.txt', 'w')
failfile.writelines('Model '+my_model+' failed and did not reach the end date '+end_date+'\n')
failfile.close()
##########################################################################
# STEP 6: If required, copy the work directory to the global file system #

8
scripts/run/mpi_task_after2.py

@ -6,6 +6,7 @@ import shutil
import move_results_CCLM
import move_results_MOM5
import move_results_I2LM
# get current folder and check if it is scripts/run
mydir = os.getcwd()
@ -60,4 +61,11 @@ if firstinnode[my_id]:
IOW_ESM_ROOT+'/output/'+run_name+'/'+my_model+'/'+start_date, #outputdir
IOW_ESM_ROOT+'/hotstart/'+run_name+'/'+my_model+'/'+end_date, #hotstartdir
end_date)
if my_model[0:5]=='I2LM_':
if firstthread[my_id]: # only the first thread will write output and hotstarts
move_results_I2LM.move_results_I2LM(work_directory_root+'/'+model, #workdir
IOW_ESM_ROOT+'/output/'+run_name+'/'+my_model+'/'+start_date, #outputdir
IOW_ESM_ROOT+'/hotstart/'+run_name+'/'+my_model+'/'+end_date, #hotstartdir
str(start_date))
os.system('sync')

15
scripts/run/run.py

@ -13,6 +13,7 @@ import create_work_directories
import move_results_CCLM
import move_results_MOM5
import move_results_I2LM
import create_namcouple
@ -212,6 +213,13 @@ for run in range(runs_per_job):
failfile = open(work_directory_root+'/failed_'+model+'.txt', 'w')
failfile.writelines('Model '+model+' failed and did not reach the end date '+str(end_date)+'\n')
failfile.close()
if model[0:5]=='I2LM_':
lastfile = work_directory_root+'/'+model+'/'+str(start_date)+'/lbfd'+str(end_date)+'00.nc'
if not files_exist(lastfile): # this does not exist -> run failed
print('run failed because no file exists:'+lastfile)
failfile = open(work_directory_root+'/failed_'+model+'.txt', 'w')
failfile.writelines('Model '+model+' failed and did not reach the end date '+str(end_date)+'\n')
failfile.close()
else:
# DO THE LOCAL POSTPROCESSING STEP 1: POSSIBLY COPY LOCAL WORKDIRS TO THE GLOBAL ONE AND CHECK WHETHER THE JOB FAILED
@ -219,6 +227,7 @@ for run in range(runs_per_job):
shellscript.writelines('export IOW_ESM_LOCAL_WORKDIR_BASE='+local_workdir_base+'\n')
shellscript.writelines('export IOW_ESM_GLOBAL_WORKDIR_BASE='+work_directory_root+'\n')
shellscript.writelines('export IOW_ESM_END_DATE='+str(end_date)+'\n')
shellscript.writelines('export IOW_ESM_START_DATE='+str(start_date)+'\n')
shellscript.writelines('python3 mpi_task_after1.py')
shellscript.close()
st = os.stat('run_after1.sh') # get current permissions
@ -279,6 +288,12 @@ for run in range(runs_per_job):
move_results_MOM5.move_results_MOM5(work_directory_root+'/'+model, #workdir
IOW_ESM_ROOT+'/output/'+run_name+'/'+model+'/'+str(start_date), #outputdir
IOW_ESM_ROOT+'/hotstart/'+run_name+'/'+model+'/'+str(end_date)) #hotstartdir
if model[0:5]=='I2LM_':
move_results_I2LM.move_results_I2LM(work_directory_root+'/'+model, #workdir
IOW_ESM_ROOT+'/output/'+run_name+'/'+model, #outputdir
IOW_ESM_ROOT+'/hotstart/'+run_name+'/'+model+'/'+str(end_date), #hotstartdir
str(start_date))
# PROCEED TO NEXT RUN
start_date = end_date

Loading…
Cancel
Save