def test_with_gen_kw(self): case_directory = self.createTestPath("local/snake_oil_no_data/") with TestAreaContext("test_enkf_runpath", store_area=True) as work_area: work_area.copy_directory(case_directory) res_config = ResConfig("snake_oil_no_data/snake_oil.ert") main = EnKFMain(res_config) iactive = BoolVector(initial_size=main.getEnsembleSize(), default_value=False) iactive[0] = True fs = main.getEnkfFsManager().getCurrentFileSystem() run_context = main.getRunContextENSEMPLE_EXPERIMENT(fs, iactive) main.createRunpath(run_context) self.assertFileExists( "snake_oil_no_data/storage/snake_oil/runpath/realisation-0/iter-0/parameters.txt" ) self.assertEqual( len(os.listdir("snake_oil_no_data/storage/snake_oil/runpath")), 1) self.assertEqual( len( os.listdir( "snake_oil_no_data/storage/snake_oil/runpath/realisation-0" )), 1, ) rp = main.create_runpath_list() self.assertEqual(len(rp), 0) rp.load() self.assertEqual(len(rp), 1)
def test_without_gen_kw(self): case_directory = self.createTestPath('local/snake_oil_no_data/') with TestAreaContext('test_enkf_runpath', store_area=True) as work_area: work_area.copy_directory(case_directory) res_config = ResConfig('snake_oil_no_data/snake_oil_no_gen_kw.ert') main = EnKFMain(res_config) iactive = BoolVector(initial_size=main.getEnsembleSize(), default_value=False) iactive[0] = True fs = main.getEnkfFsManager().getCurrentFileSystem() run_context = main.getRunContextENSEMPLE_EXPERIMENT(fs, iactive) main.createRunpath(run_context) self.assertDirectoryExists( 'storage/snake_oil_no_gen_kw/runpath/realisation-0/iter-0') self.assertFileDoesNotExist( 'storage/snake_oil_no_gen_kw/runpath/realisation-0/iter-0/parameters.txt' ) self.assertEqual( len(os.listdir('storage/snake_oil_no_gen_kw/runpath')), 1) self.assertEqual( len( os.listdir( 'storage/snake_oil_no_gen_kw/runpath/realisation-0')), 1)
def test_run_context(self): with TestAreaContext("enkf_test") as work_area: work_area.copy_directory(self.case_directory) res_config = ResConfig("simple_config/minimum_config") main = EnKFMain(res_config) fs_manager = main.getEnkfFsManager() fs = fs_manager.getCurrentFileSystem( ) iactive = BoolVector(initial_size = 10 , default_value = True) iactive[0] = False iactive[1] = False run_context = main.getRunContextENSEMPLE_EXPERIMENT( fs , iactive ) self.assertEqual( len(run_context) , 8 ) with self.assertRaises(IndexError): run_context[8] with self.assertRaises(TypeError): run_context["String"] run_arg = run_context[0] self.assertTrue( isinstance( run_arg , RunArg )) with self.assertRaises(ValueError): run_context.iensGet(0) with self.assertRaises(ValueError): run_context.iensGet(1) arg0 = run_context[0] arg2 = run_context.iensGet( 2 )
def test_run_context(self): with TestAreaContext("enkf_test") as work_area: work_area.copy_directory(self.case_directory) res_config = ResConfig("simple_config/minimum_config") main = EnKFMain(res_config) fs_manager = main.getEnkfFsManager() fs = fs_manager.getCurrentFileSystem() iactive = BoolVector(initial_size=10, default_value=True) iactive[0] = False iactive[1] = False run_context = main.getRunContextENSEMPLE_EXPERIMENT(fs, iactive) self.assertEqual(len(run_context), 10) with self.assertRaises(IndexError): run_context[10] with self.assertRaises(TypeError): run_context["String"] self.assertIsNone(run_context[0]) run_arg = run_context[2] self.assertTrue(isinstance(run_arg, RunArg)) rng1 = main.rng() rng1.setState("ABCDEFGHIJ012345") d1 = rng1.getDouble() rng1.setState("ABCDEFGHIJ012345") rng2 = main.rng() d2 = rng2.getDouble() self.assertEqual(d1, d2)
def test_config( self ): with TestAreaContext("enkf_test") as work_area: work_area.copy_directory(self.case_directory) res_config = ResConfig("simple_config/minimum_config") main = EnKFMain(res_config) self.assertIsInstance(main.ensembleConfig(), EnsembleConfig) self.assertIsInstance(main.analysisConfig(), AnalysisConfig) self.assertIsInstance(main.getModelConfig(), ModelConfig) #self.assertIsInstance(main.local_config(), LocalConfig) #warn: Should this be None? self.assertIsInstance(main.siteConfig(), SiteConfig) self.assertIsInstance(main.eclConfig(), EclConfig) self.assertIsInstance(main.plotConfig(), PlotSettings) # self.main.load_obs(obs_config_file) self.assertIsInstance(main.getObservations(), EnkfObs) self.assertIsInstance(main.get_templates(), ErtTemplates) self.assertIsInstance(main.getEnkfFsManager().getCurrentFileSystem(), EnkfFs) # self.assertIsInstance(main.iget_member_config(0), MemberConfig) self.assertIsInstance(main.getMemberRunningState(0), EnKFState) self.assertEqual( "Ensemble" , main.getMountPoint()) main.free()
def test_with_enkf_fs(self): config_file = self.createTestPath("Statoil/config/with_data/config") with TestAreaContext("enkf/summary_key_set/enkf_fs", store_area=True) as context: context.copy_parent_content(config_file) fs = EnkfFs("storage/default") summary_key_set = fs.getSummaryKeySet() summary_key_set.addSummaryKey("FOPT") summary_key_set.addSummaryKey("WWCT") summary_key_set.addSummaryKey("WOPR") fs.umount() ert = EnKFMain("config") fs = ert.getEnkfFsManager().getCurrentFileSystem() summary_key_set = fs.getSummaryKeySet() self.assertTrue("FOPT" in summary_key_set) self.assertTrue("WWCT" in summary_key_set) self.assertTrue("WOPR" in summary_key_set) ensemble_config = ert.ensembleConfig() self.assertTrue("FOPT" in ensemble_config) self.assertTrue("WWCT" in ensemble_config) self.assertTrue("WOPR" in ensemble_config) self.assertFalse("TCPU" in ensemble_config)
def test_with_gen_kw(copy_case): copy_case("local/snake_oil") shutil.rmtree("storage") res_config = ResConfig("snake_oil.ert") main = EnKFMain(res_config) fs = main.getEnkfFsManager().getCurrentFileSystem() run_context = main.getRunContextENSEMPLE_EXPERIMENT(fs, [True]) main.createRunpath(run_context) assert os.path.exists("storage/snake_oil/" "runpath/realization-0/iter-0/parameters.txt") assert len(os.listdir("storage/snake_oil/runpath")) == 1 assert len(os.listdir("storage/snake_oil/runpath/realization-0")) == 1 rp = main.create_runpath_list() assert len(rp) == 0 rp.load() assert len(rp), 1
def test_ecl_config_creation(self): with TestAreaContext("enkf_library_test") as work_area: work_area.copy_directory(self.case_directory) main = EnKFMain("simple_config/minimum_config") self.assertIsInstance(main.analysisConfig(), AnalysisConfig) self.assertIsInstance(main.eclConfig(), EclConfig) with self.assertRaises(AssertionError): # Null pointer! self.assertIsInstance(main.eclConfig().getRefcase(), EclSum) file_system = main.getEnkfFsManager().getCurrentFileSystem() self.assertEqual(file_system.getCaseName(), "default") time_map = file_system.getTimeMap() self.assertIsInstance(time_map, TimeMap) main.free()
def test_run_context_from_external_folder(self): with TestAreaContext('enkf_test') as work_area: work_area.copy_directory(self.case_directory_custom_kw) res_config = ResConfig('snake_oil/snake_oil.ert') main = EnKFMain(res_config) fs_manager = main.getEnkfFsManager() fs = fs_manager.getCurrentFileSystem( ) mask = BoolVector(default_value = False , initial_size = 10) mask[0] = True run_context = main.getRunContextENSEMPLE_EXPERIMENT( fs , mask ) self.assertEqual( len(run_context) , 1 ) job_queue = main.get_queue_config().create_job_queue() main.getEnkfSimulationRunner().createRunPath( run_context ) num = main.getEnkfSimulationRunner().runEnsembleExperiment(job_queue, run_context) self.assertEqual( num , 1 )
def test_config( self ): with TestAreaContext("enkf_test") as work_area: work_area.copy_directory(self.case_directory) res_config = ResConfig("simple_config/minimum_config") main = EnKFMain(res_config) self.assertIsInstance(main.ensembleConfig(), EnsembleConfig) self.assertIsInstance(main.analysisConfig(), AnalysisConfig) self.assertIsInstance(main.getModelConfig(), ModelConfig) self.assertIsInstance(main.siteConfig(), SiteConfig) self.assertIsInstance(main.eclConfig(), EclConfig) self.assertIsInstance(main.getObservations(), EnkfObs) self.assertIsInstance(main.get_templates(), ErtTemplates) self.assertIsInstance(main.getEnkfFsManager().getCurrentFileSystem(), EnkfFs) self.assertIsInstance(main.getMemberRunningState(0), EnKFState) self.assertEqual( "simple_config/Ensemble" , main.getMountPoint())
def test_without_gen_kw(copy_case): copy_case("local/snake_oil") with fileinput.input("snake_oil.ert", inplace=True) as fin: for line in fin: if line.startswith("GEN_KW"): continue print(line, end="") shutil.rmtree("storage") assert "GEN_KW" not in Path("snake_oil.ert").read_text("utf-8") res_config = ResConfig("snake_oil.ert") main = EnKFMain(res_config) fs = main.getEnkfFsManager().getCurrentFileSystem() run_context = main.getRunContextENSEMPLE_EXPERIMENT(fs, [True]) main.createRunpath(run_context) assert os.path.exists("storage/snake_oil/runpath/realization-0/iter-0") assert not os.path.exists( "storage/snake_oil/runpath/realization-0/iter-0/parameters.txt") assert len(os.listdir("storage/snake_oil/runpath")) == 1 assert len(os.listdir("storage/snake_oil/runpath/realization-0")) == 1
def _create_runpath(enkf_main: EnKFMain) -> ErtRunContext: """ Instantiate an ERT runpath. This will create the parameter coefficients. """ result_fs = enkf_main.getEnkfFsManager().getCurrentFileSystem() model_config = enkf_main.getModelConfig() runpath_fmt = model_config.getRunpathFormat() jobname_fmt = model_config.getJobnameFormat() subst_list = enkf_main.getDataKW() run_context = ErtRunContext.ensemble_smoother( result_fs, None, BoolVector(default_value=True, initial_size=1), runpath_fmt, jobname_fmt, subst_list, 0, ) enkf_main.getEnkfSimulationRunner().createRunPath(run_context) return run_context
def test_run_context_from_external_folder(self): with TestAreaContext("enkf_test") as work_area: work_area.copy_directory(self.case_directory_snake_oil) res_config = ResConfig("snake_oil/snake_oil.ert") main = EnKFMain(res_config) fs_manager = main.getEnkfFsManager() fs = fs_manager.getCurrentFileSystem() mask = [False] * 10 mask[0] = True run_context = main.getRunContextENSEMPLE_EXPERIMENT(fs, mask) self.assertEqual(len(run_context), 10) job_queue = main.get_queue_config().create_job_queue() main.getEnkfSimulationRunner().createRunPath(run_context) num = main.getEnkfSimulationRunner().runEnsembleExperiment( job_queue, run_context) self.assertTrue( os.path.isdir( "snake_oil/storage/snake_oil/runpath/realization-0/iter-0") ) self.assertEqual(num, 1)