Skip to content

Commit

Permalink
Remove unneeded lsf_server checks in queue_config
Browse files Browse the repository at this point in the history
  • Loading branch information
larsevj committed Jun 5, 2024
1 parent 65b7afe commit 99a29f6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 46 deletions.
27 changes: 3 additions & 24 deletions src/ert/config/queue_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,6 @@ def from_dict(cls, config_dict: ConfigDict) -> QueueConfig:
queue_options[queue_system].append(
(option_name, values[0] if values else "")
)
if values and option_name == "LSF_SERVER" and values[0].startswith("$"):
raise ConfigValidationError(
"Invalid server name specified for QUEUE_OPTION LSF"
f" LSF_SERVER: {values[0]}. Server name is currently an"
" undefined environment variable. The LSF_SERVER keyword is"
" usually provided by the site-configuration file, beware that"
" you are effectively replacing the default value provided."
)
if (
values
and option_name == "SUBMIT_SLEEP"
Expand Down Expand Up @@ -145,7 +137,7 @@ def max_running(self) -> int:
def _option_list_to_dict(option_list: List[Tuple[str, str]]) -> Dict[str, List[str]]:
temp_dict: Dict[str, List[str]] = defaultdict(list)
for option_string in option_list:
temp_dict.setdefault(option_string[0], []).append(option_string[1])
temp_dict[option_string[0]].append(option_string[1])
return temp_dict


Expand All @@ -168,8 +160,8 @@ def _check_num_cpu_requirement(
queue_system_options: List[Tuple[str, str]],
) -> None:
torque_options = _option_list_to_dict(queue_system_options)
num_nodes_str = torque_options.get("NUM_NODES", [""])[0]
num_cpus_per_node_str = torque_options.get("NUM_CPUS_PER_NODE", [""])[0]
num_nodes_str = torque_options.get("NUM_NODES", [""])[-1]
num_cpus_per_node_str = torque_options.get("NUM_CPUS_PER_NODE", [""])[-1]
num_nodes = int(num_nodes_str) if num_nodes_str else 1
num_cpus_per_node = int(num_cpus_per_node_str) if num_cpus_per_node_str else 1
if num_cpu != num_nodes * num_cpus_per_node:
Expand Down Expand Up @@ -201,19 +193,6 @@ def validate(self, mem_str_format: str) -> bool:
)


def parse_slurm_memopt(s: str) -> str:
return s.lower().replace("b", "").upper()


def parse_torque_memopt(s: str) -> str:
if re.match(r"\d+[kgmt](?!\w)", s, re.IGNORECASE):
return s.lower() + "b"
if re.match(r"^\d+$", s):
return s + "kb"

return s


queue_memory_usage_formats: Mapping[str, QueueMemoryStringFormat] = {
"SLURM": QueueMemoryStringFormat(suffixes=["", "K", "M", "G", "T"]),
"TORQUE": QueueMemoryStringFormat(suffixes=["kb", "mb", "gb", "KB", "MB", "GB"]),
Expand Down
24 changes: 2 additions & 22 deletions tests/unit_tests/config/test_queue_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def test_that_invalid_memory_pr_job_raises_validation_error(memory_with_unit_str
@pytest.mark.usefixtures("use_tmpdir")
@pytest.mark.parametrize(
"queue_system, queue_system_option",
[("LSF", "LSF_SERVER"), ("SLURM", "SQUEUE"), ("TORQUE", "QUEUE")],
[("LSF", "LSF_QUEUE"), ("SLURM", "SQUEUE"), ("TORQUE", "QUEUE")],
)
def test_that_overwriting_QUEUE_OPTIONS_warns(
tmp_path, monkeypatch, queue_system, queue_system_option, caplog
Expand Down Expand Up @@ -123,30 +123,10 @@ def test_that_overwriting_QUEUE_OPTIONS_warns(
) not in caplog.text


@pytest.mark.usefixtures("use_tmpdir", "set_site_config")
def test_undefined_LSF_SERVER_environment_variable_raises_validation_error():
filename = "config.ert"
with open(filename, "w", encoding="utf-8") as f:
f.write("NUM_REALIZATIONS 1\n")
f.write("QUEUE_SYSTEM LSF\n")
f.write("QUEUE_OPTION LSF LSF_SERVER $MY_SERVER\n")
with pytest.raises(
ConfigValidationError,
match=(
r"Invalid server name specified for QUEUE_OPTION LSF LSF_SERVER: "
r"\$MY_SERVER. Server name is currently an undefined environment variable."
r" The LSF_SERVER keyword is usually provided by the site-configuration"
r" file, beware that you are effectively replacing the default value"
r" provided."
),
):
ErtConfig.from_file(filename)


@pytest.mark.usefixtures("use_tmpdir")
@pytest.mark.parametrize(
"queue_system, queue_system_option",
[("LSF", "LSF_SERVER"), ("SLURM", "SQUEUE")],
[("LSF", "LSF_QUEUE"), ("SLURM", "SQUEUE")],
)
def test_initializing_empty_config_queue_options_resets_to_default_value(
queue_system, queue_system_option
Expand Down

0 comments on commit 99a29f6

Please sign in to comment.