def test_simulation_model(self): with TestAreaContext('enkf_test_sim_model_kw') as work_area: base_path = os.getcwd() source_path = self.createTestPath('local/simulation_model') work_area.copy_directory(source_path) dir_ert = os.path.join(base_path, 'simulation_model') assert (os.path.isdir(dir_ert)) file_ert = os.path.join(dir_ert, 'sim_kw.ert') assert (os.path.isfile(file_ert)) with ErtTestContext("sim_kw", model_config=file_ert, store_area=True) as ctx: ert = ctx.getErt() fs_manager = ert.getEnkfFsManager() result_fs = fs_manager.getCurrentFileSystem() model_config = ert.getModelConfig() forward_model = model_config.getForwardModel() self.assertEqual(forward_model.get_size(), 4) self.assertEqual( forward_model.iget_job(3).get_arglist(), ['WORD_A']) self.assertEqual( forward_model.iget_job(0).get_arglist(), ['<ARGUMENT>']) self.assertEqual( forward_model.iget_job(1).get_arglist(), ['Hello', 'True', '3.14', '4']) self.assertEqual( forward_model.iget_job(2).get_arglist(), ['word', '<ECLBASE>']) runpath_fmt = model_config.getRunpathFormat() jobname_fmt = model_config.getJobnameFormat() subst_list = ert.getDataKW() itr = 0 mask = BoolVector(default_value=True, initial_size=1) run_context = ErtRunContext.ensemble_experiment( result_fs, mask, runpath_fmt, jobname_fmt, subst_list, itr) ert.getEnkfSimulationRunner().createRunPath(run_context) queue_config = ert.get_queue_config() self.assertEqual(queue_config.num_cpu, 5) os.chdir('storage/sim_kw/runpath/realisation-0/iter-0') assert (os.path.isfile('jobs.json')) with open("jobs.json", "r") as f: data = json.load(f) jobList = data["jobList"] old_job_A = jobList[3] self.assertEqual(old_job_A["argList"], ['WORD_A']) old_job_B = jobList[0] self.assertEqual(old_job_B["argList"], ['yy']) new_job_A = jobList[1] self.assertEqual(new_job_A["argList"], ['Hello', 'True', '3.14', '4']) new_job_B = jobList[2] self.assertEqual(new_job_B["argList"], ['word', 'SIM_KW'])
def test_transfer_var(self): with TestAreaContext('enkf_test_transfer_env') as work_area: base_path = os.getcwd() source_path = self.createTestPath('local/snake_oil_no_data') work_area.copy_directory(source_path) dir_ert = os.path.join(base_path, 'snake_oil_no_data') assert (os.path.isdir(dir_ert)) file_ert = os.path.join(dir_ert, 'snake_oil.ert') assert (os.path.isfile(file_ert)) with ErtTestContext("transfer_env_var", model_config=file_ert, store_area=True) as ctx: ert = ctx.getErt() fs_manager = ert.getEnkfFsManager() result_fs = fs_manager.getCurrentFileSystem() model_config = ert.getModelConfig() runpath_fmt = model_config.getRunpathFormat() jobname_fmt = model_config.getJobnameFormat() subst_list = ert.getDataKW() itr = 0 mask = BoolVector(default_value=True, initial_size=1) run_context = ErtRunContext.ensemble_experiment( result_fs, mask, runpath_fmt, jobname_fmt, subst_list, itr) ert.getEnkfSimulationRunner().createRunPath(run_context) os.chdir('storage/snake_oil/runpath/realisation-0/iter-0') assert (os.path.isfile('jobs.json')) with open("jobs.json", "r") as f: data = json.load(f) env_data = data["global_environment"] self.assertEqual('TheFirstValue', env_data["FIRST"]) self.assertEqual('TheSecondValue', env_data["SECOND"]) path_data = data["global_update_path"] self.assertEqual('TheThirdValue', path_data["THIRD"]) self.assertEqual('TheFourthValue', path_data["FOURTH"])
def test_transfer_var(use_tmpdir): # Write a minimal config file with env with open("config_file.ert", "w") as fout: fout.write( dedent(""" NUM_REALIZATIONS 1 JOBNAME a_name_%d SETENV FIRST TheFirstValue SETENV SECOND TheSecondValue UPDATE_PATH THIRD TheThirdValue UPDATE_PATH FOURTH TheFourthValue """)) res_config = ResConfig("config_file.ert") ert = EnKFMain(res_config) fs_manager = ert.getEnkfFsManager() model_config = ert.getModelConfig() run_context = ErtRunContext.ensemble_experiment( fs_manager.getCurrentFileSystem(), [True], model_config.getRunpathFormat(), model_config.getJobnameFormat(), ert.getDataKW(), 0, ) ert.getEnkfSimulationRunner().createRunPath(run_context) os.chdir("simulations/realization0") with open("jobs.json", "r") as f: data = json.load(f) env_data = data["global_environment"] assert env_data["FIRST"] == "TheFirstValue" assert env_data["SECOND"] == "TheSecondValue" path_data = data["global_update_path"] assert "TheThirdValue" == path_data["THIRD"] assert "TheFourthValue" == path_data["FOURTH"]
def test_simulation_model(self): with TestAreaContext("enkf_test_sim_model_kw") as work_area: base_path = os.getcwd() source_path = self.createTestPath("local/simulation_model") work_area.copy_directory(source_path) dir_ert = os.path.join(base_path, "simulation_model") assert os.path.isdir(dir_ert) file_ert = os.path.join(dir_ert, "sim_kw.ert") assert os.path.isfile(file_ert) with ErtTestContext("sim_kw", model_config=file_ert, store_area=True) as ctx: ert = ctx.getErt() fs_manager = ert.getEnkfFsManager() result_fs = fs_manager.getCurrentFileSystem() model_config = ert.getModelConfig() forward_model = model_config.getForwardModel() self.assertEqual(forward_model.get_size(), 6) self.assertEqual( forward_model.iget_job(3).get_arglist(), ["WORD_A"]) self.assertEqual( forward_model.iget_job(0).get_arglist(), ["<ARGUMENT>"]) self.assertEqual( forward_model.iget_job(1).get_arglist(), ["Hello", "True", "3.14", "4"], ) self.assertEqual( forward_model.iget_job(2).get_arglist(), ["word", "<ECLBASE>"]) self.assertEqual( forward_model.iget_job(0).get_argvalues(), ["yy"]) self.assertEqual( forward_model.iget_job(1).get_argvalues(), ["Hello", "True", "3.14", "4"], ) self.assertEqual( forward_model.iget_job(2).get_argvalues(), ["word", "<ECLBASE>"]) self.assertEqual( forward_model.iget_job(3).get_argvalues(), ["WORD_A"]) self.assertEqual( list(forward_model.iget_job(4).get_argvalues()), [ "configured_argumentA", "configured_argumentB", "DEFINED_ARGC_VALUE", ], ) self.assertEqual( list(forward_model.iget_job(5).get_argvalues()), [ "DEFAULT_ARGA_VALUE", "<ARGUMENTB>", "DEFINED_ARGC_VALUE" ], ) runpath_fmt = model_config.getRunpathFormat() jobname_fmt = model_config.getJobnameFormat() subst_list = ert.getDataKW() itr = 0 mask = BoolVector(default_value=True, initial_size=1) run_context = ErtRunContext.ensemble_experiment( result_fs, mask, runpath_fmt, jobname_fmt, subst_list, itr) ert.getEnkfSimulationRunner().createRunPath(run_context) queue_config = ert.get_queue_config() self.assertEqual(queue_config.num_cpu, 5) os.chdir("storage/sim_kw/runpath/realisation-0/iter-0") assert os.path.isfile("jobs.json") with open("jobs.json", "r") as f: data = json.load(f) jobList = data["jobList"] old_job_A = jobList[3] self.assertEqual(old_job_A["argList"], ["WORD_A"]) old_job_B = jobList[0] self.assertEqual(old_job_B["argList"], ["yy"]) new_job_A = jobList[1] self.assertEqual(new_job_A["argList"], ["Hello", "True", "3.14", "4"]) new_job_B = jobList[2] self.assertEqual(new_job_B["argList"], ["word", "SIM_KW"])