Skip to content
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
28 changes: 22 additions & 6 deletions CrocoDash/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ def __init__(
ntasks_ocn : int, optional
Number of tasks for the ocean model. If None, defaults to VisualCaseGen Grid Calculation.
job_queue: str, optional
The queue to submit the CESM case to. If None, defaults to the CESM defaults (usually main)
The queue to submit the CESM case to. If None, defaults to the CESM defaults (usually main).
Must be one of the machine's queues. Ignored, with a warning, on a machine with no
batch system (e.g. ubuntu-latest).
job_wallclock_time: str, optional
Must be in the form hh:mm:ss. If None, defaults to the CESM defaults
"""
Expand Down Expand Up @@ -1097,20 +1099,34 @@ def _apply_final_xmlchanges(
xmlchange(
"MOM6_MEMORY_MODE",
"dynamic_symmetric",
is_non_local=self.cc._is_non_local(),
is_non_local=self.is_non_local,
)

# xmlchange("ROOTPE_OCN", 128, is_non_local=self.cc._is_non_local()) -> needs to be before the the setup
# xmlchange("ROOTPE_OCN", 128, is_non_local=self.is_non_local) -> needs to be before the the setup
if ntasks_ocn is not None:
xmlchange("NTASKS_OCN", ntasks_ocn, is_non_local=self.cc._is_non_local())
xmlchange("NTASKS_OCN", ntasks_ocn, is_non_local=self.is_non_local)
# This will trigger for both the run and the archiver.
if job_queue is not None:
xmlchange("JOB_QUEUE", job_queue, is_non_local=self.cc._is_non_local())
# xmlchange rejects a JOB_QUEUE the machine doesn't list, and a
# machine with no batch system (e.g. ubuntu-latest) lists none.
if self._cime_case.get_value("BATCH_SYSTEM") == "none":
Comment thread
alperaltuntas marked this conversation as resolved.
Resolved
Comment thread
alperaltuntas marked this conversation as resolved.
Resolved
print(
f"WARNING: ignoring job_queue={job_queue!r}: machine "
f"{self.machine} has no batch system."
)
else:
queues = self._cime_case.get_env("batch")._get_all_queue_names()
if job_queue not in queues:
raise ValueError(
f"job_queue={job_queue!r} is not a queue on machine "
f"{self.machine}. Valid queues: {', '.join(queues) or 'none'}."
)
xmlchange("JOB_QUEUE", job_queue, is_non_local=self.is_non_local)
if job_wallclock_time is not None:
xmlchange(
"JOB_WALLCLOCK_TIME",
job_wallclock_time,
is_non_local=self.cc._is_non_local(),
is_non_local=self.is_non_local,
)

def validate_case(self):
Expand Down
44 changes: 44 additions & 0 deletions tests/test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,50 @@ def test_coupling_interval_rejects_uneven_ncpl():
_stub_case_for_ncpl(7, 5450.0)._coupling_interval("ICE")


def _stub_case_for_xmlchanges(monkeypatch, batch_system, queues):
"""A Case with only what _apply_final_xmlchanges reads; returns it and
the xml variables it changes."""
from types import SimpleNamespace
import CrocoDash.case as case_mod

changed = {}
monkeypatch.setattr(
case_mod, "xmlchange", lambda var, val, **kw: changed.update({var: val})
)
case = case_mod.Case.__new__(case_mod.Case)
case.machine = "some-machine"
case.is_non_local = False
batch = SimpleNamespace(_get_all_queue_names=lambda: queues)
case._cime_case = SimpleNamespace(
get_value={"BATCH_SYSTEM": batch_system}.__getitem__,
get_env={"batch": batch}.__getitem__,
)
return case, changed


@pytest.mark.parametrize(
"batch_system, queues, expected",
[
("pbs", ["develop", "main"], "develop"),
("none", [], None), # ubuntu-latest: xmlchange rejects any queue
],
)
def test_job_queue_is_set_only_on_a_machine_with_a_batch_system(
monkeypatch, batch_system, queues, expected
):
case, changed = _stub_case_for_xmlchanges(monkeypatch, batch_system, queues)
case._apply_final_xmlchanges(job_queue="develop", job_wallclock_time="01:00:00")
assert changed.get("JOB_QUEUE") == expected
assert changed["JOB_WALLCLOCK_TIME"] == "01:00:00"


def test_an_unknown_job_queue_lists_the_valid_ones(monkeypatch):
case, changed = _stub_case_for_xmlchanges(monkeypatch, "pbs", ["develop", "main"])
with pytest.raises(ValueError, match="Valid queues: develop, main"):
case._apply_final_xmlchanges(job_queue="mian")
assert "JOB_QUEUE" not in changed


def test_a_configuration_error_raises_instead_of_returning_a_half_built_case(
CrocoDash_case_factory, tmp_path, monkeypatch
):
Expand Down
Loading