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

Add mksurfdata_esmf system test to test-suite #1756

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
007ea0c
Merge remote-tracking branch 'escomp/ctsm5.2.mksurfdata' into mksurfd…
slevis-lmwg May 12, 2022
198beb4
Enable mksurfdata_esmf build and run on casper
slevis-lmwg May 12, 2022
0a25ee0
Add . ./.env_mach_specific.sh to gen_mksurfdata_jobscript_*.py
slevis-lmwg May 17, 2022
dd72733
First successful version of new test-suite system test
slevis-lmwg May 17, 2022
b8fc136
Changes needed for gen_mksurfdata_build.sh to work with new system test
slevis-lmwg May 18, 2022
32264cd
Fleshing out the steps to complete this system test (not done)
slevis-lmwg May 18, 2022
575f770
Small revisions in response to ErikK's code review
slevis-lmwg May 18, 2022
d1de496
More updates in response to code review
slevis-lmwg May 18, 2022
a0540a4
Further fleshing out of the steps involved in this test
slevis-lmwg May 18, 2022
5f02dfe
Remove some hardwiring
slevis-lmwg May 18, 2022
9621dd6
Update some comments
slevis-lmwg May 18, 2022
cd0daa1
Adding flexibility of running this test from casper, though read caveat:
slevis-lmwg May 18, 2022
f1253dc
Added comment to the script's docstring
slevis-lmwg May 18, 2022
08a77d7
Added the new test to testlist_clm.xml
slevis-lmwg May 18, 2022
128bef9
Remove "_" and "self._" from local variables
slevis-lmwg May 19, 2022
182458c
Remove /tools/mksurfdata_esmf/bld directory when done using it
slevis-lmwg May 19, 2022
0134b4e
Improved error messages from subprocess.check_call commands
slevis-lmwg May 19, 2022
a5a1d66
Keep mksurfdata /bld after it's no longer needed (reverts https://git…
slevis-lmwg May 20, 2022
87e9e99
Reduced if "done_file" to cover modify_user_nl; added new if to the rest
slevis-lmwg May 20, 2022
c624a73
Rm preexisting .namelist & .nc files before creating them
slevis-lmwg May 20, 2022
dca62af
Changes to gen_mksurfdata_build.sh (in progress)
slevis-lmwg May 23, 2022
4e8caf8
Now we may place the /bld of mksurfdata_esmf anywhere
slevis-lmwg May 24, 2022
8c8ac64
Enable gen_mksurfdata_namelist.py to also work on casper
slevis-lmwg May 24, 2022
8b72098
pylint recommendations and other clean-up
slevis-lmwg May 24, 2022
1fca36c
Error msg for when "machine" is not valid
slevis-lmwg May 26, 2022
3fb88c6
Change default bld dir from /bld to /tool_bld for sys test to work
slevis-lmwg Jun 8, 2022
c46720f
Update sys test to generate & submit the jobscript that runs mksurfdata
slevis-lmwg Jun 8, 2022
57b936a
Corretion of a path in gen_mksurfdata_jobscript_single.py
slevis-lmwg Jun 9, 2022
8efad79
Small corrections to README
slevis-lmwg Jun 22, 2022
7806635
Clarify help-string pertaining to --model-mesh-nx & --model-mesh-ny
slevis-lmwg Jun 22, 2022
de3fb92
Updates based on pylint recommendations
slevis-lmwg Jul 1, 2022
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
131 changes: 131 additions & 0 deletions cime_config/SystemTests/mksurfdataesmf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
"""
This test passes if mksurfdata_esmf generates an fsurdat (surface dataset)
and the CTSM completes a simulation with this fsurdat file.

We test res = '10x15' because it uses a lower-res topography file instead of
the 1-km topography raw dataset. The 1-km file causes the test to run out of
memory on cheyenne.

Currently casper complains that `git -C` is not a valid option.
I added -C to the `git describe` in gen_mksurfdata_namelist.py for this
system test to work.
"""
import os
import sys
import subprocess
from datetime import datetime
from CIME.SystemTests.system_tests_common import SystemTestsCommon
from CIME.XML.standard_module_setup import *
from CIME.SystemTests.test_utils.user_nl_utils import append_to_user_nl_files

