diff --git a/src/ert/analysis/_es_update.py b/src/ert/analysis/_es_update.py index 667213e2b42..f70b2c3ab75 100644 --- a/src/ert/analysis/_es_update.py +++ b/src/ert/analysis/_es_update.py @@ -3,6 +3,7 @@ import functools import logging import time +import warnings from collections.abc import Callable, Iterable, Sequence from fnmatch import fnmatch from typing import ( @@ -16,6 +17,7 @@ import numpy as np import polars import psutil +import scipy from iterative_ensemble_smoother.experimental import AdaptiveESMDA from ert.config import GenKwConfig @@ -515,7 +517,37 @@ def adaptive_localization_progress_callback( else: # Compute transition matrix so that # X_posterior = X_prior @ T - T = smoother_es.compute_transition_matrix(Y=S, alpha=1.0, truncation=truncation) + try: + with warnings.catch_warnings( + record=True, category=scipy.linalg.LinAlgWarning + ) as all_warnings: + T = smoother_es.compute_transition_matrix( + Y=S, alpha=1.0, truncation=truncation + ) + if all_warnings: + progress_callback( + AnalysisStatusEvent( + msg="Warning encountered while computing transition matrix in update" + f"Results may be unreliable: {all_warnings}", + ) + ) + + except scipy.linalg.LinAlgError as err: + msg = ( + "Failed while computing transition matrix, " + f"this might be due to outlier values in one or more realizations: {err}" + ) + progress_callback( + AnalysisErrorEvent( + error_msg=msg, + data=DataSection( + header=smoother_snapshot.header, + data=smoother_snapshot.csv, + extra=smoother_snapshot.extra, + ), + ) + ) + raise ErtAnalysisError(msg) from err # Add identity in place for fast computation np.fill_diagonal(T, T.diagonal() + 1) diff --git a/src/ert/run_models/base_run_model.py b/src/ert/run_models/base_run_model.py index bd6392647de..22036bc18bc 100644 --- a/src/ert/run_models/base_run_model.py +++ b/src/ert/run_models/base_run_model.py @@ -801,7 +801,7 @@ def update( except ErtAnalysisError as e: raise ErtRunError( "Update algorithm failed for iteration:" - f"{posterior.iteration}. The following error occurred {e}" + f"{posterior.iteration}. The following error occurred: {e}" ) from e self.run_workflows(HookRuntime.POST_UPDATE, self._storage, prior) return posterior