def test_create(self): with TestAreaContext("run_context"): arg = None sim_fs = EnkfFs.createFileSystem("sim_fs", EnKFFSType.BLOCK_FS_DRIVER_ID, arg) target_fs = None mask = BoolVector(initial_size=100, default_value=True) mask[50] = False runpath_fmt = PathFormat("path/to/sim%d") subst_list = SubstitutionList() itr = 0 jobname_fmt = "job%d" run_context1 = ErtRunContext(EnkfRunType.ENSEMBLE_EXPERIMENT, sim_fs, target_fs, mask, runpath_fmt, jobname_fmt, subst_list, itr) run_id1 = run_context1.get_id() run_arg0 = run_context1[0] with self.assertRaises(ValueError): run_arg0.getQueueIndex() self.assertEqual(run_arg0.iter_id, itr) self.assertEqual(run_id1, run_arg0.get_run_id()) run_context2 = ErtRunContext(EnkfRunType.ENSEMBLE_EXPERIMENT, sim_fs, target_fs, mask, runpath_fmt, jobname_fmt, subst_list, itr) run_id2 = run_context2.get_id() self.assertFalse(run_id1 == run_id2) self.assertTrue(run_context1.is_active(49)) self.assertFalse(run_context1.is_active(50))
def test_create(self): with TestAreaContext("run_context"): arg = None sim_fs = EnkfFs.createFileSystem("sim_fs", EnKFFSType.BLOCK_FS_DRIVER_ID, arg) target_fs = None mask = BoolVector(initial_size=100, default_value=True) runpath_fmt = PathFormat("path/to/sim%d") subst_list = SubstitutionList() itr = 0 run_context1 = ErtRunContext(EnkfRunType.ENSEMBLE_EXPERIMENT, sim_fs, target_fs, mask, runpath_fmt, subst_list, itr) run_id1 = run_context1.get_id() run_arg0 = run_context1[0] self.assertEqual(run_id1, run_arg0.get_run_id()) run_context2 = ErtRunContext(EnkfRunType.ENSEMBLE_EXPERIMENT, sim_fs, target_fs, mask, runpath_fmt, subst_list, itr) run_id2 = run_context2.get_id() self.assertFalse(run_id1 == run_id2)
def test_assert_symlink_deleted(self): with ErtTestContext("create_runpath_symlink_deleted" , self.createTestPath("local/snake_oil_field/snake_oil.ert")) as tc: ert = tc.getErt( ) runpath_list = ert.getRunpathList( ) ens_size = ert.getEnsembleSize() runner = ert.getEnkfSimulationRunner() mask = BoolVector( initial_size = ens_size , default_value = True ) fs_manager = ert.getEnkfFsManager() init_fs = fs_manager.getFileSystem("init_fs") # create directory structure runpath_fmt = ert.getModelConfig().getRunpathFormat( ) subst_list = SubstitutionList( ) itr = 0 jobname_fmt = ert.getModelConfig().getJobnameFormat() run_context = ErtRunContext( EnkfRunType.INIT_ONLY , init_fs, None , mask , runpath_fmt, jobname_fmt, subst_list , itr ) runner.createRunPath( run_context ) # replace field file with symlink linkpath = '%s/permx.grdcel' % str(runpath_list[0].runpath) targetpath = '%s/permx.grdcel.target' % str(runpath_list[0].runpath) open(targetpath, 'a').close() os.remove(linkpath) os.symlink(targetpath, linkpath) # recreate directory structure runner.createRunPath( run_context ) # ensure field symlink is replaced by file self.assertFalse( os.path.islink(linkpath) )
def test_simulated_custom_kw(self): config = self.createTestPath("local/custom_kw/mini_config") with ErtTestContext("python/enkf/data/custom_kw_simulated", config) as context: ert = context.getErt() ensemble_config = ert.ensembleConfig() self.assertTrue("AGGREGATED" in ensemble_config) config = ensemble_config.getNode("AGGREGATED").getCustomKeywordModelConfig() self.assertEqual(len(config.getKeys()), 0) simulation_runner = EnkfSimulationRunner(ert) job_queue = ert.get_queue_config().create_job_queue() iteration_count = 0 active = BoolVector(default_value = True, initial_size = 4) subst_list = ert.getDataKW( ) runpath_fmt = ert.getModelConfig( ).getRunpathFormat( ) fs_manager = ert.getEnkfFsManager( ) fs = fs_manager.getFileSystem("fs") jobname_fmt = ert.getModelConfig( ).getJobnameFormat( ) run_context = ErtRunContext( EnkfRunType.ENSEMBLE_EXPERIMENT , fs, None , active , runpath_fmt, jobname_fmt, subst_list , iteration_count) simulation_runner.createRunPath( run_context ) simulation_runner.runEnsembleExperiment(job_queue, run_context) config = ensemble_config.getNode("AGGREGATED").getCustomKeywordModelConfig() self.assertEqual(len(config.getKeys()), 4) self.assertItemsEqual(config.getKeys(), ["PERLIN_1", "PERLIN_2", "PERLIN_3", "STATE"])
def test_assert_export(self): with ErtTestContext( "create_runpath1", self.createTestPath( "local/snake_oil_no_data/snake_oil.ert")) as tc: ert = tc.getErt() runpath_list = ert.getRunpathList() self.assertFalse(path.isfile(runpath_list.getExportFile())) ens_size = ert.getEnsembleSize() runner = ert.getEnkfSimulationRunner() fs_manager = ert.getEnkfFsManager() init_fs = fs_manager.getFileSystem("init_fs") mask = BoolVector(initial_size=100, default_value=True) runpath_fmt = ert.getModelConfig().getRunpathFormat() subst_list = SubstitutionList() itr = 0 run_context1 = ErtRunContext(EnkfRunType.INIT_ONLY, init_fs, None, None, mask, runpath_fmt, subst_list, itr) runner.createRunPath(run_context1) self.assertTrue(path.isfile(runpath_list.getExportFile())) self.assertEqual("test_runpath_list.txt", path.basename(runpath_list.getExportFile()))
def initializeCase(ert, name, size): """ @type ert: res.enkf.enkf_main.EnKFMain @type name: str @type size: int @rtype: """ fs = ert.getEnkfFsManager().getFileSystem(name) mask = BoolVector(default_value=True, initial_size=size) model_config = ert.getModelConfig() runpath_fmt = model_config.getRunpathFormat() jobname_fmt = model_config.getJobnameFormat() subst_list = ert.getDataKW() itr = 0 run_context = ErtRunContext(EnkfRunType.ENSEMBLE_EXPERIMENT, fs, None, mask, runpath_fmt, jobname_fmt, subst_list, itr) parameters = ert.ensembleConfig().getKeylistFromVarType( EnkfVarType.PARAMETER) ert.getEnkfFsManager().initializeFromScratch(parameters, run_context)
def __init__(self, ert, sim_fs, mask, itr, case_data): self._ert = ert """ :type: res.enkf.EnKFMain """ max_runtime = ert.analysisConfig().get_max_runtime() self._mask = mask job_queue = ert.get_queue_config().create_job_queue() job_queue.set_max_job_duration(max_runtime) self._queue_manager = JobQueueManager(job_queue) subst_list = self._ert.getDataKW() path_fmt = self._ert.getModelConfig().getRunpathFormat() jobname_fmt = self._ert.getModelConfig().getJobnameFormat() self._run_context = ErtRunContext( EnkfRunType.ENSEMBLE_EXPERIMENT, sim_fs, None, mask, path_fmt, jobname_fmt, subst_list, itr, ) # fill in the missing geo_id data for sim_id, (geo_id, _) in enumerate(case_data): if mask[sim_id]: run_arg = self._run_context[sim_id] run_arg.geo_id = geo_id self._ert.getEnkfSimulationRunner().createRunPath(self._run_context) EnkfSimulationRunner.runWorkflows(HookRuntime.PRE_SIMULATION, self._ert) self._sim_thread = self._run_simulations_simple_step() # Wait until the queue is active before we finish the creation # to ensure sane job status while running while self.isRunning() and not self._queue_manager.isRunning(): sleep(0.1)