logger = logging.getLogger(__name__)

class MKSURFDATAESMF(SystemTestsCommon):

def __init__(self, case):
"""
initialize an object interface to the SMS system test
"""
SystemTestsCommon.__init__(self, case)

# Paths and strings needed throughout
ctsm_root = self._case.get_value('COMP_ROOT_DIR_LND')
self._tool_path = os.path.join(ctsm_root, 'tools/mksurfdata_esmf')
self._tool_bld = os.path.join(self._get_caseroot(), 'tool_bld')
time_stamp = datetime.today().strftime("%y%m%d")
self._res = '10x15' # see important comment in script's docstring
self._model_yr = '1850'
self._jobscript = os.path.join(self._get_caseroot(),
'mksurfdata_jobscript_single')
self._fsurdat_namelist = os.path.join(self._get_caseroot(),
f'surfdata_{self._res}_hist_78pfts_CMIP6_{self._model_yr}_c{time_stamp}.namelist')
self._fsurdat_nc = os.path.join(self._get_caseroot(),
f'surfdata_{self._res}_hist_78pfts_CMIP6_{self._model_yr}_c{time_stamp}.nc')
self._TestStatus_log_path = os.path.join(self._get_caseroot(),
'TestStatus.log')

def build_phase(self, sharedlib_only=False, model_only=False):
"""
Build executable that will generate fsurdat
Generate namelist for generating fsurdat
Generate jobscript that runs executable
Modify user_nl_clm to point to the generated fsurdat
"""
# build_phase gets called twice:
# - once with sharedlib_only = True and
# - once with model_only = True
# Call the following steps only once during the test but do not skip
# if the test stops and gets restarted.
if sharedlib_only:
# Paths and strings
build_script_path = os.path.join(self._tool_path,
'gen_mksurfdata_build.sh')
nml_script_path = os.path.join(self._tool_path,
'gen_mksurfdata_namelist.py')
gen_jobscript_path = os.path.join(self._tool_path,
'gen_mksurfdata_jobscript_single.py')
gen_mksurfdata_namelist = f'{nml_script_path} --res {self._res} --start-year {self._model_yr} --end-year {self._model_yr}'
gen_mksurfdata_jobscript = f'{gen_jobscript_path} --number-of-nodes 12 --tasks-per-node 12 --namelist-file {self._fsurdat_namelist}'

# Rm tool_bld and build executable that will generate fsurdat
try:
subprocess.check_call(f'rm -rf {self._tool_bld}', shell=True)
except subprocess.CalledProcessError as e:
sys.exit(f'{e} ERROR REMOVING {self._tool_bld}. DETAILS IN {self._TestStatus_log_path}')
try:
subprocess.check_call(f'{build_script_path} --blddir {self._tool_bld}', shell=True)
except subprocess.CalledProcessError as e:
sys.exit(f'{e} ERROR RUNNING {build_script_path}. DETAILS IN {self._TestStatus_log_path}')

# Generate namelist for generating fsurdat (rm namelist if exists)
if os.path.exists(self._fsurdat_namelist):
os.remove(self._fsurdat_namelist)
try:
subprocess.check_call(gen_mksurfdata_namelist, shell=True)
except subprocess.CalledProcessError as e:
sys.exit(f'{e} ERROR RUNNING {gen_mksurfdata_namelist}. DETAILS IN {self._TestStatus_log_path}')

# Generate jobscript that will run the executable
if os.path.exists(self._jobscript):
os.remove(self._jobscript)
try:
subprocess.check_call(gen_mksurfdata_jobscript, shell=True)
except subprocess.CalledProcessError as e:
sys.exit(f'{e} ERROR RUNNING {gen_mksurfdata_jobscript}. DETAILS IN {self._TestStatus_log_path}')
# Change self._jobscript to an executable file
subprocess.check_call(f'chmod a+x {self._jobscript}', shell=True)

