class SimulationContext(object): def __init__(self, ert, size, verbose=False): self._ert = ert """ :type: ert.enkf.EnKFMain """ self._size = size max_runtime = ert.analysisConfig().get_max_runtime() job_queue = ert.siteConfig().getJobQueue() job_queue.set_max_job_duration(max_runtime) self._queue_manager = JobQueueManager(job_queue) self._queue_manager.startQueue(size, verbose=verbose) self._run_args = {} """ :type: dict[int, RunArg] """ self._thread_pool = CThreadPool(8) self._thread_pool.addTaskFunction("submitJob", ENKF_LIB, "enkf_main_isubmit_job__") def addSimulation(self, iens, target_fs): if iens >= self._size: raise UserWarning("Realization number out of range: %d >= %d" % (iens, self._size)) if iens in self._run_args: raise UserWarning("Realization number: '%d' already queued" % iens) runpath_fmt = self._ert.getModelConfig().getRunpathFormat() member = self._ert.getRealisation(iens) runpath = ErtRunContext.createRunpath(iens , runpath_fmt, member.getDataKW( )) run_arg = RunArg.createEnsembleExperimentRunArg(target_fs, iens, runpath) self._ert.createRunPath(run_arg) self._run_args[iens] = run_arg self._thread_pool.submitJob(ArgPack(self._ert, run_arg)) def isRunning(self): return self._queue_manager.isRunning() def getNumRunning(self): return self._queue_manager.getNumRunning() def getNumSuccess(self): return self._queue_manager.getNumSuccess() def getNumFailed(self): return self._queue_manager.getNumFailed() def getNumWaiting(self): return self._queue_manager.getNumWaiting() def didRealizationSucceed(self, iens): queue_index = self._run_args[iens].getQueueIndex() return self._queue_manager.didJobSucceed(queue_index) def didRealizationFail(self, iens): # For the purposes of this class, a failure should be anything (killed job, etc) that is not an explicit success. return not self.didRealizationSucceed(iens) def isRealizationQueued(self, iens): return iens in self._run_args def isRealizationFinished(self, iens): run_arg = self._run_args[iens] if run_arg.isSubmitted(): queue_index = run_arg.getQueueIndex() return self._queue_manager.isJobComplete(queue_index) else: return False def __repr__(self): running = 'running' if self.isRunning() else 'not running' numRunn = self.getNumRunning() numSucc = self.getNumSuccess() numFail = self.getNumFailed() numWait = self.getNumWaiting() fmt = '%s, #running = %d, #success = %d, #failed = %d, #waiting = %d' fmt = fmt % (running, numRunn, numSucc, numFail, numWait) return 'SimulationContext(%s)' % fmt
class SimulationContext(object): def __init__(self, ert, size, verbose=False): self._ert = ert """ :type: ert.enkf.EnKFMain """ self._size = size self._queue_manager = JobQueueManager(ert.siteConfig().getJobQueue()) self._queue_manager.startQueue(size, verbose=verbose) self._run_args = {} """ :type: dict[int, RunArg] """ self._thread_pool = CThreadPool(8) self._thread_pool.addTaskFunction("submitJob", ENKF_LIB, "enkf_main_isubmit_job__") def addSimulation(self, iens, target_fs): if iens >= self._size: raise UserWarning("Realization number out of range: %d >= %d" % (iens, self._size)) if iens in self._run_args: raise UserWarning("Realization number: '%d' already queued" % iens) runpath_fmt = self._ert.getModelConfig().getRunpathFormat() member = self._ert.getRealisation(iens) runpath = ErtRunContext.createRunpath(iens, runpath_fmt, member.getDataKW()) run_arg = RunArg.createEnsembleExperimentRunArg( target_fs, iens, runpath) self._ert.createRunPath(run_arg) self._run_args[iens] = run_arg self._thread_pool.submitJob(ArgPack(self._ert, run_arg)) def isRunning(self): return self._queue_manager.isRunning() def getNumRunning(self): return self._queue_manager.getNumRunning() def getNumSuccess(self): return self._queue_manager.getNumSuccess() def getNumFailed(self): return self._queue_manager.getNumFailed() def getNumWaiting(self): return self._queue_manager.getNumWaiting() def didRealizationSucceed(self, iens): queue_index = self._run_args[iens].getQueueIndex() return self._queue_manager.didJobSucceed(queue_index) def didRealizationFail(self, iens): queue_index = self._run_args[iens].getQueueIndex() return self._queue_manager.didJobFail(queue_index) def isRealizationQueued(self, iens): return iens in self._run_args def isRealizationFinished(self, iens): run_arg = self._run_args[iens] if run_arg.isSubmitted(): queue_index = run_arg.getQueueIndex() return self._queue_manager.isJobComplete(queue_index) else: return False
# Create list of RunArg instances which hold metadata for one running # realisation, create the directory where the simulation should run # and submit the simulation. path_fmt = "/tmp/run%d" arg_list = [ RunArg.createEnsembleExperimentRunArg(fs, iens, path_fmt % iens) for iens in range(ert.getEnsembleSize()) ] for arg in arg_list: ert.createRunPath(arg) ert.submitSimulation(arg) while True: print("Waiting:%d Running:%d Complete:%d/%d" % (queue_manager.getNumWaiting(), queue_manager.getNumRunning(), queue_manager.getNumSuccess(), queue_manager.getNumFailed())) if not queue_manager.isRunning(): break time.sleep(5) ens_config = ert.ensembleConfig() data_config = ens_config["SNAKE_OIL_OPR_DIFF"] param_config = ens_config["SNAKE_OIL_PARAM"] for iens in range(ert.getEnsembleSize()): data_id = NodeId(realization_number=iens, report_step=199) enkf_node1 = EnkfNode(data_config) enkf_node1.load(fs, data_id) gen_data = enkf_node1.asGenData() data = gen_data.getData()
queue_manager = JobQueueManager( site_config.getJobQueue( ) ) queue_manager.startQueue( ert.getEnsembleSize( ) , verbose = False ) # Create list of RunArg instances which hold metadata for one running # realisation, create the directory where the simulation should run # and submit the simulation. path_fmt = "/tmp/run%d" arg_list = [ RunArg.createEnsembleExperimentRunArg(fs, iens, path_fmt % iens) for iens in range(ert.getEnsembleSize()) ] for arg in arg_list: ert.createRunPath( arg ) ert.submitSimulation( arg ) while True: print("Waiting:%d Running:%d Complete:%d/%d" % (queue_manager.getNumWaiting( ), queue_manager.getNumRunning( ) , queue_manager.getNumSuccess() , queue_manager.getNumFailed( ))) if not queue_manager.isRunning( ): break time.sleep( 5 ) ens_config = ert.ensembleConfig( ) data_config = ens_config["SNAKE_OIL_OPR_DIFF"] param_config = ens_config["SNAKE_OIL_PARAM"] for iens in range(ert.getEnsembleSize( )): data_id = NodeId( realization_number = iens, report_step = 199 ) enkf_node1 = EnkfNode( data_config ) enkf_node1.load( fs , data_id ) gen_data = enkf_node1.asGenData( ) data = gen_data.getData( )
class SimulationContext(object): def __init__(self, ert, size, verbose=False): self._ert = ert """ :type: ert.enkf.EnKFMain """ self._size = size self._queue_manager = JobQueueManager(ert.siteConfig().getJobQueue()) self._queue_manager.startQueue(size, verbose=verbose) self._run_args = {} """ :type: dict[int, RunArg] """ self._thread_pool = CThreadPool(8) self._thread_pool.addTaskFunction("submitJob", ENKF_LIB, "enkf_main_isubmit_job__") def addSimulation(self, iens, target_fs): if iens >= self._size: raise UserWarning("Realization number out of range: %d >= %d" % (iens, self._size)) if iens in self._run_args: raise UserWarning("Realization number: '%d' already queued" % iens) runpath_fmt = self._ert.getModelConfig().getRunpathFormat() member = self._ert.getRealisation(iens) runpath = ErtRunContext.createRunpath(iens, runpath_fmt, member.getDataKW()) run_arg = RunArg.createEnsembleExperimentRunArg(target_fs, iens, runpath) self._run_args[iens] = run_arg self._thread_pool.submitJob(ArgPack(self._ert, run_arg)) def isRunning(self): return self._queue_manager.isRunning() def getNumRunning(self): return self._queue_manager.getNumRunning() def getNumSuccess(self): return self._queue_manager.getNumSuccess() def getNumFailed(self): return self._queue_manager.getNumFailed() def getNumWaiting(self): return self._queue_manager.getNumWaiting() def didRealizationSucceed(self, iens): queue_index = self._run_args[iens].getQueueIndex() return self._queue_manager.didJobSucceed(queue_index) def didRealizationFail(self, iens): queue_index = self._run_args[iens].getQueueIndex() return self._queue_manager.didJobFail(queue_index) def isRealizationQueued(self, iens): return iens in self._run_args def isRealizationFinished(self, iens): run_arg = self._run_args[iens] if run_arg.isSubmitted(): queue_index = run_arg.getQueueIndex() return self._queue_manager.isJobComplete(queue_index) else: return False