def run_experiment(ncores, codebase, diag, namelist, resolution, exp_name,
                   codebase_name):
    """
    Measure the time taken to complete the experiment
    :param ncores: Number of processor cores to be used
    :param codebase: One of: Held-Suarez, Grey-Mars
    :param diag: Diagnostics
    :param namelist: Namelist file
    :param resolution: Resolution of simulatin. One of: T21, T42, T85
    :param exp_name: Name of the experiment
    :param codebase_name: Name of the codebase
    """
    runs = 0
    if codebase_name == constants.HELD_SUAREZ:
        runs = 13
    elif codebase_name == constants.GREY_MARS:
        runs = 23

    exp = Experiment(f'{exp_name}', codebase=codebase)
    exp.rm_datadir()
    exp.clear_rundir()
    exp.diag_table = diag
    exp.namelist = namelist.copy()
    exp.set_resolution(*resolution)
    start = time.time()
    print(exp.namelist)
    exp.run(1, use_restart=False, num_cores=ncores)
    end = time.time()
    time_delta = end - start
    data = [ncores, resolution[0], 1, time_delta]
    write_to_csvfile(f'{constants.GFDL_BENCH}/{exp_name}', data)
    for i in range(
            2, runs
    ):  # 13 as there are 12 months (12+1=13)(241 for grey_mars) / (13 for held_suarez)
        start = time.time()
        exp.run(i, num_cores=ncores)
        end = time.time()
        time_delta = end - start
        data = [ncores, resolution[0], i, time_delta]
        write_to_csvfile(f'{constants.GFDL_BENCH}/{exp_name}', data)
Beispiel #2
0
def conduct_comparison_on_test_case(base_commit,
                                    later_commit,
                                    test_case_name,
                                    repo_to_use='[email protected]:execlim/Isca',
                                    num_cores_to_use=4):
    """Process here is to checkout each commit in turn, compiles it if necessary, uses the appropriate nml for the test
    case under consideration, and runs the code with the two commits in turn. The output is then compared for all variables
    in the diag file. If there are any differences in the output variables then the test classed as a failure."""

    data_dir_dict = {}
    nml_use, input_files_use = get_nml_diag(test_case_name)
    diag_use = define_simple_diag_table()
    test_pass = True
    run_complete = True

    #Do the run for each of the commits in turn
    for s in [base_commit, later_commit]:
        exp_name = test_case_name + '_trip_test_21_' + s
        if 'socrates' in test_case_name:
            cb = SocratesCodeBase(repo=repo_to_use, commit=s)
        else:
            cb = IscaCodeBase(repo=repo_to_use, commit=s)
        cb.compile()
        exp = Experiment(exp_name, codebase=cb)
        exp.namelist = nml_use.copy()
        exp.diag_table = diag_use
        exp.inputfiles = input_files_use

        #Only run for 3 days to keep things short.
        exp.update_namelist({'main_nml': {
            'days': 3,
        }})

        try:
            # run with a progress bar
            with exp_progress(exp, description=s) as pbar:
                exp.run(1, use_restart=False, num_cores=num_cores_to_use)
        except FailedRunError as e:
            #If run fails then test automatically fails
            run_complete = False
            test_pass = False
            continue

        data_dir_dict[s] = exp.datadir
    if run_complete:
        #For each of the diag files defined, compare the output
        for diag_file_entry in diag_use.files.keys():
            base_commit_dataset = xar.open_dataset(
                data_dir_dict[base_commit] + '/run0001/' + diag_file_entry +
                '.nc',
                decode_times=False)
            later_commit_dataset = xar.open_dataset(
                data_dir_dict[later_commit] + '/run0001/' + diag_file_entry +
                '.nc',
                decode_times=False)

            diff = later_commit_dataset - base_commit_dataset

            #Check each of the output variables for differences
            for var in diff.data_vars.keys():
                maxval = np.abs(diff[var]).max()
                if maxval != 0.:
                    print('Test failed for ' + var + ' max diff value = ' +
                          str(maxval.values))
                    test_pass = False

        if test_pass:
            print('Test passed for ' + test_case_name + '. Commit ' +
                  later_commit + ' gives the same answer as commit ' +
                  base_commit)
            return_test_result = 'pass'
        else:
            print('Test failed for ' + test_case_name + '. Commit ' +
                  later_commit + ' gives a different answer to commit ' +
                  base_commit)
            return_test_result = 'fail'

    else:
        print('Test failed for ' + test_case_name +
              ' because the run crashed.')
        return_test_result = 'fail'

    return return_test_result
