Skip to content

Commit

Permalink
move case update to preview_namelist
Browse files Browse the repository at this point in the history
  • Loading branch information
jedwards4b committed Jul 12, 2016
1 parent d1ed95a commit dea5064
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 117 deletions.
156 changes: 53 additions & 103 deletions utils/python/CIME/SystemTests/erp.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def build(self, sharedlib_only=False, model_only=False):
self._case.set_value("NTASKS_%s"%comp, ntasks/2)
self._case.set_value("ROOTPE_%s"%comp, rootpe/2)

self._case.flush()
# self._case.flush()

# Note, some components, like CESM-CICE, have
# decomposition information in env_build.xml
Expand All @@ -84,8 +84,8 @@ def build(self, sharedlib_only=False, model_only=False):
case_setup(self._case, test_mode=True, reset=True)

# update the case to the new values
self._case = None
self._case = Case(self._caseroot)
# self._case = None
# self._case = Case(self._caseroot)

# Now rebuild the system, given updated information in env_build.xml

Expand All @@ -100,108 +100,58 @@ def build(self, sharedlib_only=False, model_only=False):
#
#

def _erp_first_phase(self):

# Reset beginning test settings
expect(os.path.isfile(os.path.join("LockedFiles","env_mach_pes.ERP1.xml")),
"ERROR: LockedFiles/env_mach_pes.ERP1.xml does not exist, run case.build" )

# Use the first env_mach_pes.xml and env_build.xml files
shutil.copy(os.path.join("LockedFiles","env_mach_pes.ERP1.xml"), "env_mach_pes.xml")
shutil.copy("env_mach_pes.xml", os.path.join("LockedFiles","env_mach_pes.xml"))
shutil.copy(os.path.join("LockedFiles","env_build.ERP1.xml"), "env_build.xml")
shutil.copy("env_build.xml", os.path.join("LockedFiles","env_build.xml"))

# update the case to the new values
self._case = None
self._case = Case(self._caseroot)

# Use the first executable that was created
exeroot = self._case.get_value("EXEROOT")
cime_model = CIME.utils.get_model()
exefile = "%s/%s.exe"%(exeroot,cime_model)
exefile1 = "%s/%s.ERP1.exe"%(exeroot,cime_model)
if (os.path.isfile(exefile)):
os.remove(exefile)
shutil.copy(exefile1, exefile)

case_setup(self._case, test_mode=True, reset=True)

stop_n = self._case.get_value("STOP_N")
stop_option = self._case.get_value("STOP_OPTION")
expect(stop_n > 0, "Bad STOP_N: %d" % stop_n)

rest_n = stop_n/2 + 1
self._case.set_value("REST_N", rest_n)
self._case.set_value("REST_OPTION", stop_option)
self._case.set_value("HIST_N", stop_n)
self._case.set_value("HIST_OPTION", stop_option)
self._case.set_value("CONTINUE_RUN", False)
self._case.flush()

expect(stop_n > 2, "ERROR: stop_n value %d too short"%stop_n)

# Run the test
logger.info("doing an %s %s initial test with restart file at %s %s"
%(str(stop_n), stop_option, str(rest_n), stop_option))
return SystemTestsCommon.run(self)

def _erp_second_phase(self):

expect(os.path.isfile(os.path.join("LockedFiles","env_mach_pes.ERP2.xml")),
"ERROR: LockedFiles/env_mach_pes.ERP2.xml does not exist, run case.build" )

# Use the second env_mach_pes.xml and env_build.xml files
shutil.copy(os.path.join("LockedFiles","env_mach_pes.ERP2.xml"), "env_mach_pes.xml")
shutil.copy("env_mach_pes.xml", os.path.join("LockedFiles","env_mach_pes.xml"))
shutil.copy(os.path.join("LockedFiles","env_build.ERP2.xml"), "env_build.xml")
shutil.copy("env_build.xml", os.path.join("LockedFiles","env_build.xml"))

# update the case to use the new values
self._case = None
self._case = Case(self._caseroot)

# Use the second executable that was created
exeroot = self._case.get_value("EXEROOT")
cime_model = CIME.utils.get_model()
exefile = "%s/%s.exe"%(exeroot,cime_model)
exefile2 = "%s/%s.ERP2.exe"%(exeroot,cime_model)
if (os.path.isfile(exefile)):
os.remove(exefile)
shutil.copy(exefile2, exefile)

case_setup(self._case, test_mode=True, reset=True)

# Determine stop time and retart time
stop_n = self._case.get_value("STOP_N")
stop_option = self._case.get_value("STOP_OPTION")

rest_n = stop_n/2 + 1
stop_new = stop_n - rest_n
expect(stop_new > 0, "ERROR: stop_n value %d too short %d %d"%(stop_new,stop_n,rest_n))

self._case.set_value("STOP_N", stop_new)
self._case.set_value("CONTINUE_RUN", True)
self._case.set_value("REST_OPTION","never")
self._case.flush()

# Run the test
logger.info("doing an %s %s restart test" %(str(stop_new), stop_option))
success = SystemTestsCommon._run(self, "rest")

# Compare restart file
if success:
return self._component_compare_test("base", "rest")
else:
return False

