def get_and_log_mst_weight_from_checker(input_graph, force_recompute=False, inputslogfn=None): """Returns the a 2-tuple of (input, weight). If force_recompute is not True, then it will check the input log cache to see if we already know the answer first. Logs the result.""" ti = __get_ti(input_graph) # load in the inputs in the category of input_graph if inputslogfn is None: logfn = InputSolution.get_path_to(ti.prec, ti.dims, ti.min, ti.max) else: logfn = inputslogfn ds = DataSet.read_from_file(InputSolution, logfn) if ds.dataset.has_key(ti): input_soln = ds.dataset[ti] do_log = True # see if we already know the answer if not force_recompute: if input_soln.has_mst_weight(): return (ti, input_soln.mst_weight) # cache hit! else: # if we weren't tracking the input before, don't start now do_log = False # compute the answer and (if specified) save it w = compute_mst_weight(input_graph) if do_log: if input_soln.update_mst_weight(w): ds.save_to_file(logfn) return (ti, w)
print_input_footer(num_verts, num_edges, about, out) print_if_not_quiet('graph saved to ' + ppinput(options.output_file)) if out != sys.stdout: out.close() # generate output with correctness checker, if desired if options.correctness: if options.dont_track: print >> sys.stderr, "warning: skipping correctness output (only done when -t is not specified)" return 0 try: mst_weight = compute_mst_weight(options.output_file) except CheckerError, e: print >> sys.stderr, e # record this new input in our input log if not options.dont_track: data = InputSolution(options.precision, dimensionality, min_val, max_val, num_verts, num_edges, __RND_SEED, mst_weight) path = data.get_path( ) if options.inputs_list_file is None else options.inputs_list_file DataSet.add_data_to_log_file(data, path) print_if_not_quiet('logged to ' + path) return 0 if __name__ == "__main__": sys.exit(main())
options.inputs_list_file_arg = '' if options.inputs_list_file is None else ' -l ' + options.inputs_list_file collect_missing_data = lambda w,x,y,z: collect_missing_correctness_data(w,x,y,z,options.inputs_list_file_arg) # make sure no more than 1 type of data collection was specified if num_on > 1: parser.error('at most one of -c, -d, and -e may be specified') elif num_on == 0: # prepare for a performance data collection (default if nothing else is specified) get_results_for_rev = lambda rev : DataSet.read_from_file(PerfResult, PerfResult.get_path_to(rev)) collect_missing_data = collect_missing_performance_data # prepare the inputs and revisions for non-weight data collection schemes if options.num_vertices == 0: # get all performance inputs if we are not collecting for a single graph if input_solns is None: input_path = InputSolution.get_path_to(1, 0, 0, 100000) input_solns = DataSet.read_from_file(InputSolution, input_path) # prepare the revisions to collect data for if options.rev is not None: if options.rev.lower() == 'all': revs = get_tracked_revs() else: revs = [options.rev] else: revs = ['current'] # just use the current revision # pull out just the Input object (results are keyed on these, not InputSolution) inputs = [i.input() for i in input_solns.dataset.values()] # collect the data!
def main(): usage = """usage: %prog [options] Searches for missing results and uses run_test.py to collect it.""" parser = OptionParser(usage) parser.add_option("-i", "--input_graph", metavar="FILE", help="restrict the missing data check to the specified input graph") parser.add_option("-l", "--inputs-list-file", metavar="FILE", help="collect data for all inputs in the specified log file") parser.add_option("--list-only", action="store_true", default=False, help="only list missing data (do not collect it)") parser.add_option("-n", "--num-runs", type="int", default="1", help="number of desired runs per revision-input combination [default: 1]") parser.add_option("-r", "--rev", help="restrict the missing data check to the specified revision, or 'all' [default: current]") group = OptionGroup(parser, "Data Collection Options") group.add_option("-p", "--performance", action="store_true", default=True, help="collect performance data (this is the default)") group.add_option("-c", "--correctness", action="store_true", default=False, help="collect correctness data") parser.add_option_group(group) group2 = OptionGroup(parser, "Weight (Part II) Data Collection Options") group2.add_option("-v", "--num_vertices", metavar="V", type="int", default=0, help="collect weight data for V vertices (requires -d or -e)") group2.add_option("-d", "--dims", metavar="D", type="int", default=0, help="collect weight data for randomly positioned vertices in D-dimensional space (requires -v)") group2.add_option("-e", "--edge", action="store_true", default=False, help="collect weight data for random uniform edge weights in the range (0, 1] (requires -v)") parser.add_option_group(group2) (options, args) = parser.parse_args() if len(args) > 0: parser.error("too many arguments") if options.num_runs < 1: parser.error("-n must be at least 1") input_solns = None # prepare for a weight data collection num_on = 0 weight_test = False if options.num_vertices > 0: weight_test = True if options.input_graph or options.inputs_list_file: parser.error('-i, -l, and -v are mutually exclusive') if options.dims > 0: num_on += 1 wtype = 'loc%u' % options.dims if options.edge: num_on += 1 wtype = 'edge' if num_on == 0: parser.error('-v requires either -d or -e be specified too') if options.num_runs > 1: options.num_runs = 1 print 'warning: -v truncates the number of runs to 1 (weight should not change b/w runs)' input_path = InputSolution.get_path_to(15, options.dims, 0.0, 1.0) print 'reading inputs to run on from ' + input_path input_solns = DataSet.read_from_file(InputSolution, input_path) revs = [None] # not revision-specific (assuming our alg is correct) get_results_for_rev = lambda _ : DataSet.read_from_file(WeightResult, WeightResult.get_path_to(wtype)) collect_missing_data = collect_missing_weight_data elif options.dims > 0 or options.edge: parser.error('-v is required whenever -d or -e is used') # handle -i, -l: collect data for a particular graph(s) if options.input_graph and options.inputs_list_file: parser.error('-i and -l are mutually exclusive') if options.input_graph is not None: try: i = extract_input_footer(options.input_graph) except ExtractInputFooterError, e: parser.error(e) input_solns = DataSet({0:InputSolution(i.prec,i.dims,i.min,i.max,i.num_verts,i.num_edges,i.seed)})
mst_weight = -1 if options.dont_generate: print_if_not_quiet('graph not saved (as requested)') else: print_input_footer(num_verts, num_edges, about, out) print_if_not_quiet('graph saved to ' + ppinput(options.output_file)) if out != sys.stdout: out.close() # generate output with correctness checker, if desired if options.correctness: if options.dont_track: print >> sys.stderr, "warning: skipping correctness output (only done when -t is not specified)" return 0 try: mst_weight = compute_mst_weight(options.output_file) except CheckerError, e: print >> sys.stderr, e # record this new input in our input log if not options.dont_track: data = InputSolution(options.precision, dimensionality, min_val, max_val, num_verts, num_edges, __RND_SEED, mst_weight) path = data.get_path() if options.inputs_list_file is None else options.inputs_list_file DataSet.add_data_to_log_file(data, path) print_if_not_quiet('logged to ' + path) return 0 if __name__ == "__main__": sys.exit(main())