Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[develop] Fix issue 555 (restore default behavior of EXPT_BASEDIR option) #562

Merged
merged 3 commits into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/UsersGuide/source/ConfigWorkflow.rst
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ Directory Parameters
-----------------------

``EXPT_BASEDIR``: (Default: "")
The full path to the base directory in which the experiment directory (``EXPT_SUBDIR``) will be created. If this is not specified or if it is set to an empty string, it will default to ``${HOMEdir}/../expt_dirs``, where ``${HOMEdir}`` contains the full path to the ``ufs-srweather-app`` directory.
The full path to the base directory in which the experiment directory (``EXPT_SUBDIR``) will be created. If this is not specified or if it is set to an empty string, it will default to ``${HOMEdir}/../expt_dirs``, where ``${HOMEdir}`` contains the full path to the ``ufs-srweather-app`` directory. If set to a relative path, the provided path will be appended to the default value ``${HOMEdir}/../expt_dirs``. For example, if ``EXPT_BASEDIR=some/relative/path`` (i.e. a path that does not begin with ``/``), the value of ``EXPT_BASEDIR`` used by the workflow will be ``EXPT_BASEDIR=${HOMEdir}/../expt_dirs/some/relative/path``.

``EXPT_SUBDIR``: (Default: "")
The user-designated name of the experiment directory (*not* its full path). The full path to the experiment directory, which will be contained in the variable ``EXPTDIR``, will be:
Expand Down
5 changes: 3 additions & 2 deletions ush/config_defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,8 @@ workflow:
# EXPT_BASEDIR:
# The base directory in which the experiment directory will be created.
# If this is not specified or if it is set to an empty string, it will
# default to ${HOMEdir}/../expt_dirs.
# default to ${HOMEdir}/../expt_dirs. If set to a relative path, the
# path will be appended to the default value ${HOMEdir}/../expt_dirs
#
# EXPT_SUBDIR:
# The name that the experiment directory (without the full path) will
Expand All @@ -472,7 +473,7 @@ workflow:
# installed.
#-----------------------------------------------------------------------
#
EXPT_BASEDIR: '{{ workflow.EXPT_BASEDIR }}'
EXPT_BASEDIR: '' # This will be set in setup.py prior to extend_yaml() being called
EXPT_SUBDIR: '{{ EXPT_SUBDIR }}'
EXEC_SUBDIR: "exec"
EXPTDIR: '{{ [EXPT_BASEDIR, EXPT_SUBDIR]|path_join }}'
Expand Down
56 changes: 19 additions & 37 deletions ush/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,20 @@ def load_config_for_setup(ushdir, default_config, user_config):
# User settings (take precedence over all others)
update_dict(cfg_u, cfg_d)

# Set "Home" directory, the top-level ufs-srweather-app directory
homedir = os.path.abspath(os.path.dirname(__file__) + os.sep + os.pardir)
cfg_d["user"]["HOMEdir"] = homedir

# Special logic if EXPT_BASEDIR is a relative path; see config_defaults.yaml for explanation
expt_basedir = cfg_d["workflow"]["EXPT_BASEDIR"]
if (not expt_basedir) or (expt_basedir[0] != "/"):
expt_basedir = os.path.join(homedir, "..", "expt_dirs", expt_basedir)
try:
expt_basedir = os.path.realpath(expt_basedir)
except:
pass
cfg_d["workflow"]["EXPT_BASEDIR"] = os.path.abspath(expt_basedir)

extend_yaml(cfg_d)

# Do any conversions of data types
Expand All @@ -152,9 +166,6 @@ def load_config_for_setup(ushdir, default_config, user_config):
if not (v is None or v == ""):
cfg_d[sect][k] = str_to_list(v)

for k, v in cfg_d["task_run_fcst"].items():
print(f"*** {k}: {v}")

# Mandatory variables *must* be set in the user's config or the machine file; the default value is invalid
mandatory = [
"EXPT_SUBDIR",
Expand Down Expand Up @@ -216,7 +227,7 @@ def set_srw_paths(ushdir, expt_config):
"""

# HOMEdir is the location of the SRW clone, one directory above ush/
homedir = os.path.abspath(os.path.dirname(__file__) + os.sep + os.pardir)
homedir = expt_config.get("user", {}).get("HOMEdir")

# Read Externals.cfg
mng_extrns_cfg_fn = os.path.join(homedir, "Externals.cfg")
Expand Down Expand Up @@ -255,7 +266,6 @@ def set_srw_paths(ushdir, expt_config):
)

return dict(
HOMEdir=homedir,
USHdir=ushdir,
UFS_WTHR_MDL_DIR=ufs_wthr_mdl_dir,
)
Expand Down Expand Up @@ -341,38 +351,7 @@ def setup(USHdir, user_config_fn="config.yaml"):
fcst_len_hrs_max = {fcst_len_hrs_max}"""
)

#
# -----------------------------------------------------------------------
#
# If the base directory (EXPT_BASEDIR) in which the experiment subdirectory
# (EXPT_SUBDIR) will be located does not start with a "/", then it is
# either set to a null string or contains a relative directory. In both
# cases, prepend to it the absolute path of the default directory under
# which the experiment directories are placed. If EXPT_BASEDIR was set
# to a null string, it will get reset to this default experiment directory,
# and if it was set to a relative directory, it will get reset to an
# absolute directory that points to the relative directory under the
# default experiment directory. Then create EXPT_BASEDIR if it doesn't
# already exist.
#
# -----------------------------------------------------------------------
#
expt_basedir = workflow_config.get("EXPT_BASEDIR")
homedir = expt_config["user"].get("HOMEdir")
if (not expt_basedir) or (expt_basedir[0] != "/"):
if not expt_basedir or "{{" in expt_basedir:
expt_basedir = ""
expt_basedir = os.path.join(homedir, "..", "expt_dirs", expt_basedir)
try:
expt_basedir = os.path.realpath(expt_basedir)
except:
pass
expt_basedir = os.path.abspath(expt_basedir)

workflow_config["EXPT_BASEDIR"] = expt_basedir

# Update some paths that include EXPT_BASEDIR
extend_yaml(expt_config)
#
# -----------------------------------------------------------------------
#
Expand All @@ -383,7 +362,10 @@ def setup(USHdir, user_config_fn="config.yaml"):
#

expt_subdir = workflow_config.get("EXPT_SUBDIR", "")
exptdir = workflow_config["EXPTDIR"]
exptdir = workflow_config.get("EXPTDIR")

# Update some paths that include EXPTDIR and EXPT_BASEDIR
extend_yaml(expt_config)
preexisting_dir_method = workflow_config.get("PREEXISTING_DIR_METHOD", "")
try:
check_for_preexist_dir_file(exptdir, preexisting_dir_method)
Expand Down