Skip to content

Commit

Permalink
Remove run_case method from tower child types.
Browse files Browse the repository at this point in the history
  • Loading branch information
samsrabin committed Feb 15, 2025
1 parent 10c9270 commit 196bdc0
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 150 deletions.
63 changes: 0 additions & 63 deletions python/ctsm/site_and_regional/neon_site.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,69 +34,6 @@ class NeonSite(TowerSite):
A class for encapsulating neon sites.
"""

# pylint: disable=too-many-statements
def run_case(
self,
base_case_root,
run_type,
prism,
user_version,
user_mods_dirs=None,
overwrite=False,
setup_only=False,
no_batch=False,
rerun=False,
experiment=False,
no_input_data_check=False,
xmlchange=None,
):
"""
Run case.
Args:
self
base_case_root: str, opt
file path of base case
run_type: str, opt
transient, post_ad, or ad case, default transient
prism: bool, opt
if True, use PRISM precipitation, default False
user_version: str, opt
default 'latest'
overwrite: bool, opt
default False
setup_only: bool, opt
default False; if True, set up but do not run case
no_batch: bool, opt
default False
rerun: bool, opt
default False
experiment: str, opt
name of experiment, default False
no_input_data_check: bool, opt
default False
"""
user_mods_dirs = [
os.path.join(
self.cesmroot, "cime_config", "usermods_dirs", "clm", self.tower_type, self.name
)
]

super().run_case(
base_case_root,
run_type,
prism,
user_version,
user_mods_dirs,
overwrite,
setup_only,
no_batch,
rerun,
experiment,
no_input_data_check,
xmlchange,
)

def modify_user_nl(self, case_root, run_type, rundir, site_lines=None):
# TODO: include neon-specific user namelist lines, using this as just an example currently
if site_lines is None:
Expand Down
63 changes: 0 additions & 63 deletions python/ctsm/site_and_regional/plumber_site.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,69 +33,6 @@ class Plumber2Site(TowerSite):
A class for encapsulating plumber sites.
"""

# pylint: disable=too-many-statements
def run_case(
self,
base_case_root,
run_type,
prism,
user_version,
user_mods_dirs=None,
overwrite=False,
setup_only=False,
no_batch=False,
rerun=False,
experiment=False,
no_input_data_check=False,
xmlchange=None,
):
"""
Run case.
Args:
self
base_case_root: str, opt
file path of base case
run_type: str, opt
transient, post_ad, or ad case, default ad
(ad case is default because PLUMBER requires spinup)
prism: bool, opt
if True, use PRISM precipitation, default False
Note: only supported for NEON sites
user_version: str, opt
default 'latest'; this could be useful later
This is currently only implemented with neon (not plumber) sites
overwrite: bool, opt
default False
setup_only: bool, opt
default False; if True, set up but do not run case
no_batch: bool, opt
default False
rerun: bool, opt
default False
experiment: str, opt
name of experiment, default False
"""
user_mods_dirs = [
os.path.join(
self.cesmroot, "cime_config", "usermods_dirs", "clm", self.tower_type, self.name
)
]
super().run_case(
base_case_root,
run_type,
prism,
user_version,
user_mods_dirs,
overwrite,
setup_only,
no_batch,
rerun,
experiment,
no_input_data_check,
xmlchange,
)

