Skip to content

Commit

Permalink
Add testing and remove iteration none warning
Browse files Browse the repository at this point in the history
  • Loading branch information
DanSava committed Sep 16, 2024
1 parent 1d534d1 commit 949265d
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 6 deletions.
6 changes: 0 additions & 6 deletions src/ert/libres_facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,6 @@ def load_from_forward_model(
realisations: npt.NDArray[np.bool_],
iteration: Optional[int] = None,
) -> int:
if iteration is not None:
warnings.warn(
"The iteration argument has no effect, iteration is read from ensemble",
DeprecationWarning,
stacklevel=1,
)
t = time.perf_counter()
run_args = create_run_arguments(
Runpaths(
Expand Down
52 changes: 52 additions & 0 deletions tests/unit_tests/test_load_forward_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from ert.config import ErtConfig
from ert.enkf_main import create_run_path
from ert.libres_facade import LibresFacade
from ert.run_arg import create_run_arguments
from ert.storage import open_storage


Expand Down Expand Up @@ -281,3 +282,54 @@ def test_that_the_states_are_set_correctly():
facade.load_from_forward_model(new_ensemble, realizations, 0)
assert not new_ensemble.is_initalized()
assert new_ensemble.has_data()


@pytest.mark.parametrize("iter", [None, 0, 1, 2, 3])
@pytest.mark.usefixtures("use_tmpdir")
def test_loading_from_any_available_iter(storage, run_paths, run_args, iter):
config_text = dedent(
"""
NUM_REALIZATIONS 1
GEN_DATA RESPONSE RESULT_FILE:response.out INPUT_FORMAT:ASCII
"""
)
Path("config.ert").write_text(config_text, encoding="utf-8")

ert_config = ErtConfig.from_file("config.ert")
prior_ensemble = storage.create_ensemble(
storage.create_experiment(
responses=ert_config.ensemble_config.response_configuration
),
name="prior",
ensemble_size=ert_config.model_config.num_realizations,
iteration=iter if iter is not None else 0,
)

run_args = create_run_arguments(
run_paths(ert_config),
[True] * ert_config.model_config.num_realizations,
prior_ensemble,
iter,
)
create_run_path(
run_args,
prior_ensemble,
ert_config,
run_paths(ert_config),
)
run_path = Path(
f"simulations/realization-0/iter-{iter if iter is not None else 0}/"
)
with open(run_path / "response.out", "w", encoding="utf-8") as fout:
fout.write("\n".join(["1", "2", "3"]))
with open(run_path / "response.out_active", "w", encoding="utf-8") as fout:
fout.write("\n".join(["1", "0", "1"]))

facade = LibresFacade.from_config_file("config.ert")
facade.load_from_forward_model(prior_ensemble, [True], iter)
assert list(
prior_ensemble.load_responses("RESPONSE", (0,))
.to_dataframe()
.dropna()
.values.flatten()
) == [1.0, 3.0]

0 comments on commit 949265d

Please sign in to comment.