Changeset 2942
- Timestamp:
- Jul 25, 2017 3:06:04 PM (6 years ago)
- Location:
- branch/2frame
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branch/2frame/GSASIIdataGUI.py
r2940 r2942 3994 3994 3995 3995 def ExitMain(self, event): 3996 '''Called if the main window is closed''' 3996 '''Called if exit selected or the main window is closed 3997 rescord last position of data & plot windows; saved to config.py file 3998 NB: not called if console window closed 3999 ''' 3997 4000 FramePos = {'Main_Pos':tuple(self.GetPosition()),'Plot_Pos':tuple(self.plotFrame.GetPosition())} 3998 4001 GSASIIpath.SetConfigValue(FramePos) 3999 print FramePos4000 4002 config = G2G.GetConfigValsDocs() 4001 4003 G2G.SaveConfigVars(config) … … 4006 4008 sys.exit() 4007 4009 4008 # def OnFileExit(self, event):4009 # '''Called in response to the File/Quit menu button'''4010 # if self.G2plotNB:4011 # self.G2plotNB.Destroy()4012 # self.Close()4013 #4014 4010 def OnExportPeakList(self,event): 4015 4011 nptand = lambda x: np.tan(x*math.pi/180.) -
branch/2frame/GSASIImath.py
r2940 r2942 3971 3971 pass 3972 3972 3973 # A schedule due to Lester Ingber modified to use bounds - OK3974 3973 class fast_sa(base_schedule): 3975 3974 def init(self, **options): … … 4030 4029 return Tsched[1:] 4031 4030 4032 def anneal(func, x0, args=(), schedule='fast', full_output=0,4031 def anneal(func, x0, args=(), schedule='fast', 4033 4032 T0=None, Tf=1e-12, maxeval=None, maxaccept=None, maxiter=400, 4034 4033 feps=1e-6, quench=1.0, c=1.0, … … 4048 4047 :param base_schedule schedule: 4049 4048 Annealing schedule to use (a class). 4050 :param bool full_output:4051 Whether to return optional outputs.4052 4049 :param float T0: 4053 4050 Initial Temperature (estimated as 1.2 times the largest … … 4061 4058 :param int maxiter: 4062 4059 Maximum cooling iterations. 4063 :param float learn_rate:4064 Scale constant for adjusting guesses.4065 4060 :param float feps: 4066 4061 Stopping relative error tolerance for the function value in … … 4212 4207 if abs(af[-1]-best_state.cost) > feps*10: 4213 4208 retval = 5 4214 print " Warning: Cooled to %.4f > selected Tmin %.4f "%(squeeze(last_state.cost),Tf)4209 print " Warning: Cooled to %.4f > selected Tmin %.4f in %d steps"%(squeeze(last_state.cost),Tf,iters-1) 4215 4210 break 4216 4211 if (Tf is not None) and (schedule.T < Tf): 4217 print ' Minimum T reached' 4212 # print ' Minimum T reached in %d steps'%(iters-1) 4218 4213 retval = 1 4219 4214 break … … 4229 4224 break 4230 4225 4231 if full_output: 4232 return best_state.x, best_state.cost, schedule.T, \ 4233 schedule.feval, iters, schedule.accepted, retval 4234 else: 4235 return best_state.x, retval 4236 4237 def worker(iCyc,data,RBdata,reflType,reflData,covData,out_q,nprocess=-1): 4226 return best_state.x, best_state.cost, schedule.T, \ 4227 schedule.feval, iters, schedule.accepted, retval 4228 4229 def worker(iCyc,data,RBdata,reflType,reflData,covData,out_q,out_t,out_n,nprocess=-1): 4238 4230 outlist = [] 4231 timelist = [] 4232 nsflist = [] 4239 4233 random.seed(int(time.time())%100000+nprocess) #make sure each process has a different random start 4240 4234 for n in range(iCyc): 4241 result = mcsaSearch(data,RBdata,reflType,reflData,covData,None )4235 result = mcsaSearch(data,RBdata,reflType,reflData,covData,None,False) #mcsa result,time,rcov 4242 4236 outlist.append(result[0]) 4243 print ' MC/SA residual: %.3f%% structure factor time: %.3f'%(100*result[0][2],result[1]) 4237 timelist.append(result[1]) 4238 nsflist.append(result[2]) 4239 print ' MC/SA final fit: %.3f%% structure factor time: %.3f'%(100*result[0][2],result[1]) 4244 4240 out_q.put(outlist) 4241 out_t.put(timelist) 4242 out_n.put(nsflist) 4245 4243 4246 4244 def MPmcsaSearch(nCyc,data,RBdata,reflType,reflData,covData): 4247 4245 import multiprocessing as mp 4248 4246 4249 nprocs = m p.cpu_count()4247 nprocs = max(1,mp.cpu_count()-1) #leave one processor available for other work 4250 4248 out_q = mp.Queue() 4249 out_t = mp.Queue() 4250 out_n = mp.Queue() 4251 4251 procs = [] 4252 totsftime = 0. 4253 totnsf = 0 4252 4254 iCyc = np.zeros(nprocs) 4253 4255 for i in range(nCyc): 4254 4256 iCyc[i%nprocs] += 1 4255 4257 for i in range(nprocs): 4256 p = mp.Process(target=worker,args=(int(iCyc[i]),data,RBdata,reflType,reflData,covData,out_q, i))4258 p = mp.Process(target=worker,args=(int(iCyc[i]),data,RBdata,reflType,reflData,covData,out_q,out_t,out_n,i)) 4257 4259 procs.append(p) 4258 4260 p.start() … … 4260 4262 for i in range(nprocs): 4261 4263 resultlist += out_q.get() 4264 totsftime += np.sum(out_t.get()) 4265 totnsf += np.sum(out_n.get()) 4262 4266 for p in procs: 4263 4267 p.join() 4264 return resultlist 4265 4266 def mcsaSearch(data,RBdata,reflType,reflData,covData,pgbar ):4268 return resultlist,totsftime,totnsf 4269 4270 def mcsaSearch(data,RBdata,reflType,reflData,covData,pgbar,start=True): 4267 4271 '''default doc string 4268 4272 … … 4289 4293 return xnew 4290 4294 4291 global tsum 4295 global tsum,nsum 4292 4296 tsum = 0. 4297 nsum = 0 4293 4298 4294 4299 def getMDparms(item,pfx,parmDict,varyList): … … 4486 4491 ''' 4487 4492 4488 global tsum 4493 global tsum,nsum 4489 4494 t0 = time.time() 4490 4495 parmDict.update(dict(zip(varyList,values))) #update parameter tables … … 4505 4510 M = np.inner(refList[6],np.inner(rcov,refList[6])) 4506 4511 tsum += (time.time()-t0) 4512 nsum += 1 4507 4513 return np.sqrt(M/np.sum(refList[4]**2)) 4508 4514 … … 4637 4643 allFF = np.array(allFF).T 4638 4644 refs = np.array(refs).T 4639 print ' Minimum d-spacing used: %.2f No. reflections used: %d'%(MCSA['dmin'],nRef) 4640 print ' Number of parameters varied: %d'%(len(varyList)) 4645 if start: 4646 print ' Minimum d-spacing used: %.2f No. reflections used: %d'%(MCSA['dmin'],nRef) 4647 print ' Number of parameters varied: %d'%(len(varyList)) 4648 start = False 4641 4649 parmDict['sumFosq'] = sumFosq 4642 4650 x0 = [parmDict[val] for val in varyList] … … 4654 4662 T0 = None 4655 4663 results = anneal(mcsaCalc,x0,args=(refs,rcov,cosTable,ifInv,allFF,RBdata,varyList,parmDict), 4656 schedule=MCSA['Algorithm'], full_output=True,dwell=MCSA['Annealing'][2],maxiter=10000,4664 schedule=MCSA['Algorithm'], dwell=MCSA['Annealing'][2],maxiter=10000, 4657 4665 T0=T0, Tf=MCSA['Annealing'][1], 4658 4666 quench=MCSA['fast parms'][0], c=MCSA['fast parms'][1], 4659 4667 lower=lower, upper=upper, slope=MCSA['log slope'],ranStart=MCSA.get('ranStart',False), 4660 4668 ranRange=MCSA.get('ranRange',10.)/100.,autoRan=MCSA.get('autoRan',False),dlg=pgbar) 4669 print ' Acceptance rate: %.2f%% MCSA residual: %.2f%%'%(100.*results[5]/results[3],100.*results[1]) 4661 4670 results = so.minimize(mcsaCalc,results[0],method='L-BFGS-B',args=(refs,rcov,cosTable,ifInv,allFF,RBdata,varyList,parmDict), 4662 4671 bounds=bounds,) 4663 4672 mcsaCalc(results['x'],refs,rcov,cosTable,ifInv,allFF,RBdata,varyList,parmDict) 4664 4673 Result = [False,False,results['fun'],0.0,]+list(results['x']) 4665 # Result = [False,False,results[1],results[2],]+list(results[0])4666 4674 Result.append(varyList) 4667 return Result,tsum, rcov4675 return Result,tsum,nsum,rcov 4668 4676 4669 4677 -
branch/2frame/GSASIIphsGUI.py
r2940 r2942 2071 2071 line2Sizer = wx.BoxSizer(wx.HORIZONTAL) 2072 2072 line2Sizer.Add(wx.StaticText(General,label=' MC/SA runs: '),0,WACV) 2073 Cchoice = [ '1','2','4','8','16','32','64','128','256']2073 Cchoice = [str(2**i) for i in range(13)] 2074 2074 cycles = wx.ComboBox(General,-1,value=str(MCSAdata.get('Cycles',1)),choices=Cchoice, 2075 2075 style=wx.CB_READONLY|wx.CB_DROPDOWN) … … 7782 7782 for i in range(nCyc): 7783 7783 pgbar.SetTitle('MC/SA run '+str(i+1)+' of '+str(nCyc)) 7784 Result,tsum, rcov = G2mth.mcsaSearch(data,RBdata,reflType,reflData,covData,pgbar)7784 Result,tsum,nsum,rcov = G2mth.mcsaSearch(data,RBdata,reflType,reflData,covData,pgbar) 7785 7785 MCSAdata['Results'].append(Result) 7786 print ' MC/SA run completed: %d residual: %.3f%% SFcalc time: %.2fs '%(i,100*Result[2],tsum)7786 print ' MC/SA run completed: %d residual: %.3f%% SFcalc time: %.2fs Nsfcalc: %d'%(i,100*Result[2],tsum,nsum) 7787 7787 tsf += tsum 7788 7788 print ' Structure factor time: %.2f'%(tsf) … … 7790 7790 G2plt.PlotXYZ(G2frame,XY,rcov,labelX='ref No.',labelY='ref No.',newPlot=False,Title='Reflection covariance matrix') 7791 7791 else: 7792 MCSAdata['Results'] += G2mth.MPmcsaSearch(nCyc,data,RBdata,reflType,reflData,covData) #+= to any saved ones 7793 print ' MC/SA run time: %.2f'%(time.time()-time1) 7792 Results,sftime,numsf = G2mth.MPmcsaSearch(nCyc,data,RBdata,reflType,reflData,covData) 7793 MCSAdata['Results'] += Results #+= to any saved ones 7794 print ' Total SF time: %.2f MC/SA run time: %.2f Nsfcalc: %d'%(sftime,time.time()-time1,numsf) 7794 7795 finally: 7795 7796 if process == 'single':
Note: See TracChangeset
for help on using the changeset viewer.