Skip to content

Commit

Permalink
Set active realizations on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
xjules committed Nov 28, 2024
1 parent 2a8fd92 commit d86a333
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
31 changes: 14 additions & 17 deletions src/ert/config/design_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,26 +141,23 @@ def read_design_matrix(
# Read the parameter names (first row) as strings to prevent pandas from modifying them.
# This ensures that duplicate or empty column names are preserved exactly as they appear in the Excel sheet.
# By doing this, we can properly validate variable names, including detecting duplicates or missing names.
try:
param_names = (
pd.read_excel(
self.xls_filename,
sheet_name=self.design_sheet,
nrows=1,
header=None,
dtype="string",
)
.iloc[0]
.apply(lambda x: x.strip() if isinstance(x, str) else x)
)
design_matrix_df = DesignMatrix._read_excel(
param_names = (
pd.read_excel(
self.xls_filename,
self.design_sheet,
sheet_name=self.design_sheet,
nrows=1,
header=None,
skiprows=1,
dtype="string",
)
except (ValueError, AttributeError) as exc:
raise ValueError(f"Error reading design matrix: {exc}") from exc
.iloc[0]
.apply(lambda x: x.strip() if isinstance(x, str) else x)
)
design_matrix_df = DesignMatrix._read_excel(
self.xls_filename,
self.design_sheet,
header=None,
skiprows=1,
)
design_matrix_df.columns = param_names.to_list()

if "REAL" in design_matrix_df.columns:
Expand Down
2 changes: 0 additions & 2 deletions src/ert/run_models/ensemble_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ def run_experiment(
except ConfigValidationError as exc:
raise ErtRunError(str(exc)) from exc

assert design_matrix.active_realizations is not None
self.active_realizations = design_matrix.active_realizations
if not restart:
self.experiment = self._storage.create_experiment(
name=self.experiment_name,
Expand Down
17 changes: 12 additions & 5 deletions src/ert/run_models/model_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,20 @@ def _setup_ensemble_experiment(
args: Namespace,
status_queue: SimpleQueue[StatusEvents],
) -> EnsembleExperiment:
active_realizations = _realizations(args, config.model_config.num_realizations)
active_realizations = _realizations(
args, config.model_config.num_realizations
).tolist()
if (
config.analysis_config.design_matrix is not None
and config.analysis_config.design_matrix.active_realizations is not None
):
active_realizations = config.analysis_config.design_matrix.active_realizations
experiment_name = args.experiment_name
assert experiment_name is not None

return EnsembleExperiment(
random_seed=config.random_seed,
active_realizations=active_realizations.tolist(),
active_realizations=active_realizations,
ensemble_name=args.current_ensemble,
minimum_required_realizations=config.analysis_config.minimum_required_realizations,
experiment_name=experiment_name,
Expand Down Expand Up @@ -271,9 +278,9 @@ def _setup_iterative_ensemble_smoother(
random_seed=config.random_seed,
active_realizations=active_realizations.tolist(),
target_ensemble=_iterative_ensemble_format(args),
number_of_iterations=int(args.num_iterations)
if args.num_iterations is not None
else 4,
number_of_iterations=(
int(args.num_iterations) if args.num_iterations is not None else 4
),
minimum_required_realizations=config.analysis_config.minimum_required_realizations,
num_retries_per_iter=4,
experiment_name=experiment_name,
Expand Down

0 comments on commit d86a333

Please sign in to comment.