Skip to content

Commit

Permalink
Unify all driver options validation
Browse files Browse the repository at this point in the history
  • Loading branch information
xjules committed Oct 26, 2023
1 parent 59e48f2 commit f8174af
Showing 1 changed file with 31 additions and 60 deletions.
91 changes: 31 additions & 60 deletions src/ert/config/queue_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,32 +31,6 @@ class QueueConfig:
default_factory=dict
)

def __post_init__(self) -> None:
errors = []
for _, value in [
setting
for settings in self.queue_options.values()
for setting in settings
if setting[0] == "MAX_RUNNING" and setting[1]
]:
err_msg = "QUEUE_OPTION MAX_RUNNING is"
try:
int_val = int(value)
if int_val < 0:
errors.append(
ErrorInfo(f"{err_msg} negative: {str(value)!r}").set_context(
value
)
)
except ValueError:
errors.append(
ErrorInfo(f"{err_msg} not an integer: {str(value)!r}").set_context(
value
)
)
if errors:
raise ConfigValidationError.from_collected(errors)

@no_type_check
@classmethod
def from_dict(cls, config_dict: ConfigDict) -> QueueConfig:
Expand Down Expand Up @@ -95,20 +69,11 @@ def from_dict(cls, config_dict: ConfigDict) -> QueueConfig:
" usually provided by the site-configuration file, beware that"
" you are effectively replacing the default value provided."
)
if (
selected_queue_system == QueueSystem.TORQUE
and queue_options[QueueSystem.TORQUE]
):
_validate_queue_options(queue_options[QueueSystem.TORQUE], "TORQUE")

if selected_queue_system == QueueSystem.LSF and queue_options[QueueSystem.LSF]:
_validate_queue_options(queue_options[QueueSystem.LSF], "LSF")

if (
selected_queue_system == QueueSystem.SLURM
and queue_options[QueueSystem.SLURM]
):
_validate_queue_options(queue_options[QueueSystem.SLURM], "SLURM")
if queue_options[selected_queue_system]:
_validate_queue_options(
queue_options[selected_queue_system], selected_queue_system
)

if (
selected_queue_system != QueueSystem.LOCAL
Expand Down Expand Up @@ -148,14 +113,15 @@ def generate_dict(option_list: List[Tuple[str, str]]) -> Dict[str, List[str]]:
)


memory_options: Mapping[str, List[str]] = {
"LSF": [],
"SLURM": [],
"TORQUE": ["MEMORY_PER_JOB"],
memory_options: Mapping[QueueSystem, List[str]] = {
QueueSystem.LSF: [],
QueueSystem.SLURM: [],
QueueSystem.TORQUE: ["MEMORY_PER_JOB"],
QueueSystem.LOCAL: [],
}

string_options: Mapping[str, List[str]] = {
"LSF": [
string_options: Mapping[QueueSystem, List[str]] = {
QueueSystem.LSF: [
"DEBUG_OUTPUT",
"LSF_RESOURCE",
"LSF_SERVER",
Expand All @@ -169,7 +135,7 @@ def generate_dict(option_list: List[Tuple[str, str]]) -> Dict[str, List[str]]:
"EXCLUDE_HOST",
"PROJECT_CODE",
],
"SLURM": [
QueueSystem.SLURM: [
"SBATCH",
"SCANCEL",
"SCONTROL",
Expand All @@ -178,51 +144,56 @@ def generate_dict(option_list: List[Tuple[str, str]]) -> Dict[str, List[str]]:
"INCLUDE_HOST",
"EXCLUDE_HOST",
],
"TORQUE": [
QueueSystem.TORQUE: [
"QSUB_CMD",
"QSTAT_CMD",
"QDEL_CMD",
"QSTAT_OPTIONS",
"QUEUE",
"DEBUG_OUTPUT",
],
QueueSystem.LOCAL: [],
}

positive_int_options: Mapping[str, List[str]] = {
"LSF": [
positive_int_options: Mapping[QueueSystem, List[str]] = {
QueueSystem.LSF: [
"BJOBS_TIMEOUT",
"MAX_RUNNING",
],
"SLURM": [
QueueSystem.SLURM: [
"MEMORY",
"MEMORY_PER_CPU",
"MAX_RUNNING",
],
"TORQUE": [
QueueSystem.TORQUE: [
"NUM_NODES",
"NUM_CPUS_PER_NODE",
"MAX_RUNNING",
],
QueueSystem.LOCAL: ["MAX_RUNNING"],
}

float_options: Mapping[str, List[str]] = {
"LSF": [
float_options: Mapping[QueueSystem, List[str]] = {
QueueSystem.LSF: [
"SUBMIT_SLEEP",
],
"SLURM": [
QueueSystem.SLURM: [
"SQUEUE_TIMEOUT",
],
"TORQUE": ["SUBMIT_SLEEP", "QUEUE_QUERY_TIMEOUT"],
QueueSystem.TORQUE: ["SUBMIT_SLEEP", "QUEUE_QUERY_TIMEOUT"],
QueueSystem.LOCAL: [],
}

bool_options: Mapping[str, List[str]] = {
"LSF": ["DEBUG_OUTPUT"],
"SLURM": [],
"TORQUE": [],
bool_options: Mapping[QueueSystem, List[str]] = {
QueueSystem.LSF: ["DEBUG_OUTPUT"],
QueueSystem.SLURM: [],
QueueSystem.TORQUE: [],
QueueSystem.LOCAL: [],
}


def _validate_queue_options(
queue_options: List[Tuple[str, str]], queue_type: str
queue_options: List[Tuple[str, str]], queue_type: QueueSystem
) -> None:
for option_strings in queue_options:
option_name = option_strings[0]
Expand Down

0 comments on commit f8174af

Please sign in to comment.