Skip to content

Commit 37204fb

Browse files
authored
Merge pull request #3292 from samsrabin/subsetdata-systemtest
ctsm5.3.069: Add SystemTests to run subset_data and then CTSM
2 parents de118d5 + c579805 commit 37204fb

File tree

12 files changed

+320
-10
lines changed

12 files changed

+320
-10
lines changed

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ fxDONOTUSEurl = https://github.com/ESMCI/ccs_config_cesm.git
7676
[submodule "cime"]
7777
path = cime
7878
url = https://github.com/ESMCI/cime
79-
fxtag = cime6.1.111
79+
fxtag = cime6.1.112
8080
fxrequired = ToplevelRequired
8181
# Standard Fork to compare to with "git fleximod test" to ensure personal forks aren't committed
8282
fxDONOTUSEurl = https://github.com/ESMCI/cime

cime

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
"""
2+
Parent class for CTSM-specific tests that first run the subset_data tool and then ensure
3+
that CTSM does not fail using the just-generated input files
4+
"""
5+
6+
import os
7+
import sys
8+
import logging
9+
from CIME.SystemTests.system_tests_common import SystemTestsCommon
10+
from CIME.user_mod_support import apply_user_mods
11+
from CIME.XML.standard_module_setup import *
12+
13+
# In case we need to import subset_data later
14+
_CTSM_PYTHON = os.path.join(
15+
os.path.dirname(os.path.realpath(__file__)), os.pardir, os.pardir, "python"
16+
)
17+
sys.path.insert(1, _CTSM_PYTHON)
18+
19+
logger = logging.getLogger(__name__)
20+
21+
22+
class SUBSETDATASHARED(SystemTestsCommon):
23+
def __init__(self, case, subset_data_cmd):
24+
"""
25+
initialize an object interface to the SMS system test
26+
"""
27+
SystemTestsCommon.__init__(self, case)
28+
29+
# Check the test setup
30+
if not self._case.get_value("LND_GRID") == "CLM_USRDAT":
31+
raise RuntimeError("SUBSETDATA tests require resolution CLM_USRDAT")
32+
if "serial" not in self._case.get_value("MPILIB"):
33+
raise RuntimeError("SUBSETDATA tests require a serial MPILIB")
34+
if "BGC-CROP" not in self._case.get_value("COMPSET"):
35+
raise RuntimeError("SUBSETDATA tests require a BGC-CROP compset")
36+
37+
# Add standard subset_data arguments
38+
out_dir = os.path.join(self._get_caseroot(), "subset_data_output")
39+
self.usermods_dir = os.path.join(out_dir, "user_mods")
40+
self.subset_data_cmd = subset_data_cmd + [
41+
"--create-user-mods",
42+
"--outdir",
43+
out_dir,
44+
"--user-mods-dir",
45+
self.usermods_dir,
46+
"--overwrite",
47+
]
48+
49+
# Run subset_data, if needed.
50+
# It's needed during SETUP and/or NLCOMP phases if comparing/generating a baseline because
51+
# the namelist comparison will require generating a namelist, and that will fail if we
52+
# haven't specified our custom fsurdat and other stuff. By calling self._run_subset_data()
53+
# only if the usermods directory doesn't yet exist, we avoid it being called every time the
54+
# test class is initialized (which happens, e.g., in RUN phase).
55+
# if not os.path.exists(self.usermods_dir):
56+
# self._run_subset_data()
57+
58+
def build_phase(self, sharedlib_only=False, model_only=False):
59+
"""
60+
Run subset_data and then build the model
61+
"""
62+
63+
# Run subset_data.
64+
# build_phase gets called twice:
65+
# - once with sharedlib_only = True and
66+
# - once with model_only = True
67+
# Because we only need subset_data run once, we only do it for the sharedlib_only call.
68+
# We could also check for the existence of the subset_data outputs, but that might lead to
69+
# a situation where the user expects subset_data to be called but it's not. Better to run
70+
# unnecessarily (e.g., if you fixed some FORTRAN code and just need to rebuild).
71+
# In that same vein, yes we did run subset_data during the first time this test case was
72+
# initialized (see __init__() above), but we're doing it again here just to be safe.
73+
if sharedlib_only:
74+
self._run_subset_data()
75+
76+
# Do the build
77+
self.build_indv(sharedlib_only=sharedlib_only, model_only=model_only)
78+
79+
def _run_subset_data(self):
80+
"""
81+
Run subset_data
82+
"""
83+
# Import subset_data. Do it here rather than at top because otherwise the import will
84+
# be attempted even during RUN phase.
85+
# pylint: disable=wrong-import-position,import-outside-toplevel
86+
from ctsm.subset_data import main as subset_data
87+
88+
# Run subset_data
89+
sys.argv = self.subset_data_cmd
90+
subset_data()
91+
92+
# Required so that CTSM doesn't fail
93+
user_nl_clm_path = os.path.join(self.usermods_dir, "user_nl_clm")
94+
with open(user_nl_clm_path, "a", encoding="utf-8") as user_nl_clm:
95+
user_nl_clm.write("\ncheck_dynpft_consistency = .false.\n")
96+
97+
# Apply the user mods
98+
self._case.flush(flushall=True)
99+
apply_user_mods(self._get_caseroot(), self.usermods_dir)
100+
self._case.read_xml()
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"""
2+
CTSM-specific test that first runs the subset_data point tool and then ensures
3+
that CTSM does not fail using the just-generated input files
4+
"""
5+
6+
from subsetdata import SUBSETDATASHARED
7+
8+
9+
class SUBSETDATAPOINT(SUBSETDATASHARED):
10+
def __init__(self, case):
11+
"""
12+
initialize an object interface to the SMS system test
13+
"""
14+
15+
lat = 45.402252
16+
lon = -92.798085
17+
18+
# Don't need to include things that are added during SUBSETDATASHARED.__init__()
19+
subset_data_cmd = [
20+
"tools/site_and_regional/subset_data",
21+
"point",
22+
"--lat",
23+
str(lat),
24+
"--lon",
25+
str(lon),
26+
"--create-surface",
27+
"--crop",
28+
"--create-landuse",
29+
"--surf-year",
30+
"1850",
31+
"--create-datm",
32+
"--datm-syr",
33+
"1901",
34+
"--datm-eyr",
35+
"1901",
36+
]
37+
38+
super().__init__(case, subset_data_cmd)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
"""
2+
CTSM-specific test that first runs the subset_data region tool and then ensures
3+
that CTSM does not fail using the just-generated input files
4+
"""
5+
6+
from subsetdata import SUBSETDATASHARED
7+
8+
9+
class SUBSETDATAREGION(SUBSETDATASHARED):
10+
def __init__(self, case):
11+
"""
12+
initialize an object interface to the SMS system test
13+
"""
14+
15+
lat1 = -9
16+
lat2 = -7
17+
lon1 = 291
18+
lon2 = 293
19+
20+
# Don't need to include things that are added during SUBSETDATASHARED.__init__()
21+
subset_data_cmd = [
22+
"tools/site_and_regional/subset_data",
23+
"region",
24+
"--lat1",
25+
str(lat1),
26+
"--lat2",
27+
str(lat2),
28+
"--lon1",
29+
str(lon1),
30+
"--lon2",
31+
str(lon2),
32+
"--create-mesh",
33+
"--create-domain",
34+
"--create-surface",
35+
"--crop",
36+
"--create-landuse",
37+
"--surf-year",
38+
"1850",
39+
]
40+
41+
super().__init__(case, subset_data_cmd)

