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
import os import numpy as np from isca import IscaCodeBase, DiagTable, Experiment, Namelist, GFDL_BASE NCORES = 8 base_dir = os.path.dirname(os.path.realpath(__file__)) # a CodeBase can be a directory on the computer, # useful for iterative development cb = IscaCodeBase.from_directory(GFDL_BASE) # or it can point to a specific git repo and commit id. # This method should ensure future, independent, reproducibility of results. # cb = DryCodeBase.from_repo(repo='https://github.com/isca/isca', commit='isca1.1') # compilation depends on computer specific settings. The $GFDL_ENV # environment variable is used to determine which `$GFDL_BASE/src/extra/env` file # is used to load the correct compilers. The env file is always loaded from # $GFDL_BASE and not the checked out git repo. cb.compile( ) # compile the source code to working directory $GFDL_WORK/codebase # create an Experiment object to handle the configuration of model parameters # and output diagnostics exp = Experiment('frierson_rotate_slow', codebase=cb) #Tell model how to write diagnostics diag = DiagTable() diag.add_file('atmos_monthly', 30, 'days', time_units='days')
import os import numpy as np from isca import IscaCodeBase, DiagTable, Experiment, Namelist, GFDL_BASE NCORES = 16 base_dir = os.getcwd() # a CodeBase can be a directory on the computer, # useful for iterative development # cb = IscaCodeBase.from_directory(GFDL_BASE) # or it can point to a specific git repo and commit id. # This method should ensure future, independent, reproducibility of results. cb = IscaCodeBase.from_repo( repo='https://github.com/mp586/Isca.git', commit='f1bb5c4' ) #looked up commit which was used for original 2xCO2 experiment # compilation depends on computer specific settings. The $GFDL_ENV # environment variable is used to determine which `$GFDL_BASE/src/extra/env` file # is used to load the correct compilers. The env file is always loaded from # $GFDL_BASE and not the checked out git repo. cb.compile( ) # compile the source code to working directory $GFDL_WORK/codebase # create an Experiment object to handle the configuration of model parameters # and output diagnostics #### NORTHLAND : change name of experiment when you're running a different set-up e.g. northland_different_albedo ##### exp = Experiment('northland_different_albedo', codebase=cb)
if os.path.exists(os.environ['GFDL_DATA'] + casename): shutil.rmtree(os.environ['GFDL_DATA'] + casename) #Step 2. Provide the necessary input files and user source code: if not os.path.exists(builddir): os.makedirs(builddir) if not os.path.exists(builddir + '/Isca'): os.symlink(os.environ['GFDL_BASE'], builddir + '/Isca') #cb = IscaCodeBase.from_directory(builddir+'/Isca',storedir=builddir) # for saving obj files in Isca_caseroot/ if radiation_scheme == 'grey': cb = GreyCodeBase.from_directory(builddir + '/Isca') do_grey = True do_rrtm = False do_socrates = False if radiation_scheme == 'rrtm': cb = IscaCodeBase.from_directory(builddir + '/Isca') do_grey = False do_rrtm = True do_socrates = False if radiation_scheme == 'socrates': cb = SocratesCodeBase.from_directory(builddir + '/Isca') do_grey = False do_rrtm = False do_socrates = True if 'compile' in todo or 'configure' in todo: if mothercase is not None: mom_builddir = isca_caseroot + mothercase mom_objdir = mom_builddir.replace('/', '_') + '_Isca' if os.path.exists(os.environ['GFDL_WORK'] + '/codebase/' + mom_objdir): print('found mother case: ' + mothercase + ', copying .......')
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
def test_isca_codebase(): cb = IscaCodeBase.from_directory(GFDL_BASE) cb.compile()