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

make the hidden status of batch jobs xml dependent #4677

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
1 change: 0 additions & 1 deletion CIME/Tools/xmlchange
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ from standard_script_setup import *
from CIME.utils import (
expect,
convert_to_type,
get_batch_script_for_job,
Timeout,
)
from CIME.status import append_case_status
Expand Down
61 changes: 56 additions & 5 deletions CIME/XML/env_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def __init__(self, case_root=None, infile="env_batch.xml", read_only=False):
initialize an object interface to file env_batch.xml in the case directory
"""
self._batchtype = None
self._hidden_batch_script = {}
# This arbitrary setting should always be overwritten
self._default_walltime = "00:20:00"
schema = os.path.join(utils.get_schema_path(), "env_batch.xsd")
Expand Down Expand Up @@ -257,7 +258,20 @@ def make_batch_script(self, input_template, job, case, outfile=None):
subgroup=job,
overrides=overrides,
)
output_name = get_batch_script_for_job(job) if outfile is None else outfile
env_workflow = case.get_env("workflow")
self._hidden_batch_script[job] = env_workflow.get_value("hidden", subgroup=job)
output_name = (
get_batch_script_for_job(
job,
hidden=(
self._hidden_batch_script[job]
if job in self._hidden_batch_script
else None
),
)
if outfile is None
else outfile
)
logger.info("Creating file {}".format(output_name))
with open(output_name, "w") as fd:
fd.write(output_text)
Expand Down Expand Up @@ -745,7 +759,17 @@ def submit_jobs(
alljobs = [
j
for j in alljobs
if os.path.isfile(os.path.join(self._caseroot, get_batch_script_for_job(j)))
if os.path.isfile(
os.path.join(
self._caseroot,
get_batch_script_for_job(
j,
hidden=self._hidden_batch_script[j]
if j in self._hidden_batch_script
else None,
),
)
)
]

startindex = 0
Expand Down Expand Up @@ -1071,22 +1095,49 @@ def _submit_single_job(
batchsubmit,
submitargs,
batchredirect,
get_batch_script_for_job(job),
get_batch_script_for_job(
job,
hidden=(
self._hidden_batch_script[job]
if job in self._hidden_batch_script
else None
),
),
)
elif batch_env_flag:
sequence = (
batchsubmit,
submitargs,
run_args,
batchredirect,
os.path.join(self._caseroot, get_batch_script_for_job(job)),
os.path.join(
self._caseroot,
get_batch_script_for_job(
job,
hidden=(
self._hidden_batch_script[job]
if job in self._hidden_batch_script
else None
),
),
),
)
else:
sequence = (
batchsubmit,
submitargs,
batchredirect,
os.path.join(self._caseroot, get_batch_script_for_job(job)),
os.path.join(
self._caseroot,
get_batch_script_for_job(
job,
hidden=(
self._hidden_batch_script[job]
if job in self._hidden_batch_script
else None
),
),
),
run_args,
)

Expand Down
2 changes: 2 additions & 0 deletions CIME/data/config/xml_schemas/config_workflow.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

<!-- simple elements -->
<xs:element name="template" type="xs:anyURI"/>
<xs:element name="hidden" type="xs:string" default="True"/>
<xs:element name="task_count" type="xs:string"/>
<xs:element name="tasks_per_node" type="xs:string"/>
<xs:element name="walltime" type="xs:string"/>
Expand Down Expand Up @@ -57,6 +58,7 @@
<xs:complexType>
<xs:sequence>
<xs:element ref="template"/>
<xs:element ref="hidden" minOccurs="0"/>
<xs:element minOccurs="0" ref="dependency"/>
<xs:element ref="prereq"/>
<xs:element ref="runtime_parameters" minOccurs="0" maxOccurs="unbounded"/>
Expand Down
3 changes: 2 additions & 1 deletion CIME/tests/test_sys_cime_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,8 @@ def test_self_build_cprnc(self):
)

self.run_cmd_assert_result(
"./xmlchange CCSM_CPRNC=this_is_a_broken_cprnc", from_dir=casedir
"./xmlchange CCSM_CPRNC=this_is_a_broken_cprnc --file env_test.xml",
from_dir=casedir,
)
self.run_cmd_assert_result("./case.build", from_dir=casedir)
self.run_cmd_assert_result("./case.submit", from_dir=casedir)
Expand Down
7 changes: 5 additions & 2 deletions CIME/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2530,8 +2530,11 @@ def run_bld_cmd_ensure_logging(cmd, arg_logger, from_dir=None, timeout=None):
expect(stat == 0, filter_unicode(errput))


def get_batch_script_for_job(job):
return job if "st_archive" in job else "." + job
def get_batch_script_for_job(job, hidden="True"):
# this if statement is for backward compatibility
if job == "case.st_archive" and not hidden:
hidden = "False"
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the new logic in this function would be easier to parse if the default for hidden is None and then the if block was

if hidden is None:
  if job == "case.st_archive":
    hidden = False
  else:
    hidden = True

or, to avoid setting logical variables inside an if statement,

if hidden is None:
  hidden = (job != "case.st_archive")

Copy link
Contributor

Choose a reason for hiding this comment

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

The only catch is that we'd need to make sure hidden is treated as a boolean flag if it is present in the XML file, I assume from the current logic it's read in as a string

return "." + job if not hidden or hidden == "True" else job


def string_in_list(_string, _list):
Expand Down
Loading