cime_config/config_tests.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,26 @@ This defines various CTSM-specific system tests
3535
<HIST_N>$STOP_N</HIST_N>
3636
</test>
3737

38+
<test NAME="SUBSETDATAPOINT">
39+
<DESC>Run CTSM with files generated by the subset_data point tool</DESC>
40+
<INFO_DBUG>1</INFO_DBUG>
41+
<DOUT_S>FALSE</DOUT_S>
42+
<CONTINUE_RUN>FALSE</CONTINUE_RUN>
43+
<REST_OPTION>never</REST_OPTION>
44+
<HIST_OPTION>$STOP_OPTION</HIST_OPTION>
45+
<HIST_N>$STOP_N</HIST_N>
46+
</test>
47+
48+
<test NAME="SUBSETDATAREGION">
49+
<DESC>Run CTSM with files generated by the subset_data region tool</DESC>
50+
<INFO_DBUG>1</INFO_DBUG>
51+
<DOUT_S>FALSE</DOUT_S>
52+
<CONTINUE_RUN>FALSE</CONTINUE_RUN>
53+
<REST_OPTION>never</REST_OPTION>
54+
<HIST_OPTION>$STOP_OPTION</HIST_OPTION>
55+
<HIST_N>$STOP_N</HIST_N>
56+
</test>
57+
3858
<test NAME="LGRAIN2">
3959
<DESC>CTSM Land model test to ensure that we can allocate and use a second grain pool</DESC>
4060
<INFO_DBUG>1</INFO_DBUG>

