From f8174af96653470d599da2ed73b4e033255780f1 Mon Sep 17 00:00:00 2001 From: xjules Date: Thu, 26 Oct 2023 14:21:28 +0200 Subject: [PATCH] Unify all driver options validation --- src/ert/config/queue_config.py | 91 ++++++++++++---------------------- 1 file changed, 31 insertions(+), 60 deletions(-) diff --git a/src/ert/config/queue_config.py b/src/ert/config/queue_config.py index a86a1c8f92d..a9db8643187 100644 --- a/src/ert/config/queue_config.py +++ b/src/ert/config/queue_config.py @@ -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: @@ -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 @@ -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", @@ -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", @@ -178,7 +144,7 @@ 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", @@ -186,43 +152,48 @@ def generate_dict(option_list: List[Tuple[str, str]]) -> Dict[str, List[str]]: "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]