Beispiel #3
0
        'vert_coord_option':
        'input',  #Use the vertical levels from Frierson 2006
        'surf_res': 0.5,
        'scale_heights': 11.0,
        'exponent': 7.0,
        'robert_coeff': 0.03
    },
    'vert_coordinate_nml': {
        'bk': [
            0.000000, 0.0117665, 0.0196679, 0.0315244, 0.0485411, 0.0719344,
            0.1027829, 0.1418581, 0.1894648, 0.2453219, 0.3085103, 0.3775033,
            0.4502789, 0.5244989, 0.5977253, 0.6676441, 0.7322627, 0.7900587,
            0.8400683, 0.8819111, 0.9157609, 0.9422770, 0.9625127, 0.9778177,
            0.9897489, 1.0000000
        ],
        'pk': [
            0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000,
            0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000,
            0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000,
            0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000,
            0.000000, 0.000000
        ],
    }
})

#Lets do a run!
if __name__ == "__main__":
    exp.run(1, use_restart=False, num_cores=NCORES)
    for i in range(2, 25):
        exp.run(i, num_cores=NCORES)
        'num_levels':40,      #How many model pressure levels to use
        'valid_range_t':[100.,800.],
        'initial_sphum':[2.e-6],
        'vert_coord_option':'uneven_sigma',
        'surf_res':0.2, #Parameter that sets the vertical distribution of sigma levels
        'scale_heights' : 11.0,
        'exponent':7.0,
        'robert_coeff':0.03,
        'ocean_topog_smoothing': 0.8
    },

    'spectral_init_cond_nml':{
        'topog_file_name': 'era_land_t42.nc',
        'topography_option': 'input'
    },

})

#Lets do a run!
if __name__=="__main__":

        cb.compile(debug=False)
        #Set up the experiment object, with the first argument being the experiment name.
        #This will be the name of the folder that the data will appear in.

        overwrite=False

        exp.run(1, use_restart=False, num_cores=NCORES, overwrite_data=overwrite)#, run_idb=True)
        for i in range(2,61):
            exp.run(i, num_cores=NCORES, overwrite_data=overwrite)
Beispiel #5
0
        print(fi)
        os.system("cp -rf " + builddir + "/srcmod/" + fi + " " +
                  isca_caseroot + "/srcmod/" + fi + "_" + casename)
    os.system("cp -rf " + os.path.realpath(__file__) + " " + isca_caseroot +
              "/srcmod/build_isca.py_" + casename)

#Step 9. Run the fortran code
if 'run' in todo:
    exp = Experiment(casename, codebase=cb)
    exp.clear_rundir()

    exp.diag_table = diag
    exp.namelist = namelist.copy()

    if qflux_file_name != 'off':
        inputfiles.append(os.path.join(builddir, qflux_file_name + '.nc'))
        exp.namelist['mixed_layer_nml']['load_qflux'] = True
        exp.namelist['mixed_layer_nml']['time_varying_qflux'] = False
        exp.namelist['mixed_layer_nml']['qflux_file_name'] = qflux_file_name
    else:
        print('no qflux')
        exp.namelist['mixed_layer_nml']['load_qflux'] = False

    exp.inputfiles = inputfiles
    exp.set_resolution(*RESOLUTION)
    for i in range(1, 601):
        if i == 1:
            exp.run(1, use_restart=False, num_cores=NCORES, run_ddt=run_ddt)
        else:
            exp.run(i, num_cores=NCORES, run_ddt=run_ddt)