# Call this step only once even if the test stops and gets restarted.
if not os.path.exists(os.path.join(self._get_caseroot(),
'done_MKSURFDATAESMF_setup.txt')):
# Modify user_nl_clm to point to the generated fsurdat
self._modify_user_nl()
with open('done_MKSURFDATAESMF_setup.txt', 'w') as fp:
pass

self.build_indv(sharedlib_only=sharedlib_only, model_only=model_only)

def run_phase(self):
"""
Run executable to generate fsurdat
Submit CTSM run that uses fsurdat just generated
"""

# Run executable to generate fsurdat (rm fsurdat if exists)
if os.path.exists(self._fsurdat_nc):
os.remove(self._fsurdat_nc)
try:
subprocess.check_call(self._jobscript, shell=True)
except subprocess.CalledProcessError as e:
sys.exit(f'{e} ERROR RUNNING {self._jobscript}; details in {self._TestStatus_log_path}')

# Submit CTSM run that uses fsurdat just generated
self.run_indv()

def _modify_user_nl(self):
"""
Modify user_nl_clm to point to the generated fsurdat
"""
append_to_user_nl_files(caseroot = self._get_caseroot(),
component = "clm",
contents = "fsurdat = '{}'".format(self._fsurdat_nc))
10 changes: 10 additions & 0 deletions cime_config/config_tests.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ This defines various CTSM-specific system tests
<DOUT_S>FALSE</DOUT_S>
</test>

<test NAME="MKSURFDATAESMF">
<DESC>Build and run the mksurfdata_esmf tool to generate a new fsurdat; then run the CTSM with this fsurdat</DESC>
<INFO_DBUG>1</INFO_DBUG>
<DOUT_S>FALSE</DOUT_S>
<CONTINUE_RUN>FALSE</CONTINUE_RUN>
<REST_OPTION>never</REST_OPTION>
<HIST_OPTION>$STOP_OPTION</HIST_OPTION>
<HIST_N>$STOP_N</HIST_N>
</test>

<test NAME="FSURDATMODIFYCTSM">
<DESC>Run the CTSM with an fsurdat generated by the fsurdat_modify tool</DESC>
<INFO_DBUG>1</INFO_DBUG>
Expand Down
17 changes: 17 additions & 0 deletions cime_config/testdefs/testlist_clm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2369,6 +2369,23 @@
</machines>
</test>

<test name="MKSURFDATAESMF_P144x1" grid="f10_f10_mg37" compset="I1850Clm50BgcCrop">
<machines>
<machine name="cheyenne" compiler="intel" category="aux_clm">
<options>
<option name="wallclock">00:40:00</option>
<option name="comment">Smoke test that first runs the mksurfdata_esmf tool and then ensures that the CTSM does not fail using the just-generated fsurdat file. Global BGC CROP case.</option>
</options>
</machine>
<machine name="cheyenne" compiler="intel" category="clm_pymods">
<options>
<option name="wallclock">00:40:00</option>
<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>
</options>
</machine>
</machines>
</test>

<test name="FSURDATMODIFYCTSM_D_Mmpi-serial_Ld1" grid="5x5_amazon" compset="I2000Clm50SpRs">
<machines>
<machine name="cheyenne" compiler="intel" category="aux_clm">
Expand Down
6 changes: 2 additions & 4 deletions tools/mksurfdata_esmf/README
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ on your machine you will be able to build the tool there.

To get a list of the machines that have been ported to cime:

cd ../../cime/scripts
cd ../../cime/scripts # assumes we are in tools/mksurfdata_esmf
./query_config --machines

NOTE:
Expand All @@ -41,16 +41,14 @@ to be referenced with the env variable PIO which will need to be in the porting
for the machine. Currently an independent PIO library is not available on cime ported machines.

=======================
building the executable
building the executable (working in tools/mksurfdata_esmf)
=======================

> cd tools/mksurfdata_esmf
> ./gen_mksurfdata_build.sh # For machines with a cime build

