Changeset 27610


Ignore:
Timestamp:
02/23/23 20:22:10 (2 years ago)
Author:
jdquinn
Message:

CHG: Moving again towards making Python 3 the default

File:
1 edited

Legend:

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

    r27443 r27610  
    1 #!/usr/bin/env python
    2 #
    3 # NOTE: Switch to,
    4 #
    5 #   #!/usr/bin/python3
    6 #
    7 # when making Python 3 default
    8 #
     1#!/usr/bin/env python3
     2
     3
    94import argparse
    105import os
     
    3126
    3227def runme(id=None, exclude=None, benchmark='nightly', procedure='check', output='none', rank=1, numprocs=1):
    33     """RUNME - test deck for ISSM nightly runs
     28    """runme - test deck for ISSM nightly runs
    3429
    3530    In a test deck directory (for example, test/NightlyRun) the following
     
    9186    """
    9287
    93     #Get ISSM_DIR variable
     88    # Get ISSM_DIR variable
    9489    ISSM_DIR = os.environ['ISSM_DIR']
    9590
    96     #Process options
    97     #GET benchmark {{{
     91    # Process options
     92    # Get benchmark {{{
    9893    if benchmark not in ['all', 'nightly', 'validation', 'adolc', 'eismint', 'ismip', 'mesh', 'slc', 'thermal', 'tranforcing', 'qmu']:
    9994        print(("runme warning: benchmark '{}' not supported, defaulting to test 'nightly'.".format(benchmark)))
    10095        benchmark = 'nightly'
    10196    # }}}
    102     #GET procedure {{{
     97    # Get procedure {{{
    10398    if procedure not in ['check', 'update', 'runFromNC']:
    10499        print(("runme warning: procedure '{}' not supported, defaulting to test 'check'.".format(procedure)))
    105100        procedure = 'check'
    106101    # }}}
    107     #GET output {{{
     102    # Get output {{{
    108103    if output not in ['nightly', 'none']:
    109104        print(("runme warning: output '{}' not supported, defaulting to test 'none'.".format(output)))
    110105        output = 'none'
    111106    # }}}
    112     #GET RANK and NUMPROCS for multithreaded runs {{{
     107    # Get rank and numprocs for multi-threaded runs {{{
    113108    if (numprocs < rank):
    114109        numprocs = 1
    115110    # }}}
    116     #GET ids  {{{
     111    # Get ids  {{{
    117112    flist = [f for f in os.listdir('.') if re.match('test[0-9]+.py', f)] # File name must follow the format "test<integer>.py"
    118113    list_ids = [int(re.search(r'\d+',f.split('.')[0]).group()) for f in flist] # Retrieve test IDs
    119114    i1, i2 = parallelrange(rank, numprocs, len(list_ids))  # Get tests for this CPU only
    120115    list_ids = list_ids[i1:i2 + 1]
    121     if np.size(id) > 0 and id is not None:
     116    if len(id) > 0 and id is not None:
    122117        test_ids = set(GetIds(id)).intersection(set(list_ids))
    123118        benchmark = None
    124119    else:
    125         # if no tests are specifically provided, do them all
     120        # If no tests are specifically provided, do them all
    126121        test_ids = set(list_ids)
    127122
    128123    # }}}
    129     #GET exclude {{{
     124    # Get excluded tests {{{
    130125    exclude_ids = GetIds(exclude)
    131126    test_ids = test_ids.difference(exclude_ids)
    132127    # }}}
    133128    if procedure == 'runFromNC':
    134         #That is a bamg test
     129        # bamg test
    135130        test_ids = test_ids.difference([119, 514])
    136         # that is smbGEMB format is weird for the test
     131        # smbGEMB format is weird for the test
    137132        test_ids = test_ids.difference([243, 244, 252, 253])
    138         #those are amr runs where the index is missing from fieldnames
     133        # AMR runs where the index is missing from fieldnames
    139134        test_ids = test_ids.difference([462, 463, 464, 465])
    140         #test247 solves for thermal and transient which makes it complex to check
     135        # test247 solves for thermal and transient which makes it complex to check
    141136        test_ids = test_ids.difference([247])
    142         #test 902 is running two models with different stepping
     137        # test 902 is running two models with different stepping
    143138        test_ids = test_ids.difference([902])
    144         #I have a size issue in 517 needs investigation
     139        # size issue in 517 needs investigation
    145140        test_ids = test_ids.difference([517])
    146141
    147     #Process Ids according to benchmarks {{{
     142    # Process IDs according to benchmarks {{{
    148143    if benchmark == 'nightly':
    149144        test_ids = test_ids.intersection(set(range(1, 1000)))
     
    172167    # }}}
    173168
    174     #Loop over tests and launch sequence
     169    # Loop over tests and launch sequence
    175170    root = os.getcwd()
    176171    errorcount = 0
     
    179174        print(("----------------starting:{}-----------------------".format(id)))
    180175        try:
    181             #Execute test
     176            # Execute test
    182177            os.chdir(root)
    183178            id_string = IdToName(id)
     
    188183                exec(compile(open('test{}.py'.format(id)).read(), 'test{}.py'.format(id), 'exec'), globals())
    189184
    190             #UPDATE ARCHIVE?
     185            # Update archive?
    191186            archive_name = 'Archive' + str(id)
    192187            if procedure == 'update':
     
    213208                        solvetype = re.split('Solution', key)[0]
    214209
    215                 #we save the results, scrap them and solve.
     210                # Save the results, scrap them and solve
    216211                loaded_res = mdl.results
    217212                mdl.results = []
    218213                mdl = solve(mdl, solvetype)
    219214
    220                 #we loop on the field_names from the nghtly test
     215                # Loop on the field_names from the nightly test
    221216                for k, fieldname in enumerate(Tmod.field_names):
    222217                    try:
    223                         #first look for indexing
     218                        # First, look for indexing
    224219                        if re.search(r'\d+$', fieldname):
    225220                            index = int(re.search(r'\d+$', fieldname).group()) - 1
     
    237232                            index = 0
    238233
    239                         #Then check if the key exists in the loaded results
     234                        # Then, check if the key exists in the loaded results
    240235                        try:
    241236                            reskeys = mdl.results.__dict__[solvetype + 'Solution'][index].__dict__.keys()
    242237                        except TypeError:
    243                             # most probably a steady state so no subscripting
     238                            # Most likely a steady state so no subscripting
    244239                            reskeys = mdl.results.__dict__[solvetype + 'Solution'].__dict__.keys()
    245240                        if fieldname not in reskeys:
     
    259254
    260255                            if fieldname in namedifs.keys():
    261                                 #Some fields are not consistent
     256                                # Some fields are not consistent
    262257                                fieldname = namedifs[fieldname]
    263258                            elif any([suf in fieldname for suf in sufixes]):
    264                                 #some test have loops that mess up with naming
     259                                # Some tests have loops that mess up naming
    265260                                try:
    266261                                    sufix = sufixes[np.squeeze(np.where([suf in fieldname for suf in sufixes]))]
    267262                                except TypeError:
    268                                     #probably severalmatches, we take the last one which should be the good one (Needs to be controled in the list above)
     263                                    # Probably several matches; we take the last one which should be the one we're want to run (needs to be controlled in the list above)
    269264                                    sufix = sufixes[np.squeeze(np.where([suf in fieldname for suf in sufixes]))[-1]]
    270265                                fieldname = fieldname[:re.search(sufix, fieldname).start()]
    271266                            elif fieldname.endswith("P") and index == 1:
    272                                 #we are looking for P2 but 2 as been considered as an index and so shifted by -1
     267                                # Looking for P2 but 2 refers to an index, so shift by -1
    273268                                fieldname = fieldname[:-1]
    274269                            else:
    275                                 # could be that the index selected above is part of the name
     270                                # Handle case where index selected above is part of the name
    276271                                fieldname = fieldname + str(index + 1)
    277272                        try:
     
    279274                            loaded_field = loaded_res.__dict__[solvetype + 'Solution'][index].__dict__[fieldname]
    280275                        except TypeError:
    281                             # most probably a steady state so no subscripting
     276                            # Most likely a steady state so no subscripting
    282277                            try:
    283278                                field = mdl.results.__dict__[solvetype + 'Solution'].__dict__[fieldname]
     
    291286
    292287                        ref = Tmod.field_values[k]
    293                         #Get tolerance
     288                        # Get tolerance
    294289                        tolerance = Tmod.field_tolerances[k]
    295                         #compute differences for the results computed from the nc file
     290                        # Compute differences for the results computed from the nc file
    296291                        error_diff = np.amax(np.abs(ref - field), axis=0) / (np.amax(np.abs(ref), axis=0) + float_info.epsilon)
    297292                        if not np.isscalar(error_diff):
    298293                            error_diff = error_diff[0]
    299294
    300                         #compute the differences for the results of the nc file
     295                        # Compute the differences for the results of the nc file
    301296                        load_diff = np.amax(np.abs(np.squeeze(ref) - loaded_field), axis=0) / (np.amax(np.abs(np.squeeze(ref)), axis=0) + float_info.epsilon)
    302297                        if not np.isscalar(load_diff):
    303298                            load_diff = load_diff[0]
    304299
    305                         #disp test result
     300                        # Display test result
    306301                        if (np.any(error_diff > tolerance) or np.isnan(error_diff)) and (np.any(load_diff > tolerance) or np.isnan(load_diff)):
    307302                            if abs(error_diff - load_diff) < tolerance:
     
    321316                        else:
    322317                            print(('SUCCESS difference: {:7.2g} < {:7.2g} test id: {} test name: {} field: {}{}'.format(error_diff, tolerance, id, id_string, fieldname, index + 1)))
    323                         #disp only if errors for the results
     318                        # Display only if there are errors in the results
    324319
    325320                    except Exception as message:
    326                         #something went wrong, print failure message:
     321                        # Something went wrong; print failure message
    327322                        print((format_exc()))
    328323                        if output == 'nightly':
     
    335330                            print(('FAILURE difference: N/A test id: {} test name: {} field: {}'.format(id, id_string, fieldname)))
    336331                            raise RuntimeError(message)
    337             #ELSE: CHECK TEST
     332            # Check test
    338333            else:
    339                 #load archive
     334                # Load archive
    340335                if os.path.exists(os.path.join('..', 'Archives', archive_name + '.arch')):
    341336                    archive_file = os.path.join('..', 'Archives', archive_name + '.arch')
     
    345340                for k, fieldname in enumerate(field_names):
    346341                    try:
    347                         #Get field and tolerance
     342                        # Get field and tolerance
    348343                        field = np.array(field_values[k])
    349344                        if len(field.shape) == 1:
     
    354349                        tolerance = field_tolerances[k]
    355350
    356                         #compare to archive
     351                        # Compare to archive
    357352                        # Matlab uses base 1, so use base 1 in labels
    358353                        archive = np.array(archread(archive_file, archive_name + '_field' + str(k + 1)))
     
    369364                            error_diff = error_diff[0]
    370365
    371                         #disp test result
     366                        # Display test result
    372367                        if (np.any(error_diff > tolerance) or np.isnan(error_diff)):
    373368                            print(('ERROR   difference: {:7.2g} > {:7.2g} test id: {} test name: {} field: {}'.format(error_diff, tolerance, id, id_string, fieldname)))
     
    378373
    379374                    except Exception as message:
    380                         #something went wrong, print failure message:
     375                        # Something went wrong; print failure message
    381376                        print((format_exc()))
    382377                        if output == 'nightly':
     
    391386
    392387        except Exception as message:
    393             #something went wrong, print failure message:
     388            # Something went wrong; print failure message
    394389            print((format_exc()))
    395390            if output == 'nightly':
     
    420415            print(("PYTHONSTARTUP file '{}' does not exist.".format(PYTHONSTARTUP)))
    421416
    422         parser = argparse.ArgumentParser(description='RUNME - test deck for ISSM nightly runs')
     417        parser = argparse.ArgumentParser(description='runme - test deck for ISSM nightly runs')
    423418        parser.add_argument('-i', '--id', nargs='*', type=str, help='followed by the list of ids requested', default=[])
    424419        parser.add_argument('-in', '--include_name', nargs='*', type=str, help='followed by the list of test names requested', default=[])
Note: See TracChangeset for help on using the changeset viewer.