Skip to content

Commit

Permalink
Move DesignMatrixArgs into seperate file and rename to DesignMatrix
Browse files Browse the repository at this point in the history
  • Loading branch information
larsevj committed Sep 30, 2024
1 parent c865950 commit 138faf4
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 47 deletions.
50 changes: 3 additions & 47 deletions src/ert/config/analysis_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,19 @@
from pydantic import ValidationError

from .analysis_module import ESSettings, IESSettings
from .design_matrix import DesignMatrix
from .parsing import (
AnalysisMode,
ConfigDict,
ConfigKeys,
ConfigValidationError,
ConfigWarning,
ErrorInfo,
)

logger = logging.getLogger(__name__)

DEFAULT_ANALYSIS_MODE = AnalysisMode.ENSEMBLE_SMOOTHER
ObservationGroups = List[str]
from ._option_dict import option_dict


@dataclass
Expand All @@ -33,47 +32,6 @@ class UpdateSettings:
auto_scale_observations: List[ObservationGroups] = field(default_factory=list)


@dataclass
class DesignMatrixArgs:
xls_filename: Path
designsheet: str
defaultsheet: str

@classmethod
def from_config_list(cls, config_list: List[str]) -> "DesignMatrixArgs":
filename = Path(config_list[0])
options = option_dict(config_list, 1)
design_sheet = options.get("DESIGN_SHEET")
default_sheet = options.get("DEFAULT_SHEET")
errors = []
if filename.suffix not in {
".xlsx",
".xls",
}:
errors.append(
ErrorInfo(
f"DESIGN_MATRIX must be of format .xls or .xslx; is {filename}"
).set_context(config_list)
)
if design_sheet is None:
errors.append(
ErrorInfo("Missing required DESIGN_SHEET").set_context(config_list)
)
if default_sheet is None:
errors.append(
ErrorInfo("Missing required DEFAULT_SHEET").set_context(config_list)
)
if errors:
raise ConfigValidationError.from_collected(errors)
assert design_sheet is not None
assert default_sheet is not None
return cls(
xls_filename=filename,
designsheet=design_sheet,
defaultsheet=default_sheet,
)


@dataclass
class AnalysisConfig:
max_runtime: Optional[int] = None
Expand All @@ -83,7 +41,7 @@ class AnalysisConfig:
ies_module: IESSettings = field(default_factory=IESSettings)
observation_settings: UpdateSettings = field(default_factory=UpdateSettings)
num_iterations: int = 1
design_matrix_args: Optional[DesignMatrixArgs] = None
design_matrix_args: Optional[DesignMatrix] = None

@no_type_check
@classmethod
Expand Down Expand Up @@ -236,9 +194,7 @@ def from_dict(cls, config_dict: ConfigDict) -> "AnalysisConfig":
observation_settings=obs_settings,
es_module=es_settings,
ies_module=ies_settings,
design_matrix_args=DesignMatrixArgs.from_config_list(
design_matrix_config_list
)
design_matrix_args=DesignMatrix.from_config_list(design_matrix_config_list)
if design_matrix_config_list is not None
else None,
)
Expand Down
52 changes: 52 additions & 0 deletions src/ert/config/design_matrix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from __future__ import annotations

from dataclasses import dataclass
from pathlib import Path
from typing import List

from ._option_dict import option_dict
from .parsing import (
ConfigValidationError,
ErrorInfo,
)


@dataclass
class DesignMatrix:
xls_filename: Path
designsheet: str
defaultsheet: str

@classmethod
def from_config_list(cls, config_list: List[str]) -> "DesignMatrix":
filename = Path(config_list[0])
options = option_dict(config_list, 1)
design_sheet = options.get("DESIGN_SHEET")
default_sheet = options.get("DEFAULT_SHEET")
errors = []
if filename.suffix not in {
".xlsx",
".xls",
}:
errors.append(
ErrorInfo(
f"DESIGN_MATRIX must be of format .xls or .xslx; is {filename}"
).set_context(config_list)
)
if design_sheet is None:
errors.append(
ErrorInfo("Missing required DESIGN_SHEET").set_context(config_list)
)
if default_sheet is None:
errors.append(
ErrorInfo("Missing required DEFAULT_SHEET").set_context(config_list)
)
if errors:
raise ConfigValidationError.from_collected(errors)
assert design_sheet is not None
assert default_sheet is not None
return cls(
xls_filename=filename,
designsheet=design_sheet,
defaultsheet=default_sheet,
)

0 comments on commit 138faf4

Please sign in to comment.