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

Fix for env_batch.zip #4747

Merged
merged 1 commit into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
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
Loading