Skip to content

Commit

Permalink
Fix bug where queue settings were not taken from site config
Browse files Browse the repository at this point in the history
  • Loading branch information
oyvindeide committed Jan 16, 2025
1 parent 3a094f7 commit 3635c08
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 8 deletions.
13 changes: 10 additions & 3 deletions src/everest/config/everest_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
field_validator,
model_validator,
)
from pydantic_core.core_schema import ValidationInfo
from ruamel.yaml import YAML, YAMLError

from ert.config import ErtConfig
from ert.config import ErtConfig, QueueConfig
from ert.config.parsing import BaseModelWithContextSupport
from ert.config.parsing.base_model_context import init_context
from ert.plugins import ErtPluginManager
Expand Down Expand Up @@ -274,7 +275,7 @@ def validate_queue_system(self) -> Self: # pylint: disable=E0213
return self

@model_validator(mode="after")
def validate_forward_model_job_name_installed(self) -> Self: # pylint: disable=E0213
def validate_forward_model_job_name_installed(self, info: ValidationInfo) -> Self: # pylint: disable=E0213
install_jobs = self.install_jobs
forward_model_jobs = self.forward_model
if install_jobs is None:
Expand Down Expand Up @@ -816,7 +817,13 @@ def load_file(config_file: str) -> "EverestConfig":

@classmethod
def with_plugins(cls, config_dict):
with init_context({"activate_script": ErtPluginManager().activate_script()}):
site_config = ErtConfig.read_site_config()
queue_config = QueueConfig.from_dict(site_config)
context = {
"activate_script": ErtPluginManager().activate_script(),
"queue_system": queue_config.queue_options,
}
with init_context(context):
return EverestConfig(**config_dict)

@staticmethod
Expand Down
9 changes: 6 additions & 3 deletions src/everest/config/simulator_config.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
from typing import Any

from pydantic import (
BaseModel,
Field,
NonNegativeInt,
PositiveInt,
field_validator,
model_validator,
)
from pydantic_core.core_schema import ValidationInfo

from ert.config.parsing import BaseModelWithContextSupport
from ert.config.queue_config import (
LocalQueueOptions,
LsfQueueOptions,
Expand All @@ -32,7 +33,7 @@ def check_removed_config(queue_system):
)


class SimulatorConfig(BaseModel, extra="forbid"): # type: ignore
class SimulatorConfig(BaseModelWithContextSupport, extra="forbid"): # type: ignore
cores_per_node: PositiveInt | None = Field(
default=None,
description="""defines the number of CPUs when running
Expand Down Expand Up @@ -93,8 +94,10 @@ class SimulatorConfig(BaseModel, extra="forbid"): # type: ignore

@field_validator("queue_system", mode="before")
@classmethod
def default_local_queue(cls, v):
def default_local_queue(cls, v, info: ValidationInfo):
if v is None:
if info.context:
return info.context[info.field_name]
return LocalQueueOptions(max_running=8)
return v

Expand Down
31 changes: 29 additions & 2 deletions tests/everest/test_detached.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import requests

import everest
from ert.config import ErtConfig
from ert.config import ErtConfig, QueueSystem
from ert.config.queue_config import (
LocalQueueOptions,
LsfQueueOptions,
Expand Down Expand Up @@ -322,7 +322,34 @@ def test_queue_options_site_config(queue_options, use_plugin, monkeypatch, min_c
config = EverestConfig.with_plugins(
{"simulator": {"queue_system": queue_options}} | min_config
)
assert config.server.queue_system.activate_script == expected_result
assert config.simulator.queue_system.activate_script == expected_result


@pytest.mark.parametrize("use_plugin", (True, False))
@pytest.mark.parametrize(
"queue_options",
[
{"queue_system": {"name": "slurm"}},
{},
],
)
def test_simulator_queue_system_site_config(
queue_options, use_plugin, monkeypatch, min_config
):
if queue_options:
expected_result = SlurmQueueOptions # User specified
elif use_plugin:
expected_result = LsfQueueOptions # Mock site config
else:
expected_result = LocalQueueOptions # Default value
if use_plugin:
monkeypatch.setattr(
everest.config.everest_config.ErtConfig,
"read_site_config",
MagicMock(return_value={"QUEUE_SYSTEM": QueueSystem.LSF}),
)
config = EverestConfig.with_plugins({"simulator": queue_options} | min_config)
assert isinstance(config.simulator.queue_system, expected_result)


@pytest.mark.timeout(5) # Simulation might not finish
Expand Down

0 comments on commit 3635c08

Please sign in to comment.