Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
oyvindeide committed Dec 10, 2024
1 parent 019f0fb commit f9d9737
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 62 deletions.
2 changes: 1 addition & 1 deletion src/everest/config/everest_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ def with_defaults(cls, **kwargs):
"config_path": ".",
}

return EverestConfig.model_validate({**defaults, **kwargs})
return cls.model_validate({**defaults, **kwargs})

@staticmethod
def lint_config_dict(config: dict) -> List["ErrorDetails"]:
Expand Down
2 changes: 1 addition & 1 deletion src/everest/config/simulator_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class SimulatorConfig(BaseModel, extra="forbid"): # type: ignore
""",
)
queue_system: Union[
LocalQueueOptions, LsfQueueOptions, SlurmQueueOptions, TorqueQueueOptions, None
LsfQueueOptions, LocalQueueOptions, SlurmQueueOptions, TorqueQueueOptions, None
] = Field(
default=None,
description="Defines which queue system the everest submits jobs to",
Expand Down
1 change: 1 addition & 0 deletions src/everest/simulator/everest_to_ert.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,7 @@ def everest_to_ert_config(ever_config: EverestConfig) -> ErtConfig:
)
ert_config = ErtConfig.with_plugins().from_dict(config_dict=config_dict)
ert_config.queue_config.queue_options = ever_config.simulator.queue_system
ert_config.queue_config.queue_system = ever_config.simulator.queue_system.name
ens_config = ert_config.ensemble_config

def _get_variables(
Expand Down
42 changes: 24 additions & 18 deletions tests/everest/test_config_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import pathlib
import re
import warnings
from contextlib import ExitStack as does_not_raise
from pathlib import Path
from typing import Any, Dict, List, Union

Expand Down Expand Up @@ -141,33 +142,38 @@ def test_that_max_runtime_errors_only_on_negative():

def test_that_invalid_queue_system_errors():
with pytest.raises(ValueError) as e:
EverestConfig.with_defaults(simulator={"queue_system": "docal"})
EverestConfig.with_defaults(simulator={"queue_system": {"name": "docal"}})

assert has_error(
e.value, match="Input should be 'lsf', 'local', 'slurm' or 'torque'"
e.value, match="does not match .*'lsf', .*'local', .*'slurm', .*'torque'"
)
EverestConfig.with_defaults(simulator={"queue_system": "local"})
EverestConfig.with_defaults(simulator={"queue_system": "lsf"})
EverestConfig.with_defaults(simulator={"queue_system": "slurm"})
EverestConfig.with_defaults(simulator={"queue_system": "torque"})


@pytest.mark.parametrize(
["cores", "expected_error"], [(0, True), (-1, True), (1, False)]
["cores", "expected_error"], [(0, False), (-1, True), (1, False)]
)
def test_that_cores_errors_only_on_lt0(cores, expected_error):
if expected_error:
with pytest.raises(ValueError) as e:
EverestConfig.with_defaults(simulator={"cores": cores})
def test_that_cores_errors_only_on_lt_eq0(cores, expected_error):
expectation = (
pytest.raises(ValueError, match="greater than or equal to 0")
if expected_error
else does_not_raise()
)
with expectation:
EverestConfig.with_defaults(
simulator={"queue_system": {"name": "local", "max_running": cores}}
)

assert has_error(e.value, match=".*greater than 0")

with pytest.raises(ValueError) as e:
EverestConfig.with_defaults(simulator={"cores_per_node": cores})

assert has_error(e.value, match=".*greater than 0")
else:
EverestConfig.with_defaults(simulator={"cores": cores})
@pytest.mark.parametrize(
["cores", "expected_error"], [(0, True), (-1, True), (1, False)]
)
def test_that_cores_per_node_errors_only_on_lt0(cores, expected_error):
expectation = (
pytest.raises(ValueError, match="greater than 0")
if expected_error
else does_not_raise()
)
with expectation:
EverestConfig.with_defaults(simulator={"cores_per_node": cores})


Expand Down
14 changes: 4 additions & 10 deletions tests/everest/test_detached.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import os
import stat
from pathlib import Path
from unittest.mock import MagicMock, patch
from unittest.mock import patch

import pytest
import requests

import everest.detached
from ert.config import ErtConfig
from ert.config.queue_config import (
LocalQueueOptions,
LsfQueueOptions,
SlurmQueueOptions,
activate_script,
)
from ert.scheduler.event import FinishedEvent
from everest.config import EverestConfig
Expand Down Expand Up @@ -267,13 +265,9 @@ def test_generate_queue_options_no_config():
),
],
)
def test_generate_queue_options_use_simulator_values(queue_options, expected_result, monkeypatch):
monkeypatch.setattr(
everest.detached.ErtPluginManager,
"activate_script",
MagicMock(return_value=activate_script()),
)

def test_generate_queue_options_use_simulator_values(
queue_options, expected_result, monkeypatch
):
config = EverestConfig.with_defaults(
**{"simulator": {"queue_system": queue_options}}
)
Expand Down
17 changes: 0 additions & 17 deletions tests/everest/test_everest_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
from pathlib import Path
from typing import List

import pytest

from everest.config import EverestConfig
from everest.config.control_config import ControlConfig
from everest.config.control_variable_config import ControlVariableConfig
Expand Down Expand Up @@ -286,18 +284,3 @@ def test_that_log_level_property_is_consistent_with_environment_log_level():
config.logging_level = lvl_str
assert config.environment.log_level == lvl_str
assert config.logging_level == lvl_int


@pytest.mark.parametrize("server", ["something", "", None])
def test_deprecation_warning_for_simulator_server(server):
config_src = {"simulator": {"server": server}}

if not server:
config = EverestConfig.with_defaults(**config_src)
else:
with pytest.deprecated_call(
match="The simulator server property was deprecated"
):
config = EverestConfig.with_defaults(**config_src)

assert config.simulator.server is None
29 changes: 14 additions & 15 deletions tests/everest/test_res_initialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@
[
[
{
"queue_system": "torque",
"name": "permanent_8",
"name": "torque",
"queue_name": "permanent_8",
"qsub_cmd": "qsub",
"qstat_cmd": "qstat",
"qdel_cmd": "qdel",
"keep_qsub_output": 1,
"submit_sleep": 0.5,
"project_code": "snake_oil_pc",
"cores_per_node": 3,
"num_cpus_per_node": 3,
},
{
"project_code": "snake_oil_pc",
Expand All @@ -51,9 +51,9 @@
],
[
{
"queue_system": "slurm",
"name": "default-queue",
"max_memory": "1000M",
"name": "slurm",
"queue_name": "default-queue",
"memory": "1000M",
"exclude_host": "host1,host2,host3,host4",
"include_host": "host5,host6,host7,host8",
},
Expand All @@ -72,10 +72,9 @@
],
[
{
"queue_system": "lsf",
"name": "mr",
"options": "span = 1 && select[x86 and GNU/Linux]",
"server": "lx-fastserver01",
"name": "lsf",
"queue_name": "mr",
"lsf_resource": "span = 1 && select[x86 and GNU/Linux]",
},
{
"queue_name": "mr",
Expand All @@ -85,23 +84,23 @@
],
)
def test_everest_to_ert_queue_config(config, expected):
general_options = {"resubmit_limit": 7, "cores": 42}
general_options = {"max_running": 10}
ever_config = EverestConfig.with_defaults(
**{
"simulator": config | general_options,
"simulator": {"queue_system": config | general_options},
"model": {"realizations": [0]},
}
)
ert_config = everest_to_ert_config(ever_config)

qc = ert_config.queue_config
qo = qc.queue_options
assert qc.queue_system == config["queue_system"].upper()
assert str(qc.queue_system) == config["name"]
driver_options = qo.driver_options
driver_options.pop("activate_script")
assert {k: v for k, v in driver_options.items() if v is not None} == expected
assert qc.max_submit == general_options["resubmit_limit"] + 1
assert qo.max_running == general_options["cores"]
# assert qc.max_submit == general_options["resubmit_limit"] + 1
assert qo.max_running == general_options["max_running"]


def test_everest_to_ert_controls():
Expand Down

0 comments on commit f9d9737

Please sign in to comment.