Skip to content

Commit

Permalink
Further work on icon restart
Browse files Browse the repository at this point in the history
  • Loading branch information
mjaehn committed Oct 24, 2023
1 parent cad45d6 commit 46f94e2
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 6 deletions.
6 changes: 3 additions & 3 deletions cases/icon-test/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

model: icon
constraint: gpu
run_on: gpu
run_on: cpu
compute_queue: normal
ntasks_per_node: 12
restart_step: 6
Expand Down Expand Up @@ -46,8 +46,8 @@ icon:
runjob_filename: icon_runjob.cfg
compute_queue: normal
walltime: '00:30:00'
np_tot: 6
np_tot: 12
np_io: 1
np_restart: 1
np_restart: 0
np_prefetch: 1

13 changes: 11 additions & 2 deletions cases/icon-test/icon_runjob.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ cat > icon_master.namelist << EOF
lrestart = {cfg.lrestart} ! .TRUE.=current experiment is resumed
/
! master_time_control_nml: ---------------------------------------------------
&master_time_control_nml
calendar = 'proleptic gregorian'
restartTimeIntval = '{cfg.restart_step_iso}'
checkpointTimeIntval = '{cfg.restart_step_iso}'
experimentStartDate = '{cfg.ini_datetime_string}'
experimentStopDate = '{cfg.end_datetime_string}'
/
! master_model_nml: repeated for each model ----------------------------------
&master_model_nml
model_type = 1 ! identifies which component to run (atmosphere,ocean,...)
Expand Down Expand Up @@ -86,7 +95,7 @@ cat > NAMELIST_{cfg.casename} << EOF
ltransport = .TRUE. ! compute large-scale tracer transport
ntracer = 0 ! number of advected tracers
iforcing = 3 ! forcing of dynamics and transport by parameterized processes
msg_level = 7 ! detailed report during integration
msg_level = 13 ! detailed report during integration
ltimer = .TRUE. ! timer for monitoring the runtime of specific routines
timers_level = 10 ! performance timer granularity
check_uuid_gracefully = .TRUE. ! give only warnings for non-matching uuids
Expand Down Expand Up @@ -167,7 +176,7 @@ cat > NAMELIST_{cfg.casename} << EOF
itype_pres_msl = 5 ! method for computation of mean sea level pressure
itype_rh = 1 ! method for computation of relative humidity
lmask_boundary = .TRUE. ! mask out interpolation zone in output
restart_file_type = 4
restart_file_type = 5
/
! limarea_nml: settings for limited area mode ---------------------------------
Expand Down
6 changes: 6 additions & 0 deletions jobs/icon.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ def main(starttime, hstart, hstop, cfg, model_cfg):
tools.copy_file(cfg.icon_binary_file, os.path.join(cfg.icon_work,
execname))

# Symlink the restart file to the last run into the icon/run folder
if cfg.lrestart == '.TRUE.':
restart_filename = 'restart_atm_DOM01.nc'
restart_file = os.path.join(cfg.icon_restart_in, restart_filename)
tools.symlink_file(restart_file, os.path.join(cfg.icon_work, restart_filename))

# Get name of initial file
if hasattr(cfg, 'inicond_filename'):
inidata_filename = os.path.join(cfg.icon_input_icbc,
Expand Down
2 changes: 1 addition & 1 deletion jobs/prepare_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def set_cfg_variables(cfg, starttime, hstart, hstop):
setattr(cfg, 'icon_restart_out',
os.path.join(cfg.chain_root, 'icon', 'restart'))
setattr(cfg, 'icon_restart_in',
os.path.join(cfg.chain_root_last_run, 'icon', 'restart'))
os.path.join(cfg.chain_root_last_run, 'icon', 'run'))
setattr(cfg, 'icon_input_icbc_last_run',
os.path.join(cfg.chain_root_last_run, 'icon', 'input', 'icbc'))

Expand Down
41 changes: 41 additions & 0 deletions jobs/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,47 @@ def copy_file(source_path, dest_path, output_log=False):
logging.info("Copied {} to {}".format(source_path, dest_path))


def symlink_file(source_path, dest_path, output_log=False):
"""Create a symbolic link from source_path to dest_path
Use os.symlink to create the symbolic link.
dest_path can be either a directory or a filepath.
If it is a directory, the link name will be kept,
if it is a filepath, the link name will be used.
Provides error description to the logfiles
Parameters
----------
source_path : str
Path to the source file or directory
dest_path : str
Path to the destination directory or destination link
output_log : bool, optional
Whether to log messages (default is False)
"""

try:
if os.path.lexists(dest_path):
os.remove(dest_path)
os.symlink(source_path, dest_path)
except FileNotFoundError:
if output_log:
logging.error(f"Source file or directory not found at {source_path}")
raise
except PermissionError:
if output_log:
logging.error(f"Creating symbolic link from {source_path} to {dest_path} failed due to a permission error.")
raise
except (OSError, Exception) as e:
if output_log:
logging.error(f"Creating symbolic link from {source_path} to {dest_path} failed with {type(e).__name__}")
raise

if output_log:
logging.info(f"Created symbolic link from {source_path} to {dest_path}")


def rename_file(source_path, dest_path, output_log=False):
"""Copy a file from source_path to dest_path
Expand Down
1 change: 1 addition & 0 deletions run_chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ def run_chain(work_root, model_cfg, cfg, start_time, hstart, hstop, job_names,
# Restart step
if 'restart' in model_cfg['models'][cfg.model]['features']:
setattr(cfg, 'restart_step', hstop - hstart)
setattr(cfg, 'restart_step_iso', f'PT{int(cfg.restart_step)}H')

# If nested run: use output of mother-simulation
if 'nesting' in model_cfg['models'][
Expand Down

0 comments on commit 46f94e2

Please sign in to comment.