def load_stages(state,smap = {}): sfile = os.path.join(tl.inmem(),'stagefile') stagepath = os.path.join(os.getcwd(),sfile) if not os.path.exists(stagepath): logging.warning('stagefile could not be found: %s',stagepath) return with open(stagepath,'r') as sh:slines = sh.readlines() for sl in slines: sl = sl.strip() if sl == '' or sl.startswith('#'):continue try: sn,sm,sf = [l.strip() for l in sl.split(':')] smap[sn] = __import__(sm).__dict__[sf]() except ImportError: traceback.print_exc(file = sys.stdout) logging.warning('could not import stage: %s',sl)
def inform(self,state,report): if self.active is None:return True dppath = os.path.join(tl.inmem('data'),'mcfgdata') lfu.user_data_pool_path = dppath e,zs,ax,al = self.tickets[self.active] cplan = e.cartographer_plan pplan = e.postprocess_plan for x in range(len(report)): jx,lp = report[x] ax,lp = lp if lp is None: mmap = cplan.metamap lstr = cplan._print_friendly_pspace_location(ax) ntraj = cplan.trajectory[ax].trajectory_count lp = mmap._recover_location(lstr,ntraj) else: lp.data = os.path.join(dppath,'mapdata',lp.data_pool_id) cplan._record_persistent(ax,lp) self.results[jx] = (ax,lp) pplan._enact_processes(zs,lp,arcx = ax) ncnt = self.results.count(None) perc = (1.0-float(ncnt-1)/al)*100.0 self.update_statbuff(state,'%4s percent complete',str(perc)) cplan._save_metamap() ncnt = self.results.count(None) if ncnt == 1: self.results[-1] = 'DONE' traj,pspace = cplan.trajectory,cplan.parameter_space e._output_trajectory_key(traj,pspace) let = state['lastenqueuetime'] tl.log(5,'duration of simulations',time.time()-let) tl.log(5,'performing non-0th post processing...') pstime = time.time() if pplan.use_plan:pplan._walk_processes() tl.log(5,'duration of non-0th post processes',time.time()-pstime) tl.log(5,'saving final data pool...') dpool = dba.batch_node(rnum = self.rgen.randint(10000,90000)) e._save_data_pool(dpool) tl.log(5,'saved final data pool') tl.log(5,'performing mcfg result output...') e._output() tl.log(5,'performed mcfg result output') self.update_statbuff(state,' DONE') return True
def run_mjob(state,job): ax,job = job if job is None:return ax,None f,args,drseed,dshape,ptargets = job rgen = random.Random() rgen.seed(drseed) dppath = os.path.join(tl.inmem('data'),'mcfgdata') lfu.user_data_pool_path = dppath loc_pool = dba.batch_node( metapool = True,rnum = drseed, dshape = dshape,targets = ptargets) tl.log(1,'running pspace location',ax) for x in range(dshape[0]): pseed = rgen.randint(0,sys.maxint) r = f(pseed,*args) loc_pool._trajectory(r) loc_pool._stow(v = False) loc_pool._sanitize() return ax,loc_pool
def enqueue(self,state,job): tl.log(5,'MCFG ENQUEUE',job[:20]) dppath = os.path.join(tl.inmem('data'),'mcfgdata') lfu.user_data_pool_path = dppath ensem = self.emnger._add_ensemble(module = 'gillespiem') ensem._parse_mcfg(mcfgstring = job) ensem.output_plan.targeted = ensem.run_params['plot_targets'][:] ensem.output_plan._target_settables() ensem.cartographer_plan._move_to(0) ensem._run_params_to_location_prepoolinit() cplan = ensem.cartographer_plan pplan = ensem.postprocess_plan meta = cplan.maintain_pspmap arc = cplan.trajectory if pplan.use_plan:zs = pplan._init_processes(arc) self.tickets[job] = (ensem,zs,0,len(arc)) self.active = job jx = len(self.queue) self.queue.append((jx,job)) self.results.append(None) state['lastenqueuetime'] = time.time() state['statbuff'] = os.path.join(dppath,self.name+'.buff') self.update_statbuff(state,' 0.0 percent complete')
def __init__(self,n): self.name = n self.smngr = st.manager('msched_settings.txt') self.hostfile = os.path.join(tl.inmem(),'hostfile') sys.path.append(tl.inmem('stages'))