cime_config/testdefs/testlist_clm.xml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
rxcropmaturity: Short tests to be run during development related to prescribed crop calendars
1414
matrixcn: Tests exercising the matrix-CN capability
1515
aux_clm_mpi_serial: aux_clm tests using mpi-serial. Useful for redoing tests that failed due to https://github.com/ESCOMP/CTSM/issues/2916, after having replaced libraries/mpi-serial with a fresh copy.
16+
subset_data: Tests exercising the subset_data tool and running CTSM with its output
1617
decomp_init: Initialization tests specifically for examining the PE layout decomposition initialization
1718
interim_restart: Tests having to do with interim restart capability.
1819
-->
@@ -4141,6 +4142,34 @@
41414142
</options>
41424143
</test>
41434144

4145+
<test name="SUBSETDATAPOINT_Ld5_D_Mmpi-serial" grid="CLM_USRDAT" compset="I2000Clm60BgcCropCrujra" testmods="clm-default">
4146+
<machines>
4147+
<machine name="derecho" compiler="intel" category="aux_clm"/>
4148+
<machine name="derecho" compiler="intel" category="aux_clm_mpi_serial"/>
4149+
<machine name="derecho" compiler="intel" category="clm_pymods"/>
4150+
<machine name="derecho" compiler="intel" category="subset_data"/>
4151+
</machines>
4152+
<options>
4153+
<option name="wallclock">00:20:00</option>
4154+
<option name="comment">Smoke test that first runs the subset_data point tool and then ensures that CTSM does not fail using the just-generated user mods.</option>
4155+
<option name="comment">This test invokes python code, so it should be run whenever changing python code (in addition to being run as part of aux_clm).</option>
4156+
</options>
4157+
</test>
4158+
4159+
<test name="SUBSETDATAREGION_Ld5_D_Mmpi-serial" grid="CLM_USRDAT" compset="I2000Clm60BgcCropCrujra" testmods="clm-default">
4160+
<machines>
4161+
<machine name="derecho" compiler="intel" category="aux_clm"/>
4162+
<machine name="derecho" compiler="intel" category="aux_clm_mpi_serial"/>
4163+
<machine name="derecho" compiler="intel" category="clm_pymods"/>
4164+
<machine name="derecho" compiler="intel" category="subset_data"/>
4165+
</machines>
4166+
<options>
4167+
<option name="wallclock">00:20:00</option>
4168+
<option name="comment">Smoke test that first runs the subset_data regiontool and then ensures that CTSM does not fail using the just-generated user mods.</option>
4169+
<option name="comment">This test invokes python code, so it should be run whenever changing python code (in addition to being run as part of aux_clm).</option>
4170+
</options>
4171+
</test>
4172+
41444173
<test name="LILACSMOKE_D_Ld2" grid="f10_f10_mg37" compset="I2000Ctsm50NwpSpAsRs" testmods="clm-lilac">
41454174
<machines>
41464175
<machine name="derecho" compiler="intel" category="aux_clm"/>

