From d7a49c64a73bae52597714be6cde0e801feab549 Mon Sep 17 00:00:00 2001 From: Markus Fanebust Dregi Date: Wed, 20 Feb 2019 12:35:29 +0100 Subject: [PATCH] Expose ITER as magic string --- lib/enkf/run_arg.cpp | 3 + .../tests/res/enkf/test_runpath_list_dump.py | 81 +++++++------------ .../snake_oil_no_data/snake_oil_GEO_ID.ert | 2 +- 3 files changed, 35 insertions(+), 51 deletions(-) diff --git a/lib/enkf/run_arg.cpp b/lib/enkf/run_arg.cpp index e4f69dbd05..2ff35c4e36 100644 --- a/lib/enkf/run_arg.cpp +++ b/lib/enkf/run_arg.cpp @@ -336,6 +336,9 @@ static void run_arg_update_subst(run_arg_type * run_arg) char * iens_str = util_alloc_sprintf("%d", run_arg->iens); subst_list_prepend_owned_ref(run_arg->subst_list, "", iens_str, NULL); + char * iter_str = util_alloc_sprintf("%d", run_arg->iter); + subst_list_prepend_owned_ref(run_arg->subst_list, "", iter_str, NULL); + if (run_arg->geo_id != -1) { char * geo_id_str = util_alloc_sprintf("%d", run_arg->geo_id); subst_list_prepend_owned_ref(run_arg->subst_list, "", geo_id_str, NULL); diff --git a/python/tests/res/enkf/test_runpath_list_dump.py b/python/tests/res/enkf/test_runpath_list_dump.py index 0ff021796f..53134ad120 100644 --- a/python/tests/res/enkf/test_runpath_list_dump.py +++ b/python/tests/res/enkf/test_runpath_list_dump.py @@ -1,4 +1,5 @@ import unittest, os +import itertools from ecl.util.test import TestAreaContext from tests import ResTest @@ -10,13 +11,27 @@ from res.enkf.enums import EnKFFSType, EnkfRunType from res.util import PathFormat + +def render_dynamic_values(s, itr, iens, geo_id): + dynamic_magic_strings = { + "": geo_id, + "": itr, + "": iens, + } + for key, val in dynamic_magic_strings.items(): + s = s.replace(key, str(val)) + + return s + + class RunpathListDumpTest(ResTest): def setUp(self): self.config_rel_path = "local/snake_oil_no_data/snake_oil_GEO_ID.ert" self.config_path = self.createTestPath(self.config_rel_path) - def test_add_all(self): + + def _verify_runpath_rendering(self, itr, elementwise_runpath_creation=False): with ErtTestContext("add_all_runpath_dump", model_config=self.config_path) as ctx: res = ctx.getErt() fs_manager = res.getEnkfFsManager() @@ -26,10 +41,9 @@ def test_add_all(self): mask = BoolVector(initial_size=num_realizations, default_value=True) mask[13] = False - runpath_fmt = "simulations//realisation-%d/iter-%d" + runpath_fmt = "simulations//realisation-%d/iter-%d/magic-real-/magic-iter-" jobname_fmt = "SNAKE_OIL_%d" - itr = 0 subst_list = res.resConfig().subst_config.subst_list run_context = ErtRunContext.ensemble_experiment(sim_fs, mask, PathFormat(runpath_fmt), jobname_fmt, subst_list, itr) @@ -38,8 +52,11 @@ def test_add_all(self): for i, run_arg in enumerate(run_context): if mask[i]: run_arg.geo_id = 10*i + if elementwise_runpath_creation: + res.createRunpath(run_context, i) - res.createRunpath(run_context) + if not elementwise_runpath_creation: + res.createRunpath(run_context) for i, run_arg in enumerate(run_context): if not mask[i]: @@ -51,9 +68,9 @@ def test_add_all(self): self.assertTrue(os.path.isfile(runpath_list_path)) exp_runpaths = [ - runpath_fmt.replace("", str(run_arg.geo_id)) % (iens, itr) - for iens, run_arg in enumerate(run_context) if mask[iens] - ] + render_dynamic_values(runpath_fmt, itr, iens, run_arg.geo_id) % (iens, itr) + for iens, run_arg in enumerate(run_context) if mask[iens] + ] exp_runpaths = map(os.path.realpath, exp_runpaths) with open(runpath_list_path, 'r') as f: @@ -62,46 +79,10 @@ def test_add_all(self): self.assertEqual(list(exp_runpaths), list(dumped_runpaths)) - def test_add_one_by_one(self): - with ErtTestContext("add_one_by_one_runpath_dump", model_config=self.config_path) as ctx: - res = ctx.getErt() - fs_manager = res.getEnkfFsManager() - sim_fs = fs_manager.getFileSystem("sim_fs") - - num_realizations = 25 - mask = BoolVector(initial_size=num_realizations, default_value=True) - mask[13] = False - - runpath_fmt = "simulations//realisation-%d/iter-%d" - jobname_fmt = "SNAKE_OIL_%d" - - itr = 0 - subst_list = res.resConfig().subst_config.subst_list - run_context = ErtRunContext.ensemble_experiment(sim_fs, mask, PathFormat(runpath_fmt), jobname_fmt, subst_list, itr) - - res.initRun(run_context) - - for i, run_arg in enumerate(run_context): - if mask[i]: - run_arg.geo_id = 10*i - res.createRunpath(run_context, i) - - for i, run_arg in enumerate(run_context): - if not mask[i]: - continue - - self.assertTrue(os.path.isdir("simulations/%d" % run_arg.geo_id)) - - runpath_list_path = ".ert_runpath_list" - self.assertTrue(os.path.isfile(runpath_list_path)) - - exp_runpaths = [ - runpath_fmt.replace("", str(run_arg.geo_id)) % (iens, itr) - for iens, run_arg in enumerate(run_context) if mask[iens] - ] - exp_runpaths = map(os.path.realpath, exp_runpaths) - - with open(runpath_list_path, 'r') as f: - dumped_runpaths = list(zip(*[line.split() for line in f.readlines()]))[1] - - self.assertEqual(list(exp_runpaths), list(dumped_runpaths)) + def test_add_all(self): + test_base = itertools.product([0, 1, 2, 17], [True, False]) + for itr, elementwise_creation in test_base: + self._verify_runpath_rendering( + itr, + elementwise_runpath_creation=elementwise_creation, + ) diff --git a/test-data/local/snake_oil_no_data/snake_oil_GEO_ID.ert b/test-data/local/snake_oil_no_data/snake_oil_GEO_ID.ert index 6e160cb60e..883aa05687 100644 --- a/test-data/local/snake_oil_no_data/snake_oil_GEO_ID.ert +++ b/test-data/local/snake_oil_no_data/snake_oil_GEO_ID.ert @@ -6,7 +6,7 @@ DEFINE storage/ RANDOM_SEED 3593114179000630026631423308983283277868 -RUNPATH simulations//realisation-%d/iter-%d +RUNPATH simulations//realisation-%d/iter-%d/magic-real-/magic-iter- ENSPATH /ensemble ECLBASE SNAKE_OIL_FIELD SUMMARY *