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 joint option for queue_name #9355

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
13 changes: 13 additions & 0 deletions docs/ert/reference/configuration/queue.rst
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ The following is a list of available LSF configuration options:

QUEUE_OPTION LSF LSF_QUEUE name_of_queue

.. note::
It is preferred to use the generic option instead:
QUEUE_OPTION GENERIC QUEUE_NAME name_of_queue

.. _lsf_resource:
.. topic:: LSF_RESOURCE

Expand Down Expand Up @@ -264,6 +268,10 @@ The following is a list of all queue-specific configuration options:

QUEUE_OPTION TORQUE QUEUE name_of_queue

.. note::
It is preferred to use the generic option instead:
QUEUE_OPTION GENERIC QUEUE_NAME name_of_queue

.. _torque_cluster_label:
.. topic:: CLUSTER_LABEL

Expand Down Expand Up @@ -428,6 +436,10 @@ only the most necessary options have been added.

QUEUE_OPTION SLURM PARTITION foo

.. note::
It is preferred to use the generic option instead:
QUEUE_OPTION GENERIC QUEUE_NAME name_of_queue

.. _slurm_squeue_timeout:
.. topic:: SQUEUE_TIMEOUT

Expand Down Expand Up @@ -515,6 +527,7 @@ the `GENERIC` keyword. ::
QUEUE_SYSTEM LSF
QUEUE_OPTION GENERIC MAX_RUNNING 10
QUEUE_OPTION GENERIC SUBMIT_SLEEP 2
QUEUE_OPTION GENERIC QUEUE_NAME some_name

Is equivalent to::

Expand Down
18 changes: 12 additions & 6 deletions src/ert/config/queue_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,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 @@ -41,6 +42,7 @@ class QueueOptions:
submit_sleep: pydantic.NonNegativeFloat = 0.0
project_code: Optional[str] = None
activate_script: str = field(default_factory=activate_script)
queue_name: Optional[NonEmptyString] = None

@staticmethod
def create_queue_options(
Expand Down Expand Up @@ -105,15 +107,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 @@ -126,7 +126,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 @@ -141,7 +140,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 @@ -167,7 +165,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 @@ -181,7 +178,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 @@ -298,6 +294,16 @@ 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")
):
_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 @@ -245,16 +245,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 @@ -291,15 +294,15 @@ def get_server_queue_options(
if queue_system == QueueSystem.LSF:
queue = LsfQueueOptions(
activate_script=script,
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(
activate_script=script,
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(activate_script=script)
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
23 changes: 20 additions & 3 deletions tests/ert/unit_tests/config/test_queue_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,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 @@ -234,7 +234,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 @@ -257,7 +257,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 Expand Up @@ -522,3 +522,20 @@ def test_default_activate_script_generation(expected, monkeypatch, venv):
monkeypatch.delenv("VIRTUAL_ENV", raising=False)
options = QueueOptions(name="local")
assert options.activate_script == expected


@pytest.mark.parametrize(
"queue_system, queue_option",
(
("LSF", "LSF_QUEUE"),
("TORQUE", "QUEUE"),
("SLURM", "PARTITION"),
),
)
def test_deprecated_queue_name_initialization(queue_system, queue_option):
assert (
QueueConfig.from_dict(
{"QUEUE_OPTION": [[queue_system, queue_option, "some_name"]]}
).queue_options.queue_name
== "some_name"
)
6 changes: 3 additions & 3 deletions tests/everest/test_res_initialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def slurm_queue_system():
ErtConfigKeys.QUEUE_OPTION: [
(
"SLURM",
"PARTITION",
"QUEUE_NAME",
"default-queue",
),
(
Expand Down Expand Up @@ -263,7 +263,7 @@ def test_snake_everest_to_ert_torque(copy_test_data_to_tmp):
("TORQUE", "QSUB_CMD", "qsub"),
("TORQUE", "QSTAT_CMD", "qstat"),
("TORQUE", "QDEL_CMD", "qdel"),
("TORQUE", "QUEUE", "permanent_8"),
("TORQUE", "QUEUE_NAME", "permanent_8"),
("TORQUE", "MEMORY_PER_JOB", "100mb"),
("TORQUE", "KEEP_QSUB_OUTPUT", 1),
("TORQUE", "SUBMIT_SLEEP", 0.5),
Expand Down Expand Up @@ -367,7 +367,7 @@ def test_queue_configuration(copy_test_data_to_tmp):

expected_options = [
("LSF", "MAX_RUNNING", 3),
("LSF", "LSF_QUEUE", "mr"),
("LSF", "QUEUE_NAME", "mr"),
("LSF", "LSF_RESOURCE", "span = 1 && select[x86 and GNU/Linux]"),
]

Expand Down