def set_ref_case(self, case):
super().set_ref_case(case)
return True ### Check if super returns false, if this will still return True?
8 changes: 4 additions & 4 deletions python/ctsm/site_and_regional/run_tower.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,9 @@ def main(description):
if run_from_postad:
neon_site.finidat = None
if not base_case_root:
user_mods_dirs = None
neon_site.set_default_user_mods_dirs()
base_case_root = neon_site.build_base_case(
cesmroot, output_root, res, compset, user_mods_dirs, overwrite, setup_only
cesmroot, output_root, res, compset, overwrite, setup_only
)
logger.info("-----------------------------------")
logger.info("Running CTSM for neon site : %s", neon_site.name)
Expand Down Expand Up @@ -296,9 +296,9 @@ def main(description):
if run_from_postad:
plumber_site.finidat = None
if not base_case_root:
user_mods_dirs = None
plumber_site.set_default_user_mods_dirs()
base_case_root = plumber_site.build_base_case(
cesmroot, output_root, res, compset, user_mods_dirs, overwrite, setup_only
cesmroot, output_root, res, compset, overwrite, setup_only
)
logger.info("-----------------------------------")
logger.info("Running CTSM for plumber site : %s", plumber_site.name)
Expand Down
62 changes: 42 additions & 20 deletions python/ctsm/site_and_regional/tower_site.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,17 @@ class TowerSite:
-------
"""

def __init__(self, tower_type, name, start_year, end_year, start_month, end_month, finidat):
def __init__(
self,
tower_type,
name,
start_year,
end_year,
start_month,
end_month,
finidat,
user_mods_dirs=None,
):
"""
Initializes TowerSite with the given arguments.
Parameters
Expand All @@ -62,6 +72,14 @@ def __init__(self, tower_type, name, start_year, end_year, start_month, end_mont
self.cesmroot = path_to_ctsm_root()
self.finidat = finidat

if user_mods_dirs is None:
self.set_default_user_mods_dirs()
elif not isinstance(user_mods_dirs, list):
abort("Input user_mods_dirs is NOT a list as expected: " + str(user_mods_dirs))
else:
self.user_mods_dirs = user_mods_dirs
self.check_user_mods_dirs()

def __str__(self):
"""
Converts ingredients of the TowerSite to string for printing.
Expand All @@ -76,10 +94,29 @@ def __str__(self):
),
)

def set_default_user_mods_dirs(self):
"""
Sets user_mods_dirs to the default
"""
self.user_mods_dirs = [
os.path.join(
self.cesmroot, "cime_config", "usermods_dirs", "clm", self.tower_type, self.name
)
]
self.check_user_mods_dirs()

def check_user_mods_dirs(self):
"""
Checks that every user_mod_dir exists
"""
for dirtree in self.user_mods_dirs:
if not os.path.isdir(dirtree):
abort("Input user_mods_dirs dirtreetory does NOT exist: " + str(dirtree))

# TODO: Refactor to shorten this so the disable can be removed
# pylint: disable=too-many-statements
def build_base_case(
self, cesmroot, output_root, res, compset, user_mods_dirs, overwrite=False, setup_only=False
self, cesmroot, output_root, res, compset, overwrite=False, setup_only=False
):
"""
Function for building a base_case to clone.
Expand All @@ -98,20 +135,11 @@ def build_base_case(
base_case resolution or gridname
compset (str):
base case compset
user_mods_dirs (str):
path to the user-mod-directory to use
overwrite (bool) :
Flag to overwrite the case if exists
setup_only (bool) :
Flag to only do the setup phase
"""
# Define fallback user_mods_dirs
if user_mods_dirs is None:
user_mods_dirs = [
os.path.join(
self.cesmroot, "cime_config", "usermods_dirs", "clm", self.tower_type, self.name
)
]
#
# Error checking on the input
#
Expand All @@ -125,11 +153,6 @@ def build_base_case(
abort("Input compset is NOT a boolean as expected: " + str(compset))
if not isinstance(setup_only, bool):
abort("Input setup_only is NOT a boolean as expected: " + str(setup_only))
if user_mods_dirs is not None and not isinstance(user_mods_dirs, list):
abort("Input user_mods_dirs is NOT a list as expected: " + str(user_mods_dirs))
for dirtree in user_mods_dirs:
if not os.path.isdir(dirtree):
abort("Input user_mods_dirs dirtreetory does NOT exist: " + str(dirtree))

print("---- building a base case -------")
# pylint: disable=attribute-defined-outside-init
Expand All @@ -145,7 +168,7 @@ def build_base_case(
print(case_path)

logger.info("base_case_name : %s", self.name)
logger.info("user_mods_dir : %s", user_mods_dirs[0])
logger.info("user_mods_dir : %s", self.user_mods_dirs[0])

if overwrite and os.path.isdir(case_path):
print("Removing the existing case at: {}".format(case_path))
Expand All @@ -165,7 +188,7 @@ def build_base_case(
run_unsupported=True,
answer="r",
output_root=output_root,
user_mods_dirs=user_mods_dirs,
user_mods_dirs=self.user_mods_dirs,
driver="nuopc",
)

Expand Down Expand Up @@ -304,7 +327,6 @@ def run_case(
run_type,
prism,
user_version,
user_mods_dirs,
overwrite,
setup_only,
no_batch,
Expand Down Expand Up @@ -412,7 +434,7 @@ def run_case(
# that the shell_commands file is copied, as well as taking care of the DATM inputs.
# See https://github.com/ESCOMP/CTSM/pull/1872#pullrequestreview-1169407493
#
basecase.create_clone(case_root, keepexe=True, user_mods_dirs=user_mods_dirs)
basecase.create_clone(case_root, keepexe=True, user_mods_dirs=self.user_mods_dirs)

with Case(case_root, read_only=False) as case:
if run_type != "transient":
Expand Down

0 comments on commit 196bdc0

Please sign in to comment.