def run(name, config): """ Runs the analysis of the coverage of the ice sheet over the land mass. Produces both an overall coverage percentage metric and a coverage plot. Args: name: The name of the test config: A dictionary representation of the configuration file Returns: An elements.page with the list of elements to display """ greenland_data = os.path.join(livvkit.__path__[0], config['data_dir'], config['gl_data']) velocity_data = os.path.join(livvkit.__path__[0], config['data_dir'], config['vel_data']) if not (os.path.exists(greenland_data) and os.path.exists(velocity_data)): # Add more handling here -- what do we want to return for failed tests return elements.error("lvargo13", "Could not find necessary data for validation!") # Generate the script output_dir = os.path.join(livvkit.index_dir, 'validation', 'imgs') output_file_base = os.path.join(output_dir, 'lvargo13') functions.mkdir_p(output_dir) ncl_command = 'ncl \'gl_data = addfile("' + greenland_data + '", "r")\' ' \ + '\'vel_data = addfile("' + velocity_data + '", "r")\' ' \ + '\'model_prefix = "' \ + os.path.join(livvkit.__path__[0], config['data_dir'], config['model_prefix']) \ + '"\' ' \ + '\'model_suffix = "' + config['model_suffix'] + '"\' ' \ + '\'model_start = ' + config['model_start'] + '\' ' \ + '\'model_end = ' + config['model_end'] + '\' ' \ + '\'plot_file_base = "' + output_file_base + '"\' ' \ + os.path.join(livvkit.__path__[0], config['plot_script']) # Be cautious about running subprocesses p = subprocess.Popen(ncl_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) ncl_out, ncl_err = p.communicate() # TODO: Put some error checking here output_plots = [ os.path.basename(p) for p in glob.glob(output_file_base + "*.png") ] plot_list = [] for plot in output_plots: plot_list.append(elements.image(plot, "", plot)) the_page = elements.page("lvargo13", config['description'], elements.gallery("Plots", plot_list)) return the_page
def run(name, config): """ Runs the analysis of the coverage of the ice sheet over the land mass. Produces both an overall coverage percentage metric and a coverage plot. Args: name: The name of the test config: A dictionary representation of the configuration file Returns: An elements.page with the list of elements to display """ bench_data = os.path.join(livvkit.__path__[0], config['data_dir'], config['bench_data']) model_data = os.path.join(livvkit.__path__[0], config['data_dir'], config['model_data']) if not (os.path.exists(model_data) and os.path.exists(bench_data)): # Add more handling here -- what do we want to return for failed tests print( "ERROR: Could not find necessary data to run the coverage validation!" ) print(model_data) print(bench_data) print("") return elements.error( "coverage", "Could not find necessary data to run the coverage validation!") # Generate the script plot_name = "coverage.png" output_dir = os.path.join(livvkit.index_dir, 'validation', 'imgs') output_path = os.path.join(output_dir, plot_name) functions.mkdir_p(output_dir) plot_coverage(config['plot_script'], model_data, bench_data, output_path) plot_list = [elements.image(plot_name, " ", plot_name)] the_page = elements.page('coverage', config['description'], elements.gallery("Plots", plot_list)) return the_page
strong_data, "Strong scaling efficiency for " + case.capitalize(), "Parallel efficiency (% of linear)", "", os.path.join(plot_dir, case + "_strong_scaling_efficiency.png")), ] timing_plots = timing_plots + \ [generate_timing_breakdown_plot(timing_data[s], config['scaling_var'], "Timing breakdown for " + case.capitalize()+" "+s, "", os.path.join(plot_dir, case+"_"+s+"_timing_breakdown.png") ) for s in sorted(six.iterkeys(timing_data), key=functions.sort_scale)] # Build an image gallery and write the results el = [elements.gallery("Performance Plots", timing_plots)] result = elements.page(case, config["description"], element_list=el) summary[case] = _summarize_result(timing_data, config) _print_result(case, summary) functions.create_page_from_template( "performance.html", os.path.join(livvkit.index_dir, "performance", case + ".html")) functions.write_json(result, os.path.join(livvkit.output_dir, "performance"), case + ".json") def _analyze_case(model_dir, bench_dir, config): """ Generates statistics from the timing summaries """ model_timings = set( glob.glob(os.path.join(model_dir, "*" + config["timing_ext"]))) if bench_dir is not None:
for model in sorted(six.iterkeys(analysis[a])): plt.plot(analysis[a][model][coord], analysis[a][model][config['plot_vars'][p]], line_style[model], color=case_color[model], linewidth=2, label=a+'-'+model) plt.legend(loc='best') if livvkit.publish: plt.savefig( os.path.splitext(plot_file)[0]+'.eps', dpi=600 ) plt.savefig(plot_file) plt.close() plot_list.append(elements.image(title, description, os.path.basename(plot_file))) return elements.gallery("Numerics Plots", plot_list) def summarize_result(data, config): case = config['name'] summary = LIVVDict() lengths = list(set([get_case_length(d) for d in six.iterkeys(data)])) for p, pattern in enumerate(sorted(setup[case]['pattern'])): for l in sorted(lengths): recreate_file = os.path.join( livvkit.__path__[0], setup[case]["data_dir"], pattern ).replace('???', l) axis, fs_amin, fs_amax, fs_mean, fs_std, ho_amin, ho_amax, ho_mean, ho_std = \
def run(config, analysis_data): case = config['name'] if case in ['ismip-hom-a', 'ismip-hom-c', 'ismip-hom-f']: coord = 'x_hat' else: coord = 'y_hat' lengths = list(set( [get_case_length(d) for d in six.iterkeys(analysis_data)] )) plot_list = [] for p, pattern in enumerate(sorted(setup[case]['pattern'])): fig_label = pattern.split('_')[1] description = '' for l in sorted(lengths): plt.figure(figsize=(10, 8), dpi=150) plt.xlabel(setup[case]['xlabel'][p]) plt.ylabel(setup[case]['ylabel'][p]) if case in ['ismip-hom-a', 'ismip-hom-c']: plt.title(str(int(l))+' km') title = fig_label[0:-1]+'. '+fig_label[-1]+': '+str(int(l))+' km' else: plt.title('No-Slip Bed') title = fig_label[0:-2]+'. '+fig_label[-2:]+': No-Slip Bed' plot_file = os.path.join(config["plot_dir"], config['name']+'_'+fig_label+'_'+l+'.png') recreate_file = os.path.join( livvkit.__path__[0], setup[case]["data_dir"], pattern ).replace('???', l) axis, fs_amin, fs_amax, fs_mean, fs_std, ho_amin, ho_amax, ho_mean, ho_std = \ np.genfromtxt(recreate_file, delimiter=',', missing_values='nan', unpack=True) if case in ['ismip-hom-f']: axis = axis*100.0 - 50.0 plt.fill_between(axis, ho_amin, ho_amax, facecolor='green', alpha=0.5) plt.fill_between(axis, fs_amin, fs_amax, facecolor='blue', alpha=0.5) plt.plot(axis, fs_mean, 'b-', linewidth=2, label='Full stokes') plt.plot(axis, ho_mean, 'g-', linewidth=2, label='Higher order') analysis = {} for a in six.iterkeys(analysis_data): if int(l) == int(a.split('-')[-1][1:]): analysis[a] = analysis_data[a] for a in six.iterkeys(analysis): for model in sorted(six.iterkeys(analysis[a])): plt.plot(analysis[a][model][coord], analysis[a][model][config['plot_vars'][p]], line_style[model], color=case_color[model], linewidth=2, label=a+'-'+model) plt.legend(loc='best') if livvkit.publish: plt.savefig(os.path.splitext(plot_file)[0]+'.eps', dpi=600) plt.savefig(plot_file) plt.close() plot_list.append(elements.image(title, description, os.path.basename(plot_file))) return elements.gallery("Numerics Plots", plot_list)
details[var]['std (case 1, case 2)'] = ( np.std(averages[args.case1][var]['annuals']), np.std(averages[args.case2][var]['annuals'])) if details[var]['T test (t, p)'][0] is None: details[var]['h0'] = '-' elif details[var]['K-S test (D, p)'][1] < 0.05: details[var]['h0'] = 'reject' else: details[var]['h0'] = 'accept' img_file = os.path.relpath(os.path.join(args.img_dir, var + '.png'), os.getcwd()) prob_plot(args, var, averages, 20, img_file) img_desc = 'Mean annual global average of {} for <em>{}</em> is {:.3e} and for <em>{}</em> is {:.3e}'.format( var, args.case1, details[var]['mean (case 1, case 2)'][0], args.case2, details[var]['mean (case 1, case 2)'][1]) img_link = os.path.join(os.path.basename(args.img_dir), os.path.basename(img_file)) img_list.append(el.image(var, img_desc, img_link)) img_gal = el.gallery('Analyzed variables', img_list) return details, img_gal if __name__ == '__main__': print_details(main(parse_args()))
def run_suite(case, config, summary): """ Run the full suite of performance tests """ config["name"] = case timing_data = dict() model_dir = os.path.join(livvkit.model_dir, config['data_dir'], case) bench_dir = os.path.join(livvkit.bench_dir, config['data_dir'], case) plot_dir = os.path.join(livvkit.output_dir, "performance", "imgs") model_cases = functions.collect_cases(model_dir) bench_cases = functions.collect_cases(bench_dir) functions.mkdir_p(plot_dir) # Generate all of the timing data for subcase in sorted(model_cases): bench_subcases = bench_cases[subcase] if subcase in bench_cases else [] timing_data[subcase] = dict() for mcase in model_cases[subcase]: config["case"] = "-".join([subcase, mcase]) bpath = (os.path.join(bench_dir, subcase, mcase.replace("-", os.path.sep)) if mcase in bench_subcases else None) mpath = os.path.join(model_dir, subcase, mcase.replace("-", os.path.sep)) timing_data[subcase][mcase] = _analyze_case(mpath, bpath, config) # Create scaling and timing breakdown plots weak_data = weak_scaling(timing_data, config['scaling_var'], config['weak_scaling_points']) strong_data = strong_scaling(timing_data, config['scaling_var'], config['strong_scaling_points']) timing_plots = [ generate_scaling_plot(weak_data, "Weak scaling for " + case.capitalize(), "runtime (s)", "", os.path.join(plot_dir, case + "_weak_scaling.png") ), weak_scaling_efficiency_plot(weak_data, "Weak scaling efficiency for " + case.capitalize(), "Parallel efficiency (% of linear)", "", os.path.join(plot_dir, case + "_weak_scaling_efficiency.png") ), generate_scaling_plot(strong_data, "Strong scaling for " + case.capitalize(), "Runtime (s)", "", os.path.join(plot_dir, case + "_strong_scaling.png") ), strong_scaling_efficiency_plot(strong_data, "Strong scaling efficiency for " + case.capitalize(), "Parallel efficiency (% of linear)", "", os.path.join(plot_dir, case + "_strong_scaling_efficiency.png") ), ] timing_plots = timing_plots + \ [generate_timing_breakdown_plot(timing_data[s], config['scaling_var'], "Timing breakdown for " + case.capitalize()+" "+s, "", os.path.join(plot_dir, case+"_"+s+"_timing_breakdown.png") ) for s in sorted(six.iterkeys(timing_data), key=functions.sort_scale)] # Build an image gallery and write the results el = [ elements.gallery("Performance Plots", timing_plots) ] result = elements.page(case, config["description"], element_list=el) summary[case] = _summarize_result(timing_data, config) _print_result(case, summary) functions.create_page_from_template("performance.html", os.path.join(livvkit.index_dir, "performance", case + ".html")) functions.write_json(result, os.path.join(livvkit.output_dir, "performance"), case + ".json")