Skip to content

Commit

Permalink
Merge pull request #4747 from ESMCI/jgfouca/fix_env_batch_zip
Browse files Browse the repository at this point in the history
Fix for env_batch.zip

Need to watch out for scan_children finding more children than intended when node1 has no attributes

Test suite: ./scripts_regression_tests.py test_unit_xml_env_batch.TestXMLEnvBatch
Test baseline:
Test namelist changes:
Test status: bit for bit

Fixes [CIME Github issue #]

User interface changes?:

Update gh-pages html (Y/N)?:
  • Loading branch information
jgfouca authored Feb 10, 2025
2 parents 5bbdc1d + e1a520a commit 3d87cf1
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 3 deletions.
20 changes: 17 additions & 3 deletions CIME/XML/env_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -1421,10 +1421,24 @@ def zip(self, other, name):
other_pnode = None

for node1 in self.get_children(root=self_pnode):
for node2 in other.scan_children(
other_children = other.scan_children(
node1.name, attributes=node1.attrib, root=other_pnode
):
yield node1, node2
)
real_other_children = []
if not node1.attrib:
# Only keep elements that had no attributes. If node1 has no attributes
# scan_children will return ALL elements with matching name.
for other_child in other_children:
if node1.attrib == other_child.attrib:
real_other_children.append(other_child)
else:
real_other_children = other_children

expect(
len(real_other_children) == 1,
"Multiple matches in zip for single node",
)
yield node1, real_other_children[0]

def _compare_arg(self, index, arg1, arg2):
try:
Expand Down
68 changes: 68 additions & 0 deletions CIME/tests/test_unit_xml_env_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,59 @@
</file>"""


XML_CHECK = b"""<?xml version="1.0"?>
<file id="env_batch.xml" version="2.0">
<header>
These variables may be changed anytime during a run, they
control arguments to the batch submit command.
</header>
<group id="config_batch">
<entry id="BATCH_SYSTEM" value="nersc_slurm">
<type>char</type>
<valid_values>miller_slurm,nersc_slurm,lc_slurm,moab,pbs,pbspro,lsf,slurm,cobalt,cobalt_theta,slurm_single_node,none</valid_values>
<desc>The batch system type to use for this machine.</desc>
</entry>
</group>
<group id="job_submission">
<entry id="PROJECT_REQUIRED" value="TRUE">
<type>logical</type>
<valid_values>TRUE,FALSE</valid_values>
<desc>whether the PROJECT value is required on this machine</desc>
</entry>
</group>
<batch_system MACH="pm-gpu" type="nersc_slurm">
<directives>
<directive> --constraint=gpu</directive>
</directives>
<directives COMPSET="!.*MMF.*" compiler="gnugpu">
<directive> --gpus-per-node=4</directive>
<directive> --gpu-bind=none</directive>
</directives>
<directives COMPSET=".*MMF.*" compiler="gnugpu">
<directive> --gpus-per-task=1</directive>
<directive> --gpu-bind=map_gpu:0,1,2,3</directive>
</directives>
<directives compiler="nvidiagpu">
<directive> --gpus-per-node=4</directive>
<directive> --gpu-bind=none</directive>
</directives>
<directives compiler="gnu">
<directive> -G 0</directive>
</directives>
<directives compiler="nvidia">
<directive> -G 0</directive>
</directives>
<queues>
<queue default="true" nodemax="1792" walltimemax="00:45:00">regular</queue>
<queue nodemax="1792" strict="true" walltimemax="00:45:00">preempt</queue>
<queue nodemax="1792" strict="true" walltimemax="00:45:00">shared</queue>
<queue nodemax="1792" strict="true" walltimemax="00:45:00">overrun</queue>
<queue nodemax="4" strict="true" walltimemax="00:15:00">debug</queue>
</queues>
</batch_system>
</file>"""


def _open_temp_file(stack, data):
tfile = stack.enter_context(tempfile.NamedTemporaryFile())

Expand Down Expand Up @@ -175,6 +228,21 @@ def test_compare_xml(self):

assert diff2 == expected_diff2

def test_compare_xml_same(self):
with ExitStack() as stack:
file1 = _open_temp_file(stack, XML_CHECK)
batch1 = EnvBatch(infile=file1.name)

file2 = _open_temp_file(stack, XML_CHECK)
batch2 = EnvBatch(infile=file2.name)

diff = batch1.compare_xml(batch2)
diff2 = batch2.compare_xml(batch1)

expected_diff = {}
assert diff == expected_diff, f"{diff}"
assert diff2 == expected_diff, f"{diff2}"

@mock.patch("CIME.XML.env_batch.EnvBatch._submit_single_job")
def test_submit_jobs(self, _submit_single_job):
case = mock.MagicMock()
Expand Down

0 comments on commit 3d87cf1

Please sign in to comment.