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

Create env_postprocessing.xml in case root #4742

Merged
merged 11 commits into from
Mar 5, 2025
23 changes: 23 additions & 0 deletions CIME/XML/env_postprocessing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""
Interface to the env_postprocessing.xml file. This class inherits from EnvBase
"""
from CIME.XML.standard_module_setup import *

from CIME.XML.env_base import EnvBase

from CIME import utils
from CIME.utils import convert_to_type

logger = logging.getLogger(__name__)


class EnvPostprocessing(EnvBase):
def __init__(
self, case_root=None, infile="env_postprocessing.xml", read_only=False
):
"""
initialize an object interface to file env_postprocessing.xml in the case directory
"""
schema = os.path.join(utils.get_schema_path(), "env_entry_id.xsd")

EnvBase.__init__(self, case_root, infile, schema=schema, read_only=read_only)
32 changes: 32 additions & 0 deletions CIME/XML/postprocessing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""
Interface to the config_postprocessing.xml file. This class inherits from EntryID
"""

from CIME.XML.standard_module_setup import *
from CIME.XML.entry_id import EntryID
from CIME.XML.files import Files
from CIME.utils import expect

logger = logging.getLogger(__name__)


class Postprocessing(EntryID):
def __init__(self, infile=None, files=None):
"""
initialize an object
"""
if files is None:
files = Files()
if infile is None:
infile = files.get_value("POSTPROCESSING_SPEC_FILE")
expect(infile, "No postprocessing file defined in {}".format(files.filename))

schema = files.get_schema("POSTPROCESSING_SPEC_FILE")

EntryID.__init__(self, infile, schema=schema)

# Append the contents of $HOME/.cime/config_postprocessing.xml if it exists
# This could cause problems if node matchs are repeated when only one is expected
infile = os.path.join(os.environ.get("HOME"), ".cime", "config_postprocessing.xml")
if os.path.exists(infile):
EntryID.read(self, infile)
11 changes: 11 additions & 0 deletions CIME/case/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from CIME.XML.grids import Grids
from CIME.XML.batch import Batch
from CIME.XML.workflow import Workflow
from CIME.XML.postprocessing import Postprocessing
from CIME.XML.pio import PIO
from CIME.XML.archive import Archive
from CIME.XML.env_test import EnvTest
Expand All @@ -40,6 +41,7 @@
from CIME.XML.env_archive import EnvArchive
from CIME.XML.env_batch import EnvBatch
from CIME.XML.env_workflow import EnvWorkflow
from CIME.XML.env_postprocessing import EnvPostprocessing
from CIME.XML.generic_xml import GenericXML
from CIME.user_mod_support import apply_user_mods
from CIME.aprun import get_aprun_cmd_for_case
Expand Down Expand Up @@ -356,6 +358,9 @@ def read_xml(self):
self._env_entryid_files.append(
EnvWorkflow(self._caseroot, read_only=self._force_read_only)
)
self._env_entryid_files.append(
EnvPostprocessing(self._caseroot, read_only=self._force_read_only)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I think that you want to make sure POSTPROCESSING_SPEC_FILE exists before you create an EnvPostprocessing object.

Copy link
Contributor Author

@mnlevy1981 mnlevy1981 Feb 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mentioned this on Slack, but realized I should keep this thread going as well... self.get_value("POSTPROCESSING_SPEC_FILE") is None at this point. I tried other env_case.xml variables like MODEL and got None as well, so I think get_values() doesn't work in the Case.read_xml() method. How can I get the value of POSTPROCESSING_SPEC_FILE?

Copy link
Contributor

@jedwards4b jedwards4b Mar 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe generate the almost empty env_postprocessing.xml here and then delete it (or not) when POSTPROCESSING_SPEC_FILE is available.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll see how testing goes, but I think the logic for removing env_postprocessing.xml if it is empty actually belongs in Case.flush() instead of Case.configure(); that's what d393f0c does (though I realized I spun up a new sandbox on my laptop to test this off the supercomputer and didn't run pre-commit... so there will be at least one more "fix CI" commit coming)

)

if os.path.isfile(os.path.join(self._caseroot, "env_test.xml")):
self._env_entryid_files.append(
Expand Down Expand Up @@ -1577,6 +1582,10 @@ def configure(

workflow = Workflow(files=files)

env_postprocessing = self.get_env("postprocessing")
postprocessing = Postprocessing(files=files)
env_postprocessing.add_elements_by_group(srcobj=postprocessing)

env_batch.set_batch_system(batch, batch_system_type=batch_system_type)

bjobs = workflow.get_workflow_jobs(machine=machine_name, workflowid=workflowid)
Expand Down Expand Up @@ -2216,6 +2225,8 @@ def set_file(self, xmlfile):
new_env_file = EnvBatch(infile=xmlfile)
elif ftype == "env_workflow.xml":
new_env_file = EnvWorkflow(infile=xmlfile)
elif ftype == "env_postprocessing.xml":
new_env_file = EnvPostprocessing(infile=xmlfile)
elif ftype == "env_test.xml":
new_env_file = EnvTest(infile=xmlfile)
elif ftype == "env_archive.xml":
Expand Down
9 changes: 9 additions & 0 deletions CIME/data/config/cesm/config_files.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@
<schema>$CIMEROOT/CIME/data/config/xml_schemas/config_batch.xsd</schema>
</entry>

<entry id="POSTPROCESSING_SPEC_FILE">
<type>char</type>
<default_value>$SRCROOT/tools/CUPiD/cime_config/config_tool.xml</default_value>
<group>case_last</group>
<file>env_case.xml</file>
<desc>file containing postprocessing XML configuration (for documentation only - DO NOT EDIT)</desc>
<schema>$CIMEROOT/CIME/data/config/xml_schemas/entry_id.xsd</schema>
</entry>

<entry id="WORKFLOW_SPEC_FILE">
<type>char</type>
<default_value>$SRCROOT/ccs_config/machines/config_workflow.xml</default_value>
Expand Down
7 changes: 7 additions & 0 deletions CIME/data/config/config_headers.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@
</header>
</file>

<file name="env_postprocessing.xml">
<header>
These variables may be changed anytime during a run, they
control jobs that are dependent on case.run.
</header>
</file>

<file name="env_case.xml">
<header>
These variables CANNOT BE CHANGED once a case has been created.
Expand Down
Loading