Beispiel #6
0
        'surf_res': 0.5,
        'scale_heights': 11.0,
        'exponent': 7.0,
        'robert_coeff': 0.03,
        'spinup_restart': spinup_restart
    },
    #    'vert_coordinate_nml': {
    #        'bk': [0.000000, 0.0117665, 0.0196679, 0.0315244, 0.0485411, 0.0719344, 0.1027829, 0.1418581, 0.1894648, 0.2453219, 0.3085103, 0.3775033, 0.4502789, 0.5244989, 0.5977253, 0.6676441, 0.7322627, 0.7900587, 0.8400683, 0.8819111, 0.9157609, 0.9422770, 0.9625127, 0.9778177, 0.9897489, 1.0000000],
    #        'pk': [0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000],
    #       }
})

#Lets do a run!
if __name__ == "__main__":
    if cold_restart:
        exp.run(1, use_restart=False, num_cores=NCORES)
        for i in range(2, i1):
            exp.run(i, num_cores=NCORES)
    else:
        for i in range(i0, i1):
            if use_external_restart and i == i0:
                exp.run(i,
                        num_cores=NCORES,
                        restart_file=external_restart_file)
                exp.update_namelist(
                    {'atmosphere_nml': {
                        'spinup_restart': False
                    }})
                exp.update_namelist(
                    {'spectral_dynamics_nml': {
                        'spinup_restart': False
        'damping_order': 4,             
        'water_correction_limit': 200.e2,
        'reference_sea_level_press':1.0e5,
        'num_levels':40,
        'valid_range_t':[100.,800.],
        'initial_sphum':[2.e-6],
        'vert_coord_option':'uneven_sigma',
        'surf_res':0.2, #Parameter that sets the vertical distribution of sigma levels
        'scale_heights' : 11.0,
        'exponent':7.0,
        'robert_coeff':0.03
    }
})

#Lets do a run!
exp.run(1, use_restart=False, num_cores=NCORES)
for i in range(2,481):
    exp.run(i, num_cores=NCORES)








####### co2 experiment #######
exp = Experiment('aquaplanet_finalIscaAPqflux_zerointegral_2xCO2_spinup_361', codebase=cb)


Beispiel #8
0
        0.7,  # boundary layer friction height (default p/ps = sigma = 0.7)

        # negative sign is a flag indicating that the units are days
        'ka': -40.,  # Constant Newtonian cooling timescale (default 40 days)
        'ks':
        -4.,  # Boundary layer dependent cooling timescale (default 4 days)
        'kf': -1.,  # BL momentum frictional timescale (default 1 days)
        'do_conserve_energy':
        True,  # convert dissipated momentum into heat (default True)
    },
    'diag_manager_nml': {
        'mix_snapshot_average_fields': False
    },
    'fms_nml': {
        'domains_stack_size': 600000  # default: 0
    },
    'fms_io_nml': {
        'threading_write': 'single',  # default: multi
        'fileset_write': 'single',  # default: multi
    }
})

exp.namelist = namelist
exp.set_resolution(*RESOLUTION)

#Lets do a run!
if __name__ == '__main__':
    exp.run(1, num_cores=NCORES, use_restart=False)
    for i in range(2, 13):
        exp.run(i, num_cores=NCORES)  # use the restart i-1 by default
Beispiel #9
0
cb = DryCodeBase.from_directory(GFDL_BASE)

namelist['main_nml'] = {'dt_atmos': 600, 'days': 30, 'calendar': 'no_calendar'}

earth_omega = 7.292e-5

scales = [1.0, 10.0, 100.0, 1000.0]

for s in scales:
    exp_name = 'hs_om_scale_%.0f' % s
    omega = earth_omega * (s / 100.0)
    exp = Experiment(exp_name, codebase=cb)
    exp.namelist = namelist.copy()
    exp.diag_table = diag

    exp.update_namelist({'constants_nml': {'omega': omega}})
    try:
        # run with a progress bar with description showing omega
        with exp_progress(exp, description='o%.0f d{day}' % s) as pbar:
            exp.run(1, use_restart=False, num_cores=16)

        for n in range(2, 11):
            with exp_progress(exp, description='o%.0f d{day}' % s) as pbar:
                exp.run(n)
                exp.delete_restart(n - 1)

    except FailedRunError as e:
        # don't let a crash get in the way of good science
        # (we could try and reduce timestep here if we wanted to be smarter)
        continue
