class RunContext(object): def __init__(self , ert_handle , size , init_case): self.ert_handle = ert_handle self.size = size self.init_case = init_case self.runner = ert_handle.getEnkfSimulationRunner() site_config = self.ert_handle.siteConfig() self.queue_manager = JobQueueManager( site_config.getJobQueue() ) self.queue_manager.startQueue( size , verbose = True ) fs = self.ert_handle.getEnkfFsManager().getCurrentFileSystem() mask = BoolVector( default_value = True ) mask[size - 1] = True self.ert_run_context = self.ert_handle.getRunContextENSEMPLE_EXPERIMENT( fs , mask ) def getNumRunning(self): return 0 def getNumComplete(self): return 0 def startSimulation(self , iens): self.ert_handle.submitSimulation( self.ert_run_context.get(iens) )
class RunContext(object): def __init__(self, ert_handle, size, run_fs, run_count): self.ert_handle = ert_handle self.size = size self.runner = ert_handle.getEnkfSimulationRunner() site_config = self.ert_handle.siteConfig() self.queue_manager = JobQueueManager(site_config.getJobQueue()) self.queue_manager.startQueue(size, verbose=True) mask = BoolVector(default_value=True) mask[size - 1] = True self.ert_handle.addDataKW("<ELCO_RUN_COUNT>", "%s" % run_count) self.ert_run_context = self.ert_handle.getRunContextENSEMPLE_EXPERIMENT( run_fs, mask) def isRunning(self): return self.queue_manager.isRunning() def getNumRunning(self): return self.queue_manager.getNumRunning() def getNumComplete(self): return self.queue_manager.getNumComplete() def startSimulation(self, iens): self.ert_handle.submitSimulation(self.ert_run_context.iensGet(iens)) def realisationComplete(self, iens): run_arg = self.ert_run_context.iensGet(iens) queue_index = run_arg.getQueueIndex() return self.queue_manager.jobComplete(queue_index)
class RunContext(object): def __init__(self , ert_handle , size , run_fs , run_count): self.ert_handle = ert_handle self.size = size self.runner = ert_handle.getEnkfSimulationRunner() site_config = self.ert_handle.siteConfig() self.queue_manager = JobQueueManager( site_config.getJobQueue() ) self.queue_manager.startQueue( size , verbose = True ) mask = BoolVector( default_value = True ) mask[size - 1] = True self.ert_handle.addDataKW("<ELCO_RUN_COUNT>" , "%s" % run_count) self.ert_run_context = self.ert_handle.getRunContextENSEMPLE_EXPERIMENT( run_fs , mask ) 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 startSimulation(self , iens): self.ert_handle.submitSimulation( self.ert_run_context.iensGet( iens )) def realisationSuccess(self, iens): run_arg = self.ert_run_context.iensGet( iens ) queue_index = run_arg.getQueueIndex() return self.queue_manager.jobSuccess( queue_index ) def realisationFailed(self, iens): run_arg = self.ert_run_context.iensGet( iens ) queue_index = run_arg.getQueueIndex() return self.queue_manager.jobFailed( queue_index ) def realisationRunning(self, iens): run_arg = self.ert_run_context.iensGet( iens ) queue_index = run_arg.getQueueIndex() if self.queue_manager.jobRunning( queue_index ) or self.queue_manager.jobWaiting( queue_index ): return True else: return False
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
fs = fs_manager.getCurrentFileSystem( ) # Initialize the realisations. for iens in range( ert.getEnsembleSize()): realisation = ert.getRealisation( iens ) realisation.initialize( fs ) # Fetch out the job_queue from the SiteConfig object. In addition we # create a JobQueueManager objects which wraps the queue. The purpose # of this manager object is to let the queue run nonblocking in the # background. site_config = ert.siteConfig( ) 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( ):
ert = EnKFMain(res_config) fs_manager = ert.getEnkfFsManager() fs = fs_manager.getCurrentFileSystem() # Initialize the realisations. for iens in range(ert.getEnsembleSize()): realisation = ert.getRealisation(iens) realisation.initialize(fs) # Fetch out the job_queue from the SiteConfig object. In addition we # create a JobQueueManager objects which wraps the queue. The purpose # of this manager object is to let the queue run nonblocking in the # background. site_config = ert.siteConfig() 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" %
class RunContext(object): def __init__(self , ert_handle , size , run_fs , run_count): self.ert_handle = ert_handle self.size = size self.runner = ert_handle.getEnkfSimulationRunner() site_config = self.ert_handle.siteConfig() self.queue_manager = JobQueueManager( site_config.getJobQueue() ) self.queue_manager.startQueue( size , verbose = True ) mask = BoolVector( default_value = True ) mask[size - 1] = True self.ert_handle.addDataKW("<ELCO_RUN_COUNT>" , "%s" % run_count) self.ert_run_context = self.ert_handle.getRunContextENSEMPLE_EXPERIMENT( run_fs , mask ) self.thread_pool = CThreadPool( 8 ) self.submit_func = CThreadPool.lookupCFunction( ENKF_LIB , "enkf_main_isubmit_job__" ) 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 startSimulation(self , iens): member_context = self.ert_run_context.iensGet( iens ) arg = ArgPack( self.ert_handle , member_context ) self.thread_pool.addTask( self.submit_func , arg ) def realisationSuccess(self, iens): run_arg = self.ert_run_context.iensGet( iens ) queue_index = run_arg.getQueueIndex() return self.queue_manager.jobSuccess( queue_index ) def realisationFailed(self, iens): run_arg = self.ert_run_context.iensGet( iens ) queue_index = run_arg.getQueueIndex() return self.queue_manager.jobFailed( queue_index ) # Running is slightly misleading; we have three catogories: # Complete, Failed, and "Running". Running in this context is # actually the 'the rest', and includes jobs in all sorts of # waiting. def realisationRunning(self, iens): run_arg = self.ert_run_context.iensGet( iens ) if run_arg.isSubmitted(): queue_index = run_arg.getQueueIndex() if self.queue_manager.jobRunning( queue_index ) or self.queue_manager.jobWaiting( queue_index ): return True else: return False else: return True def exportRunpathList(self): runpath_list = self.ert_handle.getRunpathList( ) runpath_list.export( )
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