doc/ChangeLog

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,77 @@
11
===============================================================
2+
Tag name: ctsm5.3.069
3+
Originator(s): samrabin (Sam Rabin, UCAR/TSS)
4+
Date: Tue Aug 12 09:52:59 MDT 2025
5+
One-line Summary: Add SystemTests to run subset_data and then CTSM
6+
7+
Purpose and description of changes
8+
----------------------------------
9+
10+
Adds SUBSETDATAPOINT and SUBSETDATAREGION tests to aux_clm (and new subset_data suite). These run subset_data for either a point or a six-cell region, then run CTSM with the outputs.
11+
12+
13+
Significant changes to scientifically-supported configurations
14+
--------------------------------------------------------------
15+
16+
Does this tag change answers significantly for any of the following physics configurations?
17+
(Details of any changes will be given in the "Answer changes" section below.)
18+
19+
[ ] clm6_0
20+
21+
[ ] clm5_0
22+
23+
[ ] ctsm5_0-nwp
24+
25+
[ ] clm4_5
26+
27+
28+
Bugs fixed
29+
----------
30+
31+
List of CTSM issues fixed (include CTSM Issue # and description):
32+
- Resolves [Issue #1491: Add two new tests that run subset_data and then run a case from it](https://github.com/ESCOMP/CTSM/issues/1491)
33+
34+
35+
Notes of particular relevance for developers:
36+
---------------------------------------------
37+
NOTE: Be sure to review the steps in README.CHECKLIST.master_tags as well as the coding style in the Developers Guide
38+
[Remove any lines that don't apply. Remove entire section if nothing applies.]
39+
40+
Caveats for developers (e.g., code that is duplicated that requires double maintenance):
41+
42+
Changes to tests or testing:
43+
- Adds test SUBSETDATAPOINT_Ld5_D_Mmpi-serial.CLM_USRDAT.I2000Clm60BgcCropCrujra.derecho_intel.clm-default
44+
- Adds test SUBSETDATAREGION_Ld5_D_Mmpi-serial.CLM_USRDAT.I2000Clm60BgcCropCrujra.derecho_intel.clm-default
45+
- Adds new subset_data suite with those tests in it
46+
- Those tests are also in aux_clm
47+
48+
Testing summary:
49+
----------------
50+
51+
[PASS means all tests PASS; OK means tests PASS other than expected fails.]
52+
53+
build-namelist tests (if CLMBuildNamelist.pm has changed):
54+
55+
derecho -
56+
57+
python testing (if python code has changed; see instructions in python/README.md; document testing done):
58+
59+
derecho - Unit, black, and pylint checks pass. Two system tests fail due to recent conda and mamba updates on Derecho; these have been fixed on b4b-dev with [Pull Request #3403: Fix py_env_create and tests by samsrabin](https://github.com/ESCOMP/CTSM/pull/3403)
60+
61+
regular tests (aux_clm: https://github.com/ESCOMP/CTSM/wiki/System-Testing-Guide#pre-merge-system-testing):
62+
63+
derecho ----- OK
64+
izumi ------- OK
65+
66+
67+
Other details
68+
-------------
69+
70+
Pull Requests that document the changes (include PR ids):
71+
- [Pull Request #3292: ctsm5.3.069: Add SystemTests to run subset_data and then CTSM by samsrabin](https://github.com/ESCOMP/CTSM/pull/3292)
72+
73+
===============================================================
74+
===============================================================
275
Tag name: ctsm5.3.068
376
Originator(s): slevis (Samuel Levis,UCAR/TSS,303-665-1310)
477
Date: Mon 11 Aug 2025 02:27:39 PM MDT

doc/ChangeSum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Tag Who Date Summary
22
============================================================================================================================
3+
ctsm5.3.069 samrabin 08/12/2025 Add SystemTests to run subset_data and then CTSM
34
ctsm5.3.068 slevis 08/11/2025 Change megan_use_gamma_sm to default false
45
ctsm5.3.067 samrabin 08/08/2025 (Mostly) fix interim restarts
56
ctsm5.3.066 slevis 08/08/2025 Merge b4b-dev to master

python/ctsm/run_sys_tests.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,14 @@ def _check_py_env(test_attributes):
749749
except ModuleNotFoundError as err:
750750
raise ModuleNotFoundError("modify_fsurdat" + err_msg) from err
751751

752+
# Check requirements for using subset_data Python module, if needed
753+
subset_data_users = ["SUBSETDATAPOINT", "SUBSETDATAREGION"]
754+
if any(any(u in t for u in subset_data_users) for t in test_attributes):
755+
try:
756+
import ctsm.subset_data
757+
except ModuleNotFoundError as err:
758+
raise ModuleNotFoundError("subset_data" + err_msg) from err
759+
752760
# Check requirements for RXCROPMATURITY, if needed
753761
if any("RXCROPMATURITY" in t for t in test_attributes):
754762
try:

0 commit comments

Comments
 (0)