Skip to content

Commit

Permalink
Create backup for jobs.json when running in existing runpath
Browse files Browse the repository at this point in the history
  • Loading branch information
kvashchuka committed Sep 28, 2023
1 parent b577c65 commit e89768d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/ert/enkf_main.py
Expand Up @@ -368,6 +368,8 @@ def createRunPath(self, run_context: RunContext) -> None:
run_context.iteration,
)

path = run_path / "jobs.json"
_backup_if_existing(path)
with open(run_path / "jobs.json", mode="w", encoding="utf-8") as fptr:
forward_model_output = ert_config.forward_model_data_to_json(
run_arg.run_id,
Expand Down
20 changes: 20 additions & 0 deletions tests/unit_tests/test_enkf_runpath.py
Expand Up @@ -47,3 +47,23 @@ def test_without_gen_kw(prior_ensemble):
)
assert len(os.listdir("storage/snake_oil/runpath")) == 1
assert len(os.listdir("storage/snake_oil/runpath/realization-0")) == 1


def test_jobs_file_is_backed_up(copy_case, storage):
copy_case("snake_oil")
ert_config = ErtConfig.from_file("snake_oil.ert")
main = EnKFMain(ert_config)
experiment_id = storage.create_experiment(
parameters=ert_config.ensemble_config.parameter_configuration
)
prior_ensemble = storage.create_ensemble(
experiment_id, name="prior", ensemble_size=5
)
prior = main.ensemble_context(prior_ensemble, [True], 0)
main.sample_prior(prior.sim_fs, prior.active_realizations)
main.createRunPath(prior)
assert os.path.exists("storage/snake_oil/runpath/realization-0/iter-0/jobs.json")
main.createRunPath(prior)
iter0_output_files = os.listdir("storage/snake_oil/runpath/realization-0/iter-0/")
jobs_files = [f for f in iter0_output_files if f.startswith("jobs.json")]
assert len(jobs_files) > 1, "No backup created for jobs.json"

0 comments on commit e89768d

Please sign in to comment.