Beispiel #10
0
    },
    'fms_io_nml': {
        'threading_write': 'single',  # default: multi
        'fileset_write': 'single',  # default: multi
    },
    'spectral_dynamics_nml': {
        'damping_order': 4,
        'water_correction_limit': 200.e2,
        'reference_sea_level_press': 1.0e5,
        'num_levels': 40,  #How many model pressure levels to use
        'valid_range_t': [100., 800.],
        'initial_sphum': [2.e-6],
        'vert_coord_option': 'uneven_sigma',
        'surf_res':
        0.2,  #Parameter that sets the vertical distribution of sigma levels
        'scale_heights': 11.0,
        'exponent': 7.0,
        'robert_coeff': 0.03
    },
})

#Lets do a run!
if __name__ == "__main__":

    cb.compile()
    #Set up the experiment object, with the first argument being the experiment name.
    #This will be the name of the folder that the data will appear in.
    exp.run(1, use_restart=False, num_cores=NCORES, overwrite_data=False)
    for i in range(2, 121):
        exp.run(i, num_cores=NCORES)
Beispiel #11
0
def conduct_comparison_on_test_case(base_commit,
                                    later_commit,
                                    test_case_name,
                                    repo_to_use='[email protected]:execlim/Isca',
                                    num_cores_to_use=4):
    """Process here is to checkout each commit in turn, compiles it if necessary, uses the appropriate nml for the test
    case under consideration, and runs the code with the two commits in turn. The output is then compared for all variables
    in the diag file. If there are any differences in the output variables then the test classed as a failure."""

    data_dir_dict = {}
    nml_use, input_files_use = get_nml_diag(test_case_name)
    diag_use = define_simple_diag_table()
    test_pass = True
    run_complete = True
    compile_successful = True

    #Do the run for each of the commits in turn
    for s in [base_commit, later_commit]:
        exp_name = test_case_name + '_trip_test_21_' + s
        if 'socrates' in test_case_name or 'ape_aquaplanet' in test_case_name:
            cb = SocratesCodeBase(repo=repo_to_use, commit=s)
        else:
            cb = IscaCodeBase(repo=repo_to_use, commit=s)
        try:
            cb.compile()
            exp = Experiment(exp_name, codebase=cb)
            exp.namelist = nml_use.copy()
            exp.diag_table = diag_use
            exp.inputfiles = input_files_use

            #Only run for 3 days to keep things short.
            exp.update_namelist({'main_nml': {
                'days': 3,
            }})
        except:
            run_complete = False
            test_pass = False
            compile_successful = False
            continue

        try:
            # run with a progress bar
            with exp_progress(exp, description=s) as pbar:
                exp.run(1, use_restart=False, num_cores=num_cores_to_use)
        except FailedRunError as e:
            #If run fails then test automatically fails
            run_complete = False
            test_pass = False
            continue

        data_dir_dict[s] = exp.datadir
    if run_complete:
        #For each of the diag files defined, compare the output
        for diag_file_entry in diag_use.files.keys():
            base_commit_dataset = xar.open_dataset(
                data_dir_dict[base_commit] + '/run0001/' + diag_file_entry +
                '.nc',
                decode_times=False)
            later_commit_dataset = xar.open_dataset(
                data_dir_dict[later_commit] + '/run0001/' + diag_file_entry +
                '.nc',
                decode_times=False)

            diff = later_commit_dataset - base_commit_dataset

            #Check each of the output variables for differences
            for var in diff.data_vars.keys():
                maxval = np.abs(diff[var]).max()
                if maxval != 0.:
                    print('Test failed for ' + var + ' max diff value = ' +
                          str(maxval.values))
                    test_pass = False

            base_experiment_input_nml = f90nml.read(
                data_dir_dict[base_commit] + '/run0001/input.nml')
            later_commit_input_nml = f90nml.read(data_dir_dict[later_commit] +
                                                 '/run0001/input.nml')

            if base_experiment_input_nml != later_commit_input_nml:
                raise AttributeError(
                    f'The two experiments to be compared have been run using different input namelists, and so the results may be different because of this. This only happens when you have run the trip tests using one of the commit IDs before, and that you happen to have used a different version of the test cases on that previous occasion. Try removing both {data_dir_dict[base_commit]} and {data_dir_dict[later_commit]} and try again.'
                )

        if test_pass:
            print('Test passed for ' + test_case_name + '. Commit ' +
                  later_commit + ' gives the same answer as commit ' +
                  base_commit)
            return_test_result = 'pass'
        else:
            print('Test failed for ' + test_case_name + '. Commit ' +
                  later_commit + ' gives a different answer to commit ' +
                  base_commit)
            return_test_result = 'fail'

    else:
        if compile_successful:
            #This means that the compiles were both successful, but at least one of the runs crashed.
            print('Test failed for ' + test_case_name +
                  ' because the run crashed.')
        else:
            print('Test failed for ' + test_case_name +
                  ' because at least one of the runs failed to compile.')

        return_test_result = 'fail'

    return return_test_result
