def bundle(self,source): self.vlog('bundled run detected',n=1) if os.path.exists(source): fobj = open(source,'r') lines = fobj.read().split('\n') fobj.close() else: self.error('source file '+source+' does not exist') #end if infiles = [] for line in lines: ls = line.strip() if ls!='': infiles.append(ls) #end if #end for self.info.input_infiles = list(infiles) analyzers = QAanalyzerCollection() request = self.info.request path = os.path.split(request.source)[0] files = os.listdir(path) outfiles = [] for file in files: if file.endswith('qmc'): outfiles.append(file) #end if #end for del files for i in range(len(infiles)): infile = infiles[i] prefix = infile.replace('.xml','') gn = i for outfile in outfiles: if outfile.startswith(prefix): gn = int(outfile.split('.')[-2][1:]) break #end if #end for req = request.copy() req.source = os.path.join(path,infile) req.group_num = gn qa = QmcpackAnalyzer(req,nindent=self.subindent()) #qa.init_sub_analyzers(group_num=gn) analyzers[gn] = qa #end for self.bundled_analyzers = analyzers self.info.perform_bundle_average = False #check to see if twist averaging # indicated by distinct twistnums # or twist in all ids twistnums = set() twist_ids = True for analyzer in analyzers: input = analyzer.info.input twistnum = input.get('twistnum') project = input.get('project') if twistnum!=None: twistnums.add(twistnum) #end if twist_ids = twist_ids and 'twist' in project.id #end for distinct_twistnums = len(twistnums)==len(analyzers) twist_averaging = distinct_twistnums or twist_ids if twist_averaging: self.info.perform_bundle_average = True #end if example = analyzers.list()[0] input,system = example.info.tuple('input','system') self.info.set( input = input.copy(), system = system.copy() ) self.vlog('average over bundled runs? {0}'.format(self.info.perform_bundle_average),n=1)
def bundle(self, source): self.vlog('bundled run detected', n=1) if os.path.exists(source): fobj = open(source, 'r') lines = fobj.read().split('\n') fobj.close() else: self.error('source file ' + source + ' does not exist') #end if infiles = [] for line in lines: ls = line.strip() if ls != '': infiles.append(ls) #end if #end for self.info.input_infiles = list(infiles) analyzers = QAanalyzerCollection() request = self.info.request path = os.path.split(request.source)[0] files = os.listdir(path) outfiles = [] for file in files: if file.endswith('qmc'): outfiles.append(file) #end if #end for del files for i in range(len(infiles)): infile = infiles[i] prefix = infile.replace('.xml', '') gn = i for outfile in outfiles: if outfile.startswith(prefix): gn = int(outfile.split('.')[-2][1:]) break #end if #end for req = request.copy() req.source = os.path.join(path, infile) req.group_num = gn qa = QmcpackAnalyzer(req, nindent=self.subindent()) #qa.init_sub_analyzers(group_num=gn) analyzers[gn] = qa #end for self.bundled_analyzers = analyzers self.info.perform_bundle_average = False #check to see if twist averaging # indicated by distinct twistnums # or twist in all ids twistnums = set() twist_ids = True for analyzer in analyzers: input = analyzer.info.input twistnum = input.get('twistnum') project = input.get('project') if twistnum != None: twistnums.add(twistnum) #end if twist_ids = twist_ids and 'twist' in project.id #end for distinct_twistnums = len(twistnums) == len(analyzers) twist_averaging = distinct_twistnums or twist_ids if twist_averaging: self.info.perform_bundle_average = True #end if example = analyzers.list()[0] input, system = example.info.tuple('input', 'system') self.info.set(input=input.copy(), system=system.copy()) self.vlog('average over bundled runs? {0}'.format( self.info.perform_bundle_average), n=1)
def init_sub_analyzers(self,request=None): own_request = request==None if request==None: request = self.info.request #end if group_num = request.group_num #determine if the run was bundled if request.source.endswith('.xml'): self.info.type = 'single' else: self.info.type = 'bundled' self.bundle(request.source) return #end if self.vlog('reading input file: '+request.source,n=1) input = QmcpackInput(request.source) input.pluralize() input.unroll_calculations() calculations = input.simulation.calculations self.info.set( input = input, ordered_input = input.read_xml(request.source) ) project,wavefunction = input.get('project','wavefunction') wavefunction = wavefunction.get_single('psi0') subindent = self.subindent() self.wavefunction = WavefunctionAnalyzer(wavefunction,nindent=subindent) self.vlog('project id: '+project.id,n=1) file_prefix = project.id if group_num!=None: group_ext = '.g'+str(group_num).zfill(3) if not file_prefix.endswith(group_ext): file_prefix += group_ext #end if elif self.info.type=='single': resdir,infile = os.path.split(request.source) ifprefix = infile.replace('.xml','') ls = os.listdir(resdir) for filename in ls: if filename.startswith(ifprefix) and filename.endswith('.qmc'): group_tag = filename.split('.')[-2] #file_prefix = 'qmc.'+group_tag file_prefix = project.id+'.'+group_tag break #end if #end for #end if if 'series' in project: series_start = int(project.series) else: series_start = 0 #end if self.vlog('data file prefix: '+file_prefix,n=1) run_info = obj( file_prefix = file_prefix, series_start = series_start, source_path = os.path.split(request.source)[0], group_num = group_num, system = input.return_system() ) self.info.transfer_from(run_info) self.set_global_info() if len(request.calculations)==0: request.calculations = set(series_start+arange(len(calculations))) #end if method_aliases = dict() for method in self.opt_methods: method_aliases[method]='opt' #end for for method in self.vmc_methods: method_aliases[method]='vmc' #end for for method in self.dmc_methods: method_aliases[method]='dmc' #end for method_objs = ['qmc','opt','vmc','dmc'] for method in method_objs: self[method] = QAanalyzerCollection() #end for for index,calc in calculations.iteritems(): method = calc.method if method in method_aliases: method_type = method_aliases[method] else: self.error('method '+method+' is unrecognized') #end if if method_type in request.methods: series = series_start + index if series in request.calculations: if method in self.opt_methods: qma = OptAnalyzer(series,calc,input,nindent=subindent) self.opt[series] = qma elif method in self.vmc_methods: qma = VmcAnalyzer(series,calc,input,nindent=subindent) self.vmc[series] = qma elif method in self.dmc_methods: qma = DmcAnalyzer(series,calc,input,nindent=subindent) self.dmc[series] = qma #end if self.qmc[series] = qma #end if #end if #end for for method in method_objs: if len(self[method])==0: del self[method] #end if #end for #Check for multi-qmc results such as # optimization or timestep studies results = QAanalyzerCollection() if 'opt' in self and len(self.opt)>0: optres = OptimizationAnalyzer(input,self.opt,nindent=subindent) results.optimization = optres #end if if 'dmc' in self and len(self.dmc)>1: maxtime = 0 times = dict() for series,dmc in self.dmc.iteritems(): blocks,steps,timestep = dmc.info.method_input.list('blocks','steps','timestep') times[series] = blocks*steps*timestep maxtime = max(times[series],maxtime) #end for dmc = QAanalyzerCollection() for series,time in times.iteritems(): if abs(time-maxtime)/maxtime<.5: dmc[series] = self.dmc[series] #end if #end for if len(dmc)>1: results.timestep_study = TimestepStudyAnalyzer(dmc,nindent=subindent) #end if #end if if len(results)>0: self.results = results #end if self.unset_global_info()
def init_sub_analyzers(self, request=None): own_request = request == None if request == None: request = self.info.request #end if group_num = request.group_num #determine if the run was bundled if request.source.endswith('.xml'): self.info.type = 'single' else: self.info.type = 'bundled' self.bundle(request.source) return #end if self.vlog('reading input file: ' + request.source, n=1) input = QmcpackInput(request.source) input.pluralize() input.unroll_calculations() calculations = input.simulation.calculations self.info.set(input=input, ordered_input=input.read_xml(request.source)) project, wavefunction = input.get('project', 'wavefunction') wavefunction = wavefunction.get_single('psi0') subindent = self.subindent() self.wavefunction = WavefunctionAnalyzer(wavefunction, nindent=subindent) self.vlog('project id: ' + project.id, n=1) file_prefix = project.id if group_num != None: group_ext = '.g' + str(group_num).zfill(3) if not file_prefix.endswith(group_ext): file_prefix += group_ext #end if elif self.info.type == 'single': resdir, infile = os.path.split(request.source) #ifprefix = infile.replace('.xml','') ifprefix = infile.replace('.xml', '.') ls = os.listdir(resdir) for filename in ls: if filename.startswith(ifprefix) and filename.endswith('.qmc'): group_tag = filename.split('.')[-2] #file_prefix = 'qmc.'+group_tag file_prefix = project.id + '.' + group_tag break #end if #end for #end if if 'series' in project: series_start = int(project.series) else: series_start = 0 #end if self.vlog('data file prefix: ' + file_prefix, n=1) run_info = obj(file_prefix=file_prefix, series_start=series_start, source_path=os.path.split(request.source)[0], group_num=group_num, system=input.return_system()) self.info.transfer_from(run_info) self.set_global_info() if len(request.calculations) == 0: request.calculations = set(series_start + arange(len(calculations))) #end if method_aliases = dict() for method in self.opt_methods: method_aliases[method] = 'opt' #end for for method in self.vmc_methods: method_aliases[method] = 'vmc' #end for for method in self.dmc_methods: method_aliases[method] = 'dmc' #end for method_objs = ['qmc', 'opt', 'vmc', 'dmc'] for method in method_objs: self[method] = QAanalyzerCollection() #end for for index, calc in calculations.iteritems(): method = calc.method if method in method_aliases: method_type = method_aliases[method] else: self.error('method ' + method + ' is unrecognized') #end if if method_type in request.methods: series = series_start + index if series in request.calculations: if method in self.opt_methods: qma = OptAnalyzer(series, calc, input, nindent=subindent) primary = self.opt elif method in self.vmc_methods: qma = VmcAnalyzer(series, calc, input, nindent=subindent) primary = self.vmc elif method in self.dmc_methods: qma = DmcAnalyzer(series, calc, input, nindent=subindent) primary = self.dmc #end if primary[series] = qma self.qmc[series] = qma #end if #end if #end for for method in method_objs: if len(self[method]) == 0: del self[method] #end if #end for #Check for multi-qmc results such as # optimization or timestep studies results = QAanalyzerCollection() if 'opt' in self and len(self.opt) > 0: optres = OptimizationAnalyzer(input, self.opt, nindent=subindent) results.optimization = optres #end if if 'dmc' in self and len(self.dmc) > 1: maxtime = 0 times = dict() for series, dmc in self.dmc.iteritems(): blocks, steps, timestep = dmc.info.method_input.list( 'blocks', 'steps', 'timestep') times[series] = blocks * steps * timestep maxtime = max(times[series], maxtime) #end for dmc = QAanalyzerCollection() for series, time in times.iteritems(): if abs(time - maxtime) / maxtime < .5: dmc[series] = self.dmc[series] #end if #end for if len(dmc) > 1: results.timestep_study = TimestepStudyAnalyzer( dmc, nindent=subindent) #end if #end if if len(results) > 0: self.results = results #end if self.unset_global_info()