Changeset 12639


Ignore:
Timestamp:
07/16/12 15:23:55 (13 years ago)
Author:
jschierm
Message:

Working version of runme.py.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/test/NightlyRun/runme.py

    r12631 r12639  
    3434import socket
    3535import numpy
     36import h5py
    3637import sys
     38from parallelrange import parallelrange
    3739from IdToName import IdToName
    3840
     
    7375
    7476        #GET ids  {{{1
    75 #       flist=os.listdir('.')     #use dir, as it seems to act OS independent
    76         flist=glob.glob('test*.m')    #File name must start with 'test' and must end by '.m'
    77         list_ids=[]
    78         for file in flist:
    79 #               if file[:4] == 'test' and \    #File name must start with 'test'
    80 #                  file[-2:] == '.m' and \    #File name must end by '.m'
    81 #                  not file == 'test.m':    #File name must be different than 'test.m'
    82                 if not file == 'test.m':    #File name must be different than 'test.m'
    83                         list_ids.append(int(file[4:-2]))    #Keep test id only (skip 'test' and '.m')
    84 #       [i1,i2]=parallelrange(rank,numprocs,length(list_ids));               #Get tests for this cpu only
    85 #       list_ids=list_ids(i1:i2);
     77        flist=glob.glob('test*.py')    #File name must start with 'test' and must end by '.py' and must be different than 'test.py'
     78        list_ids=[int(file[4:-3]) for file in flist if not file == 'test.py']    #Keep test id only (skip 'test' and '.py')
    8679        print 'list_ids =',list_ids
     80
     81        i1,i2=parallelrange(rank,numprocs,len(list_ids))    #Get tests for this cpu only
     82        list_ids=list_ids[i1:i2+1]
     83        print 'list_ids after parallelrange =',list_ids
    8784
    8885        if id:
     
    9491        else:
    9592                test_ids=set(list_ids)
    96         print 'test_ids after list =',test_ids
     93#       print 'test_ids after list =',test_ids
    9794        # }}}
    9895
     
    104101                        exclude_ids=[exclude]
    105102                test_ids=test_ids.difference(set(exclude_ids))
    106         print 'test_ids after exclude =',test_ids
     103#       print 'test_ids after exclude =',test_ids
    107104        # }}}
    108105
     
    122119        elif benchmark.lower() == 'tranforcing':
    123120                test_ids=test_ids.intersection(set(range(1501,1503)))
    124         print 'test_ids after benchmark =',test_ids
     121#       print 'test_ids after benchmark =',test_ids
    125122        test_ids=list(test_ids)
    126123        test_ids.sort()
     
    136133                        os.chdir(root)
    137134                        id_string=IdToName(id)
    138                         execfile('test'+str(id)+'.py')
     135                        execfile('test'+str(id)+'.py',globals())
    139136
    140137                        #UPDATE ARCHIVE?
     
    143140
    144141                                if not socket.gethostname().lower().split('.')[0] == 'larsen':
    145                                         raise RuntimeError('Nightly run archives must be saved on "larsen" (hostname is "'+socket.gethostname()+'")')
     142#                                       raise RuntimeError("Nightly run archives must be saved on 'larsen' (hostname is '"+socket.gethostname()+"').")
     143                                        print "Nightly run archives must be saved on 'larsen' (hostname is '"+socket.gethostname()+"')."
     144                                f = h5py.File(os.path.join('..','Archives',archive_name+'.hdf5'),'w')
    146145                                for k,fieldname in enumerate(field_names):
    147                                         field=field_values[k]
    148                                         exec(archive_name+'_field'+str(k)+' =  field')
    149 #                               eval(['save ../Archives/' archive_name ' ' archive_name '_field*']);
    150                                 print 'File ./../Archives/'+archive_name+' saved\n'
     146                                        field=numpy.array(field_values[k],dtype=float)
     147                                        f.create_dataset(archive_name+'_field'+str(k),data=field)
     148                                f.close()
     149                                print "File '%s' saved.\n" % os.path.join('..','Archives',archive_name+'.hdf5')
    151150
    152151                        #ELSE: CHECK TEST
    153152                        else:
    154153
    155 #                               #load archive
    156 #                               load(['../Archives/' archive_name ]);
     154                                #load archive
     155                                if os.path.exists(os.path.join('..','Archives',archive_name+'.hdf5')):
     156                                        f = h5py.File(os.path.join('..','Archives',archive_name+'.hdf5'),'r')
     157                                else:
     158                                        raise IOError("Archive file '"+os.path.join('..','Archives',archive_name+'.hdf5')+"' does not exist.")
    157159
    158160                                for k,fieldname in enumerate(field_names):
     
    161163                                                #Get field and tolerance
    162164                                                field=numpy.array(field_values[k],dtype=float)
     165#                                               print 'field =',field
    163166                                                tolerance=field_tolerances[k]
     167#                                               print 'tolerance =',tolerance
    164168
    165169                                                #compare to archive
    166                                                 exec('archive=numpy.array('+archive_name+'_field'+str(k)+',dtype=float)')
    167                                                 error_diff=max(abs(archive-field))/(max(abs(archive))+sys.float_info.epsilon)
     170                                                if archive_name+'_field'+str(k) in f:
     171                                                        archive=f[archive_name+'_field'+str(k)][...]
     172                                                else:
     173                                                        raise NameError("Field name '"+archive_name+'_field'+str(k)+"' does not exist in archive file.")
     174#                                               print 'archive =',archive
     175                                                error_diff=numpy.amax(numpy.abs(archive-field),axis=1)/ \
     176                                                                   (numpy.amax(numpy.abs(archive),axis=1)+sys.float_info.epsilon)
     177#                                               print 'error_diff =',error_diff
    168178
    169179                                                #disp test result
     
    181191                                                message=me2
    182192                                                if   output.lower() == 'nightly':
    183                                                         fid=open(ISSM_DIR+'/nightlylog/matlaberror.log', 'a')
     193                                                        fid=open(os.path.join(ISSM_DIR,'nightlylog','matlaberror.log'), 'a')
    184194                                                        fid.write('%s' % message)
    185195                                                        fid.write('\n------------------------------------------------------------------\n')
     
    187197                                                        print 'FAILURE difference: N/A test id: %i test name: %s field: %s' % (id,id_string,fieldname)
    188198                                                elif output.lower() == 'daily':
    189                                                         fid=open(ISSM_DIR+'/dailylog/matlaberror.log', 'a')
     199                                                        fid=open(os.path.join(ISSM_DIR,'dailylog','matlaberror.log'), 'a')
    190200                                                        fid.write('%s' % message)
    191201                                                        fid.write('\n------------------------------------------------------------------\n')
     
    196206                                                        raise RuntimeError(me2)
    197207
     208                                f.close()
     209
    198210                except Exception as me:
    199211
     
    202214                        message=me
    203215                        if   output.lower() == 'nightly':
    204                                 fid=open(ISSM_DIR+'/nightlylog/matlaberror.log', 'a')
     216                                fid=open(os.path.join(ISSM_DIR+'nightlylog','matlaberror.log'), 'a')
    205217                                fid.write('%s' % message)
    206218                                fid.write('\n------------------------------------------------------------------\n')
     
    208220                                print 'FAILURE difference: N/A test id: %i test name: %s field: %s' % (id,id_string,'N/A')
    209221                        elif output.lower() == 'daily':
    210                                 fid=open(ISSM_DIR+'/dailylog/matlaberror.log', 'a')
     222                                fid=open(os.path.join(ISSM_DIR+'dailylog','matlaberror.log'), 'a')
    211223                                fid.write('%s' % message)
    212224                                fid.write('\n------------------------------------------------------------------\n')
Note: See TracChangeset for help on using the changeset viewer.