def run(self):
success = self._erp_first_phase()
# run will have values 1,2
for run in range(1,3):

expect(os.path.isfile(os.path.join("LockedFiles","env_mach_pes.ERP%d.xml"%run)),
"ERROR: LockedFiles/env_mach_pes.ERP%d.xml does not exist, run case.build"%run )

# Use the second env_mach_pes.xml and env_build.xml files
shutil.copy(os.path.join("LockedFiles","env_mach_pes.ERP%d.xml"%run), "env_mach_pes.xml")
shutil.copy("env_mach_pes.xml", os.path.join("LockedFiles","env_mach_pes.xml"))
shutil.copy(os.path.join("LockedFiles","env_build.ERP%d.xml")%run, "env_build.xml")
shutil.copy("env_build.xml", os.path.join("LockedFiles","env_build.xml"))

# update the case to use the new values
self._case.read_xml(self._caseroot)

# Use the second executable that was created
exeroot = self._case.get_value("EXEROOT")
cime_model = CIME.utils.get_model()
exefile = os.path.join(exeroot,"%s.exe"%(cime_model))
exefile2 = os.path.join(exeroot,"%s.ERP%d.exe"%(cime_model,run))
if (os.path.isfile(exefile)):
os.remove(exefile)
shutil.copy(exefile2, exefile)

case_setup(self._case, test_mode=True, reset=True)
stop_n = self._case.get_value("STOP_N")
stop_option = self._case.get_value("STOP_OPTION")

if run == 1:
expect(stop_n > 2, "ERROR: stop_n value %d too short"%stop_n)
rest_n = stop_n/2 + 1
self._case.set_value("REST_N", rest_n)
self._case.set_value("REST_OPTION", stop_option)
self._case.set_value("HIST_N", stop_n)
self._case.set_value("HIST_OPTION", stop_option)
self._case.set_value("CONTINUE_RUN", False)
suffix = "base"
else:
rest_n = stop_n/2 + 1
stop_new = stop_n - rest_n
expect(stop_new > 0, "ERROR: stop_n value %d too short %d %d"%(stop_new,stop_n,rest_n))
self._case.set_value("STOP_N", stop_new)
self._case.set_value("CONTINUE_RUN", True)
self._case.set_value("REST_OPTION","never")
suffix = "rest"
success = SystemTestsCommon._run(self, suffix=suffix)
if not success:
break

return success

if success:
return self._erp_second_phase()
else:
return False

def report(self):
SystemTestsCommon.report(self)
28 changes: 15 additions & 13 deletions utils/python/CIME/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,7 @@ def __init__(self, case_root=None):
self._env_files_that_need_rewrite = set()

logger.debug("Initializing Case.")

self._env_entryid_files = []
self._env_entryid_files.append(EnvRun(case_root))
self._env_entryid_files.append(EnvBuild(case_root))
self._env_entryid_files.append(EnvMachPes(case_root))
self._env_entryid_files.append(EnvCase(case_root))
self._env_entryid_files.append(EnvBatch(case_root))
if os.path.isfile(os.path.join(case_root,"env_test.xml")):
self._env_entryid_files.append(EnvTest(case_root))
self._env_generic_files = []
self._env_generic_files.append(EnvMachSpecific(case_root))
self._env_generic_files.append(EnvArchive(case_root))
self._files = self._env_entryid_files + self._env_generic_files
self.read_xml(case_root)

# Hold arbitary values. In create_newcase we may set values
# for xml files that haven't been created yet. We need a place
Expand All @@ -103,6 +91,20 @@ def __init__(self, case_root=None):
self._component_config_files = []
self._component_classes = []

def read_xml(self, case_root):
self._env_entryid_files = []
self._env_entryid_files.append(EnvRun(case_root))
self._env_entryid_files.append(EnvBuild(case_root))
self._env_entryid_files.append(EnvMachPes(case_root))
self._env_entryid_files.append(EnvCase(case_root))
self._env_entryid_files.append(EnvBatch(case_root))
if os.path.isfile(os.path.join(case_root,"env_test.xml")):
self._env_entryid_files.append(EnvTest(case_root))
self._env_generic_files = []
self._env_generic_files.append(EnvMachSpecific(case_root))
self._env_generic_files.append(EnvArchive(case_root))
self._files = self._env_entryid_files + self._env_generic_files

def __del__(self):
self.flush()

Expand Down
6 changes: 5 additions & 1 deletion utils/python/CIME/preview_namelists.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
logger = logging.getLogger(__name__)

def preview_namelists(case, dryrun=False, casedir=None):
# refresh case xml files from object
case.flush()

# Get data from XML
exeroot = case.get_value("EXEROOT")
libroot = case.get_value("LIBROOT")
Expand Down Expand Up @@ -72,7 +75,8 @@ def preview_namelists(case, dryrun=False, casedir=None):
run_cmd("PREVIEW_NML=1 %s %s" % (cmd, caseroot))
else:
run_cmd("%s %s" % (cmd, caseroot))

# refresh case xml object from file
case.read_xml(caseroot)
# Save namelists to docdir
if (not os.path.isdir(docdir)):
os.makedirs(docdir)
Expand Down

0 comments on commit dea5064

Please sign in to comment.