Skip to content

Commit

Permalink
Make joint option for queue_name
Browse files Browse the repository at this point in the history
  • Loading branch information
oyvindeide committed Nov 27, 2024
1 parent ca1806e commit 61a909e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 17 deletions.
23 changes: 17 additions & 6 deletions src/ert/config/queue_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import re
import shutil
from abc import abstractmethod
from copy import copy
from dataclasses import asdict, field, fields
from typing import Any, Dict, List, Literal, Mapping, Optional, Union, no_type_check

Expand Down Expand Up @@ -32,6 +33,7 @@ class QueueOptions:
max_running: pydantic.NonNegativeInt = 0
submit_sleep: pydantic.NonNegativeFloat = 0.0
project_code: Optional[str] = None
queue_name: Optional[NonEmptyString] = None

@staticmethod
def create_queue_options(
Expand Down Expand Up @@ -96,15 +98,13 @@ class LsfQueueOptions(QueueOptions):
bkill_cmd: Optional[NonEmptyString] = None
bsub_cmd: Optional[NonEmptyString] = None
exclude_host: Optional[str] = None
lsf_queue: Optional[NonEmptyString] = None
lsf_resource: Optional[str] = None

@property
def driver_options(self) -> Dict[str, Any]:
driver_dict = asdict(self)
driver_dict.pop("name")
driver_dict["exclude_hosts"] = driver_dict.pop("exclude_host")
driver_dict["queue_name"] = driver_dict.pop("lsf_queue")
driver_dict["resource_requirement"] = driver_dict.pop("lsf_resource")
driver_dict.pop("submit_sleep")
driver_dict.pop("max_running")
Expand All @@ -117,7 +117,6 @@ class TorqueQueueOptions(QueueOptions):
qsub_cmd: Optional[NonEmptyString] = None
qstat_cmd: Optional[NonEmptyString] = None
qdel_cmd: Optional[NonEmptyString] = None
queue: Optional[NonEmptyString] = None
memory_per_job: Optional[NonEmptyString] = None
num_cpus_per_node: pydantic.PositiveInt = 1
num_nodes: pydantic.PositiveInt = 1
Expand All @@ -132,7 +131,6 @@ class TorqueQueueOptions(QueueOptions):
def driver_options(self) -> Dict[str, Any]:
driver_dict = asdict(self)
driver_dict.pop("name")
driver_dict["queue_name"] = driver_dict.pop("queue")
driver_dict.pop("max_running")
driver_dict.pop("submit_sleep")
driver_dict.pop("qstat_options")
Expand All @@ -158,7 +156,6 @@ class SlurmQueueOptions(QueueOptions):
include_host: str = ""
memory: Optional[NonEmptyString] = None
memory_per_cpu: Optional[NonEmptyString] = None
partition: Optional[NonEmptyString] = None # aka queue_name
squeue_timeout: pydantic.PositiveFloat = 2
max_runtime: Optional[pydantic.NonNegativeFloat] = None

Expand All @@ -172,7 +169,6 @@ def driver_options(self) -> Dict[str, Any]:
driver_dict["squeue_cmd"] = driver_dict.pop("squeue")
driver_dict["exclude_hosts"] = driver_dict.pop("exclude_host")
driver_dict["include_hosts"] = driver_dict.pop("include_host")
driver_dict["queue_name"] = driver_dict.pop("partition")
driver_dict.pop("max_running")
driver_dict.pop("submit_sleep")
return driver_dict
Expand Down Expand Up @@ -289,6 +285,21 @@ def from_dict(cls, config_dict: ConfigDict) -> QueueConfig:
stop_long_running = config_dict.get(ConfigKeys.STOP_LONG_RUNNING, False)

_raw_queue_options = config_dict.get("QUEUE_OPTION", [])
for i, (q_system, *options) in enumerate(copy(_raw_queue_options)):
if (
(q_system == QueueSystem.LSF and options[0] == "LSF_QUEUE") # noqa: PLR0916
or (q_system == QueueSystem.SLURM and options[0] == "PARTITION")
or (q_system == QueueSystem.TORQUE and options[0] == "QUEUE")
):
ConfigWarning.deprecation_warn(
f"Deprecated keyword: {options[0]} for QUEUE_OPTION {q_system}, use: "
f"QUEUE_OPTION GENERIC QUEUE_NAME {options[1] if len(options) >= 2 else ''}",
_raw_queue_options[i],
)
_raw_queue_options[i] = [
QueueSystemWithGeneric.GENERIC,
"QUEUE_NAME",
] + options[1:]
_grouped_queue_options = _group_queue_options_by_queue_system(
_raw_queue_options
)
Expand Down
13 changes: 8 additions & 5 deletions src/everest/detached/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,16 +239,19 @@ def start_monitor(
_QUEUE_SYSTEMS: Mapping[Literal["LSF", "SLURM"], dict] = {
"LSF": {
"options": [(CK.LSF_OPTIONS, "LSF_RESOURCE")],
"name": "LSF_QUEUE",
"name": "QUEUE_NAME",
},
"SLURM": {
"options": [
(CK.SLURM_EXCLUDE_HOST_OPTION, "EXCLUDE_HOST"),
(CK.SLURM_INCLUDE_HOST_OPTION, "INCLUDE_HOST"),
],
"name": "PARTITION",
"name": "QUEUE_NAME",
},
"TORQUE": {
"options": [CK.TORQUE_CLUSTER_LABEL, "CLUSTER_LABEL"],
"name": "QUEUE_NAME",
},
"TORQUE": {"options": [CK.TORQUE_CLUSTER_LABEL, "CLUSTER_LABEL"], "name": "QUEUE"},
}


Expand Down Expand Up @@ -284,14 +287,14 @@ def get_server_queue_options(

if queue_system == QueueSystem.LSF:
queue = LsfQueueOptions(
lsf_queue=ever_queue_config.name,
queue_name=ever_queue_config.name,
lsf_resource=ever_queue_config.options,
)
elif queue_system == QueueSystem.SLURM:
queue = SlurmQueueOptions(
exclude_host=ever_queue_config.exclude_host,
include_host=ever_queue_config.include_host,
partition=ever_queue_config.name,
queue_name=ever_queue_config.name,
)
elif queue_system == QueueSystem.TORQUE:
queue = TorqueQueueOptions()
Expand Down
6 changes: 3 additions & 3 deletions src/everest/queue_driver/queue_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

_LSF_OPTIONS = [
(ConfigKeys.CORES, "MAX_RUNNING"),
(ConfigKeys.LSF_QUEUE_NAME, "LSF_QUEUE"),
(ConfigKeys.LSF_QUEUE_NAME, "QUEUE_NAME"),
(ConfigKeys.LSF_OPTIONS, "LSF_RESOURCE"),
]

_SLURM_OPTIONS = [
(ConfigKeys.CORES, "MAX_RUNNING"),
(ConfigKeys.SLURM_QUEUE, "PARTITION"),
(ConfigKeys.SLURM_QUEUE, "QUEUE_NAME"),
(ConfigKeys.SLURM_SBATCH, "SBATCH"),
(ConfigKeys.SLURM_SCANCEL, "SCANCEL"),
(ConfigKeys.SLURM_SCONTROL, "SCONTROL"),
Expand All @@ -31,7 +31,7 @@
(ConfigKeys.TORQUE_QSUB_CMD, "QSUB_CMD"),
(ConfigKeys.TORQUE_QSTAT_CMD, "QSTAT_CMD"),
(ConfigKeys.TORQUE_QDEL_CMD, "QDEL_CMD"),
(ConfigKeys.TORQUE_QUEUE_NAME, "QUEUE"),
(ConfigKeys.TORQUE_QUEUE_NAME, "QUEUE_NAME"),
(ConfigKeys.TORQUE_CLUSTER_LABEL, "CLUSTER_LABEL"),
(ConfigKeys.CORES_PER_NODE, "NUM_CPUS_PER_NODE"),
(ConfigKeys.TORQUE_MEMORY_PER_JOB, "MEMORY_PER_JOB"),
Expand Down
6 changes: 3 additions & 3 deletions tests/ert/unit_tests/config/test_queue_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def test_that_invalid_memory_pr_job_raises_validation_error(

@pytest.mark.parametrize(
"queue_system, queue_system_option",
[("LSF", "LSF_QUEUE"), ("SLURM", "SQUEUE"), ("TORQUE", "QUEUE")],
[("LSF", "LSF_QUEUE"), ("SLURM", "PARTITION"), ("TORQUE", "QUEUE")],
)
def test_that_overwriting_QUEUE_OPTIONS_warns(
queue_system, queue_system_option, caplog
Expand All @@ -233,7 +233,7 @@ def test_that_overwriting_QUEUE_OPTIONS_warns(
f"QUEUE_OPTION {queue_system} MAX_RUNNING 10\n",
)
assert (
f"Overwriting QUEUE_OPTION {queue_system} {queue_system_option}: \n Old value:"
"Overwriting QUEUE_OPTION GENERIC QUEUE_NAME: \n Old value:"
" test_0 \n New value: test_1"
) in caplog.text and (
f"Overwriting QUEUE_OPTION {queue_system} MAX_RUNNING: \n Old value:"
Expand All @@ -256,7 +256,7 @@ def test_initializing_empty_config_queue_options_resets_to_default_value(
)

if queue_system == "LSF":
assert config_object.queue_config.queue_options.lsf_queue is None
assert config_object.queue_config.queue_options.queue_name is None
if queue_system == "SLURM":
assert config_object.queue_config.queue_options.squeue == "squeue"
assert config_object.queue_config.queue_options.max_running == 0
Expand Down

0 comments on commit 61a909e

Please sign in to comment.