Skip to content

Commit 71d2b71

Browse files
authored
Merge pull request #4742 from mnlevy1981/add_postprocessing_env_file
Create env_postprocessing.xml in case root
2 parents 1a161a5 + d58c5ea commit 71d2b71

File tree

6 files changed

+106
-1
lines changed

6 files changed

+106
-1
lines changed

.github/workflows/testing.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ jobs:
153153
- name: Checkout code
154154
uses: actions/checkout@v3
155155
- name: Cache inputdata
156-
uses: actions/cache@v2
156+
uses: actions/cache@v3
157157
with:
158158
path: /storage/inputdata
159159
key: inputdata-2

CIME/XML/env_postprocessing.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""
2+
Interface to the env_postprocessing.xml file. This class inherits from EnvBase
3+
"""
4+
from CIME.XML.standard_module_setup import *
5+
6+
from CIME.XML.env_base import EnvBase
7+
8+
from CIME import utils
9+
10+
logger = logging.getLogger(__name__)
11+
12+
13+
class EnvPostprocessing(EnvBase):
14+
def __init__(
15+
self, case_root=None, infile="env_postprocessing.xml", read_only=False
16+
):
17+
"""
18+
initialize an object interface to file env_postprocessing.xml in the case directory
19+
"""
20+
schema = os.path.join(utils.get_schema_path(), "env_entry_id.xsd")
21+
22+
EnvBase.__init__(self, case_root, infile, schema=schema, read_only=read_only)

CIME/XML/postprocessing.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"""
2+
Interface to the config_postprocessing.xml file. This class inherits from EntryID
3+
"""
4+
5+
from CIME.XML.standard_module_setup import *
6+
from CIME.XML.entry_id import EntryID
7+
from CIME.XML.files import Files
8+
from CIME.utils import expect
9+
10+
logger = logging.getLogger(__name__)
11+
12+
13+
class Postprocessing(EntryID):
14+
def __init__(self, infile=None, files=None):
15+
"""
16+
initialize an object
17+
"""
18+
if files is None:
19+
files = Files()
20+
if infile is None:
21+
infile = files.get_value("POSTPROCESSING_SPEC_FILE")
22+
if infile is not None:
23+
self.file_exists = os.path.isfile(infile)
24+
else:
25+
self.file_exists = False
26+
if not self.file_exists:
27+
return
28+
expect(infile, "No postprocessing file defined in {}".format(files.filename))
29+
30+
schema = files.get_schema("POSTPROCESSING_SPEC_FILE")
31+
32+
EntryID.__init__(self, infile, schema=schema)
33+
34+
# Append the contents of $HOME/.cime/config_postprocessing.xml if it exists
35+
# This could cause problems if node matchs are repeated when only one is expected
36+
infile = os.path.join(
37+
os.environ.get("HOME"), ".cime", "config_postprocessing.xml"
38+
)
39+
if os.path.exists(infile):
40+
EntryID.read(self, infile)

CIME/case/case.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from CIME.XML.grids import Grids
3030
from CIME.XML.batch import Batch
3131
from CIME.XML.workflow import Workflow
32+
from CIME.XML.postprocessing import Postprocessing
3233
from CIME.XML.pio import PIO
3334
from CIME.XML.archive import Archive
3435
from CIME.XML.env_test import EnvTest
@@ -40,6 +41,7 @@
4041
from CIME.XML.env_archive import EnvArchive
4142
from CIME.XML.env_batch import EnvBatch
4243
from CIME.XML.env_workflow import EnvWorkflow
44+
from CIME.XML.env_postprocessing import EnvPostprocessing
4345
from CIME.XML.generic_xml import GenericXML
4446
from CIME.user_mod_support import apply_user_mods
4547
from CIME.aprun import get_aprun_cmd_for_case
@@ -109,6 +111,7 @@ def __init__(self, case_root=None, read_only=True, record=False, non_local=False
109111
case_root
110112
),
111113
)
114+
self._existing_case = os.path.isdir(case_root)
112115

113116
self._caseroot = case_root
114117
logger.debug("Initializing Case.")
@@ -356,6 +359,10 @@ def read_xml(self):
356359
self._env_entryid_files.append(
357360
EnvWorkflow(self._caseroot, read_only=self._force_read_only)
358361
)
362+
if not self._existing_case or os.path.isfile("env_postprocessing.xml"):
363+
self._env_entryid_files.append(
364+
EnvPostprocessing(self._caseroot, read_only=self._force_read_only)
365+
)
359366

360367
if os.path.isfile(os.path.join(self._caseroot, "env_test.xml")):
361368
self._env_entryid_files.append(
@@ -430,6 +437,19 @@ def flush(self, flushall=False):
430437
# do not flush if caseroot wasnt created
431438
return
432439

440+
_postprocessing_spec_file = self.get_value("POSTPROCESSING_SPEC_FILE")
441+
if _postprocessing_spec_file is not None:
442+
have_postprocessing = os.path.isfile(_postprocessing_spec_file)
443+
else:
444+
have_postprocessing = False
445+
if not have_postprocessing:
446+
# Remove env_postprocessing.xml from self._files
447+
self._files = [
448+
file
449+
for file in self._files
450+
if file.get_id() != "env_postprocessing.xml"
451+
]
452+
433453
for env_file in self._files:
434454
env_file.write(force_write=flushall)
435455

@@ -1577,6 +1597,11 @@ def configure(
15771597

15781598
workflow = Workflow(files=files)
15791599

1600+
postprocessing = Postprocessing(files=files)
1601+
if postprocessing.file_exists:
1602+
env_postprocessing = self.get_env("postprocessing")
1603+
env_postprocessing.add_elements_by_group(srcobj=postprocessing)
1604+
15801605
env_batch.set_batch_system(batch, batch_system_type=batch_system_type)
15811606

15821607
bjobs = workflow.get_workflow_jobs(machine=machine_name, workflowid=workflowid)
@@ -2216,6 +2241,8 @@ def set_file(self, xmlfile):
22162241
new_env_file = EnvBatch(infile=xmlfile)
22172242
elif ftype == "env_workflow.xml":
22182243
new_env_file = EnvWorkflow(infile=xmlfile)
2244+
elif ftype == "env_postprocessing.xml":
2245+
new_env_file = EnvPostprocessing(infile=xmlfile)
22192246
elif ftype == "env_test.xml":
22202247
new_env_file = EnvTest(infile=xmlfile)
22212248
elif ftype == "env_archive.xml":

CIME/data/config/cesm/config_files.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@
5555
<schema>$CIMEROOT/CIME/data/config/xml_schemas/config_batch.xsd</schema>
5656
</entry>
5757

58+
<entry id="POSTPROCESSING_SPEC_FILE">
59+
<type>char</type>
60+
<default_value>$SRCROOT/tools/CUPiD/cime_config/config_tool.xml</default_value>
61+
<group>case_last</group>
62+
<file>env_case.xml</file>
63+
<desc>file containing postprocessing XML configuration (for documentation only - DO NOT EDIT)</desc>
64+
<schema>$CIMEROOT/CIME/data/config/xml_schemas/entry_id.xsd</schema>
65+
</entry>
66+
5867
<entry id="WORKFLOW_SPEC_FILE">
5968
<type>char</type>
6069
<default_value>$SRCROOT/ccs_config/machines/config_workflow.xml</default_value>

CIME/data/config/config_headers.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@
1717
</header>
1818
</file>
1919

20+
<file name="env_postprocessing.xml">
21+
<header>
22+
These variables may be changed anytime during a run, they
23+
control jobs that are dependent on case.run.
24+
</header>
25+
</file>
26+
2027
<file name="env_case.xml">
2128
<header>
2229
These variables CANNOT BE CHANGED once a case has been created.

0 commit comments

Comments
 (0)