Changeset 2894


Ignore:
Timestamp:
Jul 2, 2017 1:21:02 PM (4 years ago)
Author:
toby
Message:

speed derivative computation; add commented timing code

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIobj.py

    r2871 r2894  
    18521852        the file contents to do a "sanity" check if the file
    18531853        appears to match the selected format.
    1854         Expected to be called via self.Validator()
    18551854        '''
    18561855        #filepointer.seek(0) # rewind the file pointer
  • trunk/GSASIIstrMain.py

    r2877 r2894  
    753753def main():
    754754    'Needs a doc string'
     755    starttime = time.time()
    755756    arg = sys.argv
    756757    if len(arg) > 1:
     
    763764        print 'ERROR - missing filename'
    764765        exit()
    765     print "Done"
     766    print("Done. Execution time {:.2f} sec.".format(time.time()-starttime))
    766767         
    767768if __name__ == '__main__':
  • trunk/GSASIIstrMath.py

    r2862 r2894  
    29232923               
    29242924def GetFobsSq(Histograms,Phases,parmDict,calcControls):
    2925     'Needs a doc string'
     2925    'Compute the observed structure factors for Powder histograms'
     2926    #starttime = time.time(); print 'start GetFobsSq'
    29262927    histoList = Histograms.keys()
    29272928    histoList.sort()
     
    30323033            Histogram = Histograms[histogram]
    30333034            Histogram['Residuals']['hId'] = Histograms[histogram]['hId']
     3035    #print 'end GetFobsSq t=',time.time()-starttime
    30343036               
    30353037def getPowderProfile(parmDict,x,varylist,Histogram,Phases,calcControls,pawleyLookup):
    3036     'Needs a doc string'
     3038    'Computes the powder pattern for a histogram based on contributions from all used phases'
     3039   
     3040    #starttime = time.time(); print 'start getPowderProfile'
    30373041   
    30383042    def GetReflSigGamCW(refl,im,wave,G,GB,phfx,calcControls,parmDict):
     
    31913195    if badPeak:
    31923196        print 'ouch #4 bad profile coefficients yield negative peak width; some reflections skipped'
     3197    #print 'end getPowderProfile t=',time.time()-starttime
    31933198    return yc,yb
    31943199   
    31953200def getPowderProfileDerv(parmDict,x,varylist,Histogram,Phases,rigidbodyDict,calcControls,pawleyLookup):
    3196     'Needs a doc string'
     3201    '''Computes the derivatives of the computed powder pattern with respect to all
     3202    refined parameters
     3203    '''
     3204    #starttime = time.time(); print 'start getPowderProfileDerv'
    31973205   
    31983206    def cellVaryDerv(pfx,SGData,dpdA):
     
    32283236    bakType = calcControls[hfx+'bakType']
    32293237    dMdv = np.zeros(shape=(len(varylist),len(x)))
    3230     dMdv = ma.array(dMdv,mask=np.outer(np.ones(len(varylist)),ma.getmaskarray(x)))      #x is a MaskedArray!
     3238    # do not need dMdv to be a masked array at this point. Moved conversion to later in this routine.
     3239    #dMdv = ma.array(dMdv,mask=np.outer(np.ones(len(varylist)),ma.getmaskarray(x)))      #x is a MaskedArray!
    32313240    dMdb,dMddb,dMdpk = G2pwd.getBackgroundDerv(hfx,parmDict,bakType,calcControls[hfx+'histType'],x)
    32323241    if hfx+'Back;0' in varylist: # for now assume that Back;x vars to not appear in constraints
     
    32603269        else:
    32613270            wave = parmDict[hfx+'Lam']
     3271    #print '#1 getPowderProfileDerv t=',time.time()-starttime
    32623272    for phase in Histogram['Reflection Lists']:
    32633273        refDict = Histogram['Reflection Lists'][phase]
     
    32893299#            print 'sf-derv time %.3fs'%(time.time()-time0)
    32903300            ApplyRBModelDervs(dFdvDict,parmDict,rigidbodyDict,Phase)
     3301        #print '#2 getPowderProfileDerv t=',time.time()-starttime
     3302        # determine the parameters that will have derivatives computed only at end
     3303        nonatomvarylist = []
     3304        for name in varylist:
     3305            if '::RBV;' not in name:
     3306                try:
     3307                    aname = name.split(pfx)[1][:2]
     3308                    if aname not in ['Af','dA','AU','RB','AM','Xs','Xc','Ys','Yc','Zs','Zc',    \
     3309                        'Tm','Xm','Ym','Zm','U1','U2','U3']: continue # skip anything not an atom or rigid body param
     3310                except IndexError:
     3311                    continue
     3312            nonatomvarylist.append(name)
     3313        nonatomdependentVars = []
     3314        for name in dependentVars:
     3315            if '::RBV;' not in name:
     3316                try:
     3317                    aname = name.split(pfx)[1][:2]
     3318                    if aname not in ['Af','dA','AU','RB','AM','Xs','Xc','Ys','Yc','Zs','Zc',    \
     3319                        'Tm','Xm','Ym','Zm','U1','U2','U3']: continue # skip anything not an atom or rigid body param
     3320                except IndexError:
     3321                    continue
     3322            nonatomdependentVars.append(name)
     3323        #timelist =  10*[0.0]
     3324        #timestart = 10*[0.0]
     3325        #==========================================================================================
     3326        #==========================================================================================
    32913327        for iref,refl in enumerate(refDict['RefList']):
     3328            #timestart[0] = time.time()
    32923329            if im:
    32933330                h,k,l,m = refl[:4]
     
    33093346                break
    33103347            pos = refl[5+im]
     3348            #itim=0;timelist[itim] += time.time()-timestart[itim]; timestart[itim+1] = time.time()
    33113349            if 'C' in calcControls[hfx+'histType']:
    33123350                tanth = tand(pos/2.0)
     
    33393377                    dMdpk[i] += refl[11+im]*refl[9+im]*dMdipk[i]      #cw[iBeg:iFin]*
    33403378                dervDict = {'int':dMdpk[0],'pos':dMdpk[1],'alp':dMdpk[2],'bet':dMdpk[3],'sig':dMdpk[4],'gam':dMdpk[5]}           
     3379            #itim=1;timelist[itim] += time.time()-timestart[itim]; timestart[itim+1] = time.time()
    33413380            if Phase['General'].get('doPawley'):
    33423381                dMdpw = np.zeros(len(x))
     
    33753414                    hfx+'sig-2':[refl[4+im]**4,'sig'],hfx+'sig-q':[1./refl[4+im]**2,'sig'],
    33763415                    hfx+'Absorption':[dFdAb,'int'],phfx+'Extinction':[dFdEx,'int'],}
     3416            #itim=2;timelist[itim] += time.time()-timestart[itim]; timestart[itim+1] = time.time()
    33773417            for name in names:
    33783418                item = names[name]
     
    33943434                    if Ka2 and iFin2-iBeg2:
    33953435                        depDerivDict[iPO][iBeg2:iFin2] += dIdPO[iPO]*dervDict2['int']
     3436            #itim=3;timelist[itim] += time.time()-timestart[itim]; timestart[itim+1] = time.time()
    33963437            for i,name in enumerate(['omega','chi','phi']):
    33973438                aname = pfx+'SH '+name
     
    34333474                    if Ka2 and iFin2-iBeg2:
    34343475                        depDerivDict[name][iBeg2:iFin2] += dDijDict[name]*dervDict2['pos']
     3476            #itim=4;timelist[itim] += time.time()-timestart[itim]; timestart[itim+1] = time.time()
    34353477            for i,name in enumerate([pfx+'mV0',pfx+'mV1',pfx+'mV2']):
    34363478                if name in varylist:
     
    34743516                        if Ka2 and iFin2-iBeg2:
    34753517                            depDerivDict[phfx+name][iBeg2:iFin2] += parmDict[phfx+'Scale']*dFdvDict[phfx+name][iref]*dervDict2['int']/refl[9+im]                 
     3518            #itim=5;timelist[itim] += time.time()-timestart[itim]; timestart[itim+1] = time.time()
    34763519            if not Phase['General'].get('doPawley') and not parmDict[phfx+'LeBail']:
    34773520                #do atom derivatives -  for RB,F,X & U so far - how do I scale mixed phase constraints?
     
    34803523                if refl[9+im]:             
    34813524                    corr = dervDict['int']/refl[9+im]
     3525                    #if Ka2 and iFin2-iBeg2:
     3526                    #    corr2 = dervDict2['int']/refl[9+im]
     3527                #itim=6;timelist[itim] += time.time()-timestart[itim]; timestart[itim+1] = time.time()
     3528                for name in nonatomvarylist:
     3529                    dMdv[varylist.index(name)][iBeg:iFin] += dFdvDict[name][iref]*corr
    34823530                    if Ka2 and iFin2-iBeg2:
    3483                         corr2 = dervDict2['int']/refl[9+im]
    3484                 for name in varylist+dependentVars:
    3485                     if '::RBV;' in name:
    3486                         pass
    3487                     else:
    3488                         try:
    3489                             aname = name.split(pfx)[1][:2]
    3490                             if aname not in ['Af','dA','AU','RB','AM','Xs','Xc','Ys','Yc','Zs','Zc',    \
    3491                                 'Tm','Xm','Ym','Zm','U1','U2','U3']: continue # skip anything not an atom or rigid body param
    3492                         except IndexError:
    3493                             continue
    3494                     if name in varylist:
    3495                         dMdv[varylist.index(name)][iBeg:iFin] += dFdvDict[name][iref]*corr
    3496                         if Ka2 and iFin2-iBeg2:
    3497                             dMdv[varylist.index(name)][iBeg2:iFin2] += dFdvDict[name][iref]*corr2
    3498                     elif name in dependentVars:
    3499                         depDerivDict[name][iBeg:iFin] += dFdvDict[name][iref]*corr
    3500                         if Ka2 and iFin2-iBeg2:
    3501                             depDerivDict[name][iBeg2:iFin2] += dFdvDict[name][iref]*corr2
     3531                       dMdv[varylist.index(name)][iBeg2:iFin2] += dFdvDict[name][iref]*corr2
     3532                #itim=7;timelist[itim] += time.time()-timestart[itim]; timestart[itim+1] = time.time()
     3533                for name in nonatomdependentVars:
     3534                   depDerivDict[name][iBeg:iFin] += dFdvDict[name][iref]*corr
     3535                   if Ka2 and iFin2-iBeg2:
     3536                       depDerivDict[name][iBeg2:iFin2] += dFdvDict[name][iref]*corr2
     3537                #itim=8;timelist[itim] += time.time()-timestart[itim]   
    35023538    #        print 'profile derv time: %.3fs'%(time.time()-time0)
    35033539    # now process derivatives in constraints
     3540    #print '#3 getPowderProfileDerv t=',time.time()-starttime
     3541    #print timelist,sum(timelist)
     3542    dMdv = ma.array(dMdv,mask=np.outer(np.ones(len(varylist)),ma.getmaskarray(x)))      #x is a MaskedArray!
    35043543    G2mv.Dict2Deriv(varylist,depDerivDict,dMdv)
     3544    #print 'end getPowderProfileDerv t=',time.time()-starttime
    35053545    return dMdv
    35063546   
Note: See TracChangeset for help on using the changeset viewer.