Beispiel #12
0
        'vert_coord_option':
        'input',  #Use the vertical levels from Frierson 2006
        'surf_res': 0.5,
        'scale_heights': 11.0,
        'exponent': 7.0,
        'robert_coeff': 0.03
    },
    'vert_coordinate_nml': {
        'bk': [
            0.000000, 0.0117665, 0.0196679, 0.0315244, 0.0485411, 0.0719344,
            0.1027829, 0.1418581, 0.1894648, 0.2453219, 0.3085103, 0.3775033,
            0.4502789, 0.5244989, 0.5977253, 0.6676441, 0.7322627, 0.7900587,
            0.8400683, 0.8819111, 0.9157609, 0.9422770, 0.9625127, 0.9778177,
            0.9897489, 1.0000000
        ],
        'pk': [
            0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000,
            0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000,
            0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000,
            0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000,
            0.000000, 0.000000
        ],
    }
})

#Lets do a run!
if __name__ == "__main__":
    exp.run(1, use_restart=False, num_cores=NCORES, run_idb=True)
    for i in range(2, 121):
        exp.run(i, num_cores=NCORES, run_idb=True)
    depths = [2.]

    pers = [93] #longitude of perihelion

    scale = 1.

    for conv in conv_schemes:
        for depth_val in depths:
            for per_value in pers:
                exp = Experiment('grey_titan_userestart', codebase=cb) #name of folder in which .nc files are output
                exp.clear_rundir()

                exp.diag_table = diag
                exp.namelist = namelist.copy()
                exp.namelist['constants_nml']['grav']     = scale * 1.354 #surface gravity
                exp.namelist['constants_nml']['pstd']     = scale * 14670000.0 #surface pressure - 100 times bigger than below values
                exp.namelist['constants_nml']['pstd_mks'] = scale * 146700.0 #in Pa
                exp.namelist['spectral_dynamics_nml']['reference_sea_level_press'] = scale * 146700.0 #in Pa
                exp.namelist['idealized_moist_phys_nml']['convection_scheme'] = conv
                exp.namelist['mixed_layer_nml']['depth'] = depth_val
                exp.namelist['astronomy_nml']['per'] = per_value
                exp.set_resolution(*RESOLUTION)

#            with exp_progress(exp, description='o%.0f d{day}' % scale):
                #!!!the below ensures use of the specified restart file
                exp.run(1, restart_file='/mnt/storage/home/rm15856/scratch/Isca-Bristol/output/grey_titan/restarts/res0106.tar.gz', use_restart=True, num_cores=NCORES)
                for i in range(107, 110):
#                with exp_progress(exp, description='o%.0f d{day}' % scale):
                    exp.run(i, num_cores=NCORES)
                notify('top down with conv scheme = '+conv+' has completed', 'isca')