Skip to content

Commit

Permalink
Dont use get_ensemble_by_name from LocalStorage
Browse files Browse the repository at this point in the history
Co-authored by: larsevj <levje@equinor.com>

erts api has been updated such that get_ensemble_by_name
is only available via LocalExperiment.
  • Loading branch information
dafeda authored and oyvindeide committed Sep 6, 2024
1 parent dec6b73 commit adc6f9a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ classifiers = [
dynamic = ["version"]
dependencies = [
"resdata",
"ert>=10.2.0b13",
"ert>=11.0.0-b0",
"importlib_metadata",
"importlib_resources",
"numpy",
Expand Down
19 changes: 13 additions & 6 deletions src/semeio/workflows/ahm_analysis/ahmanalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,24 @@ def run(
prior_name,
target_name,
)

prior_ensemble = None
# Get the prior scalar parameter distributions
ensemble = self.storage.get_ensemble_by_name(prior_name)
prior_data = ensemble.load_all_gen_kw_data()
for experiment in self.storage.experiments:
try:
prior_ensemble = experiment.get_ensemble_by_name(prior_name)
break
except KeyError:
pass

if prior_ensemble is None:
raise KeyError(f"No ensembles named {prior_name} found in storage.")
prior_data = prior_ensemble.load_all_gen_kw_data()
try:
raise_if_empty(
dataframes=[
prior_data,
self.facade.load_all_misfit_data(
self.storage.get_ensemble_by_name(prior_name)
),
self.facade.load_all_misfit_data(prior_ensemble),
],
messages=[
"Empty prior ensemble",
Expand Down Expand Up @@ -177,7 +185,6 @@ def run(
"tmp_storage", "w"
) as storage:
try:
prior_ensemble = self.storage.get_ensemble_by_name(prior_name)
prev_experiment = prior_ensemble.experiment
experiment = storage.create_experiment(
parameters=prev_experiment.parameter_configuration.values(),
Expand Down
3 changes: 2 additions & 1 deletion tests/workflows/ahm_analysis/test_ahm_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ def test_make_update_log_df(snake_oil_facade, snapshot):
snapshots are correct, they are just documenting the current behavior.
"""
with open_storage(snake_oil_facade.enspath, "w") as storage:
prior_ens = storage.get_ensemble_by_name("default")
experiment = storage.get_experiment_by_name("ensemble-experiment")
prior_ens = experiment.get_ensemble_by_name("default")
posterior_ens = storage.create_ensemble(
prior_ens.experiment_id,
ensemble_size=prior_ens.ensemble_size,
Expand Down
6 changes: 4 additions & 2 deletions tests/workflows/ahm_analysis/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
def test_ahmanalysis_run(snake_oil_facade):
"""test data_set with only scalar parameters"""
with open_storage(snake_oil_facade.enspath, "w") as storage:
experiment = storage.get_experiment_by_name("ensemble-experiment")
snake_oil_facade.run_ertscript(
ahmanalysis.AhmAnalysisJob,
storage,
storage.get_ensemble_by_name("default"),
experiment.get_ensemble_by_name("default"),
)

# assert that this returns/generates a KS csv file
Expand Down Expand Up @@ -70,10 +71,11 @@ def test_ahmanalysis_run_deactivated_obs(snake_oil_facade, snapshot, caplog):
with open_storage(snake_oil_facade.enspath, "w") as storage, caplog.at_level(
logging.WARNING
):
experiment = storage.get_experiment_by_name("ensemble-experiment")
snake_oil_facade.run_ertscript(
ahmanalysis.AhmAnalysisJob,
storage,
storage.get_ensemble_by_name("default"),
experiment.get_ensemble_by_name("default"),
)
assert "Analysis failed for" in caplog.text

Expand Down

0 comments on commit adc6f9a

Please sign in to comment.