=======================
running for a single submission:
=======================
> cd ../
# to generate your target namelist:
> ./gen_mksurfdata_namelist.py --help
# for example try --res 1.9x2.5 --start-year 1850 --end-year 1850:
Expand Down
81 changes: 69 additions & 12 deletions tools/mksurfdata_esmf/gen_mksurfdata_build.sh
Original file line number Diff line number Diff line change
@@ -1,46 +1,103 @@
#! /bin/bash -f

hostname=`hostname --short`
#----------------------------------------------------------------------
# Usage subroutine
usage() {
echo ""
echo "***********************************************************************"
echo "usage:"
echo "./gen_mksurfdata_build.sh"
echo ""
echo "valid arguments: "
echo "[-h|--help] "
echo " Displays this help message"
echo "[-v|--verbose] "
echo " Run in verbose mode"
echo "[-b|--blddir <blddir>] "
echo " Overwrites default, which is /bld in the same directory as ./gen_mksurfdata_build.sh"
echo "[-m|--machine <machine>] "
echo " Overwrites default MACH"
echo "***********************************************************************"
}


# Current working directory: the location of ./gen_mksurfdata_build.sh
cwd=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

# Default settings
verbose="No"
blddir=$cwd/tool_bld # may overwrite this default with command-line option (below)

# Define what machine to use that's been ported to cime
# May overwrite this default with command-line option --machine
hostname=`hostname --short`
case $hostname in
##cheyenne
cheyenne* | r* )
export MACH="cheyenne"
;;
##casper
casper* )
export MACH="casper"
;;
## Other machines
*)
export MACH="$hostname"
;;
esac

# Create /bld directory
# Parse command-line options
while [ $# -gt 0 ]; do
case $1 in
-h|--help )
usage
exit 0
;;
-v|--verbose )
verbose="Yes"
;;
-b|--blddir )
blddir=$2
shift
;;
-m|--machine )
MACH=$2
shift
;;
* )
echo "ERROR:: invalid argument sent in: $2"
usage
exit 1
;;
esac
shift
done

# Create /tool_bld directory
echo "cime Machine is: $MACH..."
if [ -d "bld" ]; then
echo "A /bld directory exists; remove it to do a clean build..."
if [ -d "$blddir" ]; then
echo "A /tool_bld directory exists; remove it to do a clean build..."
exit 1
fi
cwd=`pwd`
rm -rf bld
mkdir bld
cd bld
mkdir $blddir
cd $blddir

# Run the cime configure tool to figure out what modules need to be loaded
echo "Run cime configure for machine $MACH..."
# You can specify the non-default compiler and mpi-library by adding --compiler and --mpilib settings
if [ -z "$COMPILER" ] || [ -z "$MPILIB" ]; then
echo "configure for the default MPI-library and compiler..."
../../../cime/tools/configure --macros-format CMake --machine $MACH
$cwd/../../cime/tools/configure --macros-format CMake --machine $MACH
else
echo "configure for the specific MPILIB=$MPILIB and COMPILER=$COMPILER..."
../../../cime/tools/configure --macros-format CMake --machine $MACH --compiler $COMPILER --mpilib $MPILIB
$cwd/../../cime/tools/configure --macros-format CMake --machine $MACH --compiler $COMPILER --mpilib $MPILIB
fi

if [ $? != 0 ]; then
echo "Error doing configure for machine name: $MACH"
exit 1
fi
. .env_mach_specific.sh
. ./.env_mach_specific.sh
ekluzek marked this conversation as resolved.
Show resolved Hide resolved
echo "COMPILER = $COMPILER, MPILIB = $MPILIB, DEBUG = $DEBUG, OS = $OS"
if [ -z "$PIO" ]; then
echo "The PIO directory for the PIO build is required and was not set in the configure"
Expand All @@ -50,7 +107,7 @@ fi

# Build the cmake files
echo "Do the cmake build..."
CC=mpicc FC=mpif90 cmake -DCMAKE_BUILD_TYPE=debug ../src
CC=mpicc FC=mpif90 cmake -DCMAKE_BUILD_TYPE=debug $cwd/src
if [ $? != 0 ]; then
echo "Error doing cmake for $MACH $MPILIB $COMPILER"
exit 1
Expand Down
Loading