def collect_missing_correctness_data(inpt, rev, first_run_id, num_runs, inputs_list_file_arg): # use a for-loop here b/c run_test only does -c on the first run it is called gen = collect_missing_prep(inpt) for i in range(num_runs): if i != 0: print '' cmd = 'run_test.py -g "%s" -r %s -n %u -C -x -t %u%s' % (gen, rev, num_runs, first_run_id+1, inputs_list_file_arg) ret = os.system(get_path_to_tools_root() + cmd) return ret == 0
def get_tracked_revs(): """Returns revisions we are tracking as an array of SHA1 revision IDs""" ret = [] try: fh = open(get_path_to_tools_root() + 'conf/tracked_revs', "r") lines = fh.readlines() for line in lines: if line[0:1] != '#': s = line.split('\t', 5) if len(s) != 5: raise DataError('line should have five columns (has %d): %s' % (len(s), line)) ret.append(s[2]) fh.close() return ret except IOError, e: raise DataError('I/O error while reading tracked revisions: ' + e)
def get_tracked_revs(): """Returns revisions we are tracking as an array of SHA1 revision IDs""" ret = [] try: fh = open(get_path_to_tools_root() + 'conf/tracked_revs', "r") lines = fh.readlines() for line in lines: if line[0:1] != '#': s = line.split('\t', 5) if len(s) != 5: raise DataError( 'line should have five columns (has %d): %s' % (len(s), line)) ret.append(s[2]) fh.close() return ret except IOError, e: raise DataError('I/O error while reading tracked revisions: ' + e)
def get_tracked_algs_and_revs(): """Returns dict mapping algorithms we are tracking to lists of SHA1 revision IDs in which they are tested.""" # maps alg name to list of revisions ret = {} try: fh = open(get_path_to_tools_root() + 'conf/tracked_revs', "r") lines = fh.readlines() for line in lines: if line[0:1] != '#': s = line.split('\t', 5) if len(s) != 5: raise DataError('line should have five columns (has %d): %s' % (len(s), line)) rev = s[2] tag = s[3] if ret.has_key(tag): ret[tag].append(rev) else: ret[tag] = [rev] fh.close() return ret except IOError, e: raise DataError('I/O error while reading tracked revisions: ' + e)
def get_tracked_algs_and_revs(): """Returns dict mapping algorithms we are tracking to lists of SHA1 revision IDs in which they are tested.""" # maps alg name to list of revisions ret = {} try: fh = open(get_path_to_tools_root() + 'conf/tracked_revs', "r") lines = fh.readlines() for line in lines: if line[0:1] != '#': s = line.split('\t', 5) if len(s) != 5: raise DataError( 'line should have five columns (has %d): %s' % (len(s), line)) rev = s[2] tag = s[3] if ret.has_key(tag): ret[tag].append(rev) else: ret[tag] = [rev] fh.close() return ret except IOError, e: raise DataError('I/O error while reading tracked revisions: ' + e)
def main(): usage = """usage: %prog [options] Tests the performance of the MST implementation. Alternatively, when -g is used with a special argument (below), this determines the weight of the MST. GEN_ARGS can be arbitrary arguments (to test performance) or one of the following special arguments to generate a complete graph (for MST weight computation only): edge,NUM_VERTICES: random uniform edge weights [0, 1] locN,NUM_VERTICES: randomly position vertices in N-dimensional space with axis ranges [0,1]""" parser = OptionParser(usage) parser.add_option( "-c", "--check", action="store_true", default=False, help= "whether to check output using check_output.py (only for the first run; exits if the check fails)" ) parser.add_option( "-C", "--check-exit-0", action="store_true", default=False, help= "same as -c, but exit with code 0 even if the correctness check fails") parser.add_option( "-g", "--generate-input", metavar="GEN_ARGS", help= "generate (and use as input) a graph from generate_input.py GEN_ARGS (one for each run); -mqt will also be passed" ) parser.add_option( "-G", "--generate-temp-input", metavar="GEN_ARGS", help="same as -g, but delete the graph after this script is done") parser.add_option("-i", "--input-file", metavar="FILE", help="FILE which describes the graph to use as input") parser.add_option( "-l", "--inputs-list-file", metavar="FILE", help= "specifies where to log correctness info (which inputs list log file) [default: inferred]" ) parser.add_option("-n", "--num-runs", metavar="N", type="int", default=1, help="number of runs to execute [default: %default]") parser.add_option( "-o", "--output-file", metavar="FILE", help= "where to save the output MST (stdout prints to stdout) [default: do not save output]" ) parser.add_option("-q", "--quiet", action="store_true", default=False, help="do not print extraneous info to stdout") parser.add_option( "-r", "--rev", help= "SHA1 of the git revision to build the mst binary from [default: use existing binary and do not log]" ) parser.add_option("-x", "--dont-log", action="store_true", default=False, help="do not log the result") parser.add_option( "-t", "--trial-num", type="int", default=-1, help= "run/trial identifier [default: do not log the trial, so ignore it]") (options, args) = parser.parse_args() if len(args) > 0: parser.error("too many arguments: none expected") # reconcile -g and -G cleanup_generated_input = False if options.generate_temp_input is not None: if options.generate_input is not None: parser.error('only one of -g or -G may be supplied') else: options.generate_input = options.generate_temp_input cleanup_generated_input = True # get the input file is_test_perf = True gen_input_args = None if options.generate_input is not None and options.input_file is not None: parser.error("-g and -i are mutually exclusive") elif options.input_file is not None: input_graph = options.input_file elif options.generate_input is not None: s = options.generate_input.split(',', 2) gen_type = s[0] if gen_type == "edge": if len(s) != 2: parser.error( '-g edge,NUM_VERTICES form requires exactly these args') gen_input_args = "-p 15 -e 0.0,1.0 %s" % s[1] elif len(gen_type) == 4 and gen_type[:3] == "loc": if len(s) != 2: parser.error( '-g %s,NUM_VERTICES form requires exactly these args' % gen_type) d = gen_type[3:] gen_input_args = "-p 15 -v %s,0.0,1.0 %s" % (d, s[1]) # if it was not a special case, just pass the args straight through if gen_input_args is None: gen_input_args = options.generate_input is_test_perf = not is_input_for_part2(gen_input_args.split()) else: is_test_perf = False input_graph = __generate_input_graph(gen_input_args, cleanup_generated_input) else: parser.error( "at least one of -g and -i must be used to specify the input graph" ) if options.num_runs < 1: parser.error("-n must be at least 1") if options.trial_num < 0: options.dont_log = True # get the mst binary we want to test with mst_binary = random_tmp_filename(10, 'mst') __files_to_cleanup.append(mst_binary) if options.rev is None or options.rev.lower() == 'current': options.dont_log = True # no logging allowed on binaries which aren't checked in to the repo options.trial_num = -1 options.rev = "" # tells the script to just use the current revision cmd = 'copy_and_build_from_rev.sh %s %s %s' % (get_path_to_mst_binary(), mst_binary, options.rev) if options.quiet: cmd += ' > /dev/null' ret = os.system(get_path_to_tools_root() + cmd) # exclude-from-submit # include-with-submit ret = 0 # include-with-submit mst_binary = './mst' if ret != 0: print 'error: unable to copy and build the mst binary' __cleanup_and_exit(ret) # handle check-exit-0 check_fail_exit_code = -1 if options.check_exit_0: options.check = True check_fail_exit_code = 0 # prepare the output file if options.output_file: out = options.output_file out_is_temporary = False else: if options.check: out = random_tmp_filename(10, 'out-for-checker') __files_to_cleanup.append(out) out_is_temporary = True else: if options.inputs_list_file: print >> sys.stderr, 'warning: -l does nothing unless -c is also specified' out = "/dev/null" # do the first run (and check the output if requested) test_mst(is_test_perf, mst_binary, input_graph, out, not options.dont_log, options.rev, options.trial_num) if options.check: rev = None if options.rev is "" else options.rev run = None if options.trial_num < 0 else options.trial_num try: ret = check(input_graph, out, 1, False, rev, run, options.inputs_list_file) except CheckerError, e: ret = INCORRECT print >> sys.stderr, str(e) if out_is_temporary: quiet_remove(out) if ret != CORRECT: __cleanup_and_exit(check_fail_exit_code ) # incorrectness already reported by check() else: print 'Correct - output checks out!'
def collect_missing_weight_data(inpt, _, first_run_id, __): gen = collect_missing_prep(inpt) cmd = 'run_test.py -g "%s" -n 1 -t %u' % (gen, first_run_id) ret = os.system(get_path_to_tools_root() + cmd) return ret == 0
def collect_missing_performance_data(inpt, rev, first_run_id, num_runs): gen = collect_missing_prep(inpt) cmd = 'run_test.py -g "%s" -r %s -n %u -t %u' % (gen, rev, num_runs, first_run_id) ret = os.system(get_path_to_tools_root() + cmd) return ret == 0
def main(): usage = """usage: %prog [options] Tests the performance of the MST implementation. Alternatively, when -g is used with a special argument (below), this determines the weight of the MST. GEN_ARGS can be arbitrary arguments (to test performance) or one of the following special arguments to generate a complete graph (for MST weight computation only): edge,NUM_VERTICES: random uniform edge weights [0, 1] locN,NUM_VERTICES: randomly position vertices in N-dimensional space with axis ranges [0,1]""" parser = OptionParser(usage) parser.add_option("-c", "--check", action="store_true", default=False, help="whether to check output using check_output.py (only for the first run; exits if the check fails)") parser.add_option("-C", "--check-exit-0", action="store_true", default=False, help="same as -c, but exit with code 0 even if the correctness check fails") parser.add_option("-g", "--generate-input", metavar="GEN_ARGS", help="generate (and use as input) a graph from generate_input.py GEN_ARGS (one for each run); -mqt will also be passed") parser.add_option("-G", "--generate-temp-input", metavar="GEN_ARGS", help="same as -g, but delete the graph after this script is done") parser.add_option("-i", "--input-file", metavar="FILE", help="FILE which describes the graph to use as input") parser.add_option("-l", "--inputs-list-file", metavar="FILE", help="specifies where to log correctness info (which inputs list log file) [default: inferred]") parser.add_option("-n", "--num-runs", metavar="N", type="int", default=1, help="number of runs to execute [default: %default]") parser.add_option("-o", "--output-file", metavar="FILE", help="where to save the output MST (stdout prints to stdout) [default: do not save output]") parser.add_option("-q", "--quiet", action="store_true", default=False, help="do not print extraneous info to stdout") parser.add_option("-r", "--rev", help="SHA1 of the git revision to build the mst binary from [default: use existing binary and do not log]") parser.add_option("-x", "--dont-log", action="store_true", default=False, help="do not log the result") parser.add_option("-t", "--trial-num", type="int", default=-1, help="run/trial identifier [default: do not log the trial, so ignore it]") (options, args) = parser.parse_args() if len(args) > 0: parser.error("too many arguments: none expected") # reconcile -g and -G cleanup_generated_input = False if options.generate_temp_input is not None: if options.generate_input is not None: parser.error('only one of -g or -G may be supplied') else: options.generate_input = options.generate_temp_input cleanup_generated_input = True # get the input file is_test_perf = True gen_input_args = None if options.generate_input is not None and options.input_file is not None: parser.error("-g and -i are mutually exclusive") elif options.input_file is not None: input_graph = options.input_file elif options.generate_input is not None: s = options.generate_input.split(',',2) gen_type = s[0] if gen_type == "edge": if len(s) != 2: parser.error('-g edge,NUM_VERTICES form requires exactly these args') gen_input_args = "-p 15 -e 0.0,1.0 %s" % s[1] elif len(gen_type)==4 and gen_type[:3] == "loc": if len(s) != 2: parser.error('-g %s,NUM_VERTICES form requires exactly these args' % gen_type) d = gen_type[3:] gen_input_args = "-p 15 -v %s,0.0,1.0 %s" % (d, s[1]) # if it was not a special case, just pass the args straight through if gen_input_args is None: gen_input_args = options.generate_input is_test_perf = not is_input_for_part2(gen_input_args.split()) else: is_test_perf = False input_graph = __generate_input_graph(gen_input_args, cleanup_generated_input) else: parser.error("at least one of -g and -i must be used to specify the input graph") if options.num_runs < 1: parser.error("-n must be at least 1") if options.trial_num < 0: options.dont_log = True # get the mst binary we want to test with mst_binary = random_tmp_filename(10, 'mst') __files_to_cleanup.append(mst_binary) if options.rev is None or options.rev.lower() == 'current': options.dont_log = True # no logging allowed on binaries which aren't checked in to the repo options.trial_num = -1 options.rev = "" # tells the script to just use the current revision cmd = 'copy_and_build_from_rev.sh %s %s %s' % (get_path_to_mst_binary(), mst_binary, options.rev) if options.quiet: cmd += ' > /dev/null' ret = os.system(get_path_to_tools_root() + cmd) # exclude-from-submit # include-with-submit ret = 0 # include-with-submit mst_binary = './mst' if ret != 0: print 'error: unable to copy and build the mst binary' __cleanup_and_exit(ret) # handle check-exit-0 check_fail_exit_code = -1 if options.check_exit_0: options.check = True check_fail_exit_code = 0 # prepare the output file if options.output_file: out = options.output_file out_is_temporary = False else: if options.check: out = random_tmp_filename(10, 'out-for-checker') __files_to_cleanup.append(out) out_is_temporary = True else: if options.inputs_list_file: print >> sys.stderr, 'warning: -l does nothing unless -c is also specified' out = "/dev/null" # do the first run (and check the output if requested) test_mst(is_test_perf, mst_binary, input_graph, out, not options.dont_log, options.rev, options.trial_num) if options.check: rev = None if options.rev is "" else options.rev run = None if options.trial_num < 0 else options.trial_num try: ret = check(input_graph, out, 1, False, rev, run, options.inputs_list_file) except CheckerError, e: ret = INCORRECT print >> sys.stderr, str(e) if out_is_temporary: quiet_remove(out) if ret != CORRECT: __cleanup_and_exit(check_fail_exit_code) # incorrectness already reported by check() else: print 'Correct - output checks out!'
def main(argv=sys.argv[1:]): usage = """usage: %prog [options] Generates input for part 2 of the project en masse. Examples: Generate inputs for 2D vertex placement in powers of 2 up to and including 10000 vertices (10 inputs for each step): %prog -d2 -u10000 -n10 Generate inputs for random edge weights in steps of 10 vertices up to and including 100 vertices (1 input for each step): %prog -a -s10 -u100""" parser = OptionParser(usage) parser.add_option("-a", "--additive-step-type", action="store_true", default=False, help="use additive stepping between numbers of vertices [default: multiplicative]") parser.add_option("-d", "--dims", type="int", default=0, help="number of dimensions to use; 0 => use random edge weights [default: %default]") parser.add_option("-g", "--go", action="store_true", default=False, help="run right away rather than generating inputs") parser.add_option("-l", "--min", type="int", default=1, help="minimum number of vertices to generate a graph for [default: %default]") parser.add_option("-n", "--num-per-step", type="int", default=1, metavar="n", help="number of inputs to generate for each step [default: %default]") parser.add_option("-s", "--step", type="float", default=2.0, help="step amount between vertex sizes (see -a) [default: %default]") parser.add_option("-u", "--max", type="int", default=1024, help="maximum number of vertices to generate a graph for [default: %default]") (options, args) = parser.parse_args(argv) if len(args) > 1: parser.error("too many arguments") if options.dims == 0: what = '-e 0.0,1.0' else: what = '-v %u,0.0,1.0' % options.dims if options.min < 1 or options.min > options.max: parser.error('-l must be in the range [1, max]') if options.max < 1: parser.error('-u must be at least 1') if options.additive_step_type: if options.step < 1.0: parser.error('-s must be greater than or equal to 1 when -a is used') elif options.step <= 1.0: parser.error('-s must be greater than 1 when -a is not used') v = options.min while True: for _ in range(options.num_per_step): if not options.go: args = '-p15 %s %u' % (what, int(v)) try: print 'generating new input: ' + args ret = generate_input(args.split()) except Exception, errstr: print >> sys.stderr, 'generate_weight_inputs failed for: ' + args + ': ' + str(errstr) return -1 if ret != 0: print >> sys.stderr, 'generate_weight_inputs failed for: ' + args return -1 else: cmd = get_path_to_tools_root() + 'run_test.py' cmd += " -G '-p15 %s %u' -n1" % (what, int(v)) if os.system(cmd) != 0: print >> sys.stderr, 'generate_weight_inputs GO mode failed for: ' + cmd return -1 if v >= options.max: break if options.additive_step_type: v += options.step else: v *= options.step if v > options.max: v = options.max
def main(argv=sys.argv[1:]): usage = """usage: %prog [options] Generates input for part 2 of the project en masse. Examples: Generate inputs for 2D vertex placement in powers of 2 up to and including 10000 vertices (10 inputs for each step): %prog -d2 -u10000 -n10 Generate inputs for random edge weights in steps of 10 vertices up to and including 100 vertices (1 input for each step): %prog -a -s10 -u100""" parser = OptionParser(usage) parser.add_option( "-a", "--additive-step-type", action="store_true", default=False, help= "use additive stepping between numbers of vertices [default: multiplicative]" ) parser.add_option( "-d", "--dims", type="int", default=0, help= "number of dimensions to use; 0 => use random edge weights [default: %default]" ) parser.add_option("-g", "--go", action="store_true", default=False, help="run right away rather than generating inputs") parser.add_option( "-l", "--min", type="int", default=1, help= "minimum number of vertices to generate a graph for [default: %default]" ) parser.add_option( "-n", "--num-per-step", type="int", default=1, metavar="n", help="number of inputs to generate for each step [default: %default]") parser.add_option( "-s", "--step", type="float", default=2.0, help="step amount between vertex sizes (see -a) [default: %default]") parser.add_option( "-u", "--max", type="int", default=1024, help= "maximum number of vertices to generate a graph for [default: %default]" ) (options, args) = parser.parse_args(argv) if len(args) > 1: parser.error("too many arguments") if options.dims == 0: what = '-e 0.0,1.0' else: what = '-v %u,0.0,1.0' % options.dims if options.min < 1 or options.min > options.max: parser.error('-l must be in the range [1, max]') if options.max < 1: parser.error('-u must be at least 1') if options.additive_step_type: if options.step < 1.0: parser.error( '-s must be greater than or equal to 1 when -a is used') elif options.step <= 1.0: parser.error('-s must be greater than 1 when -a is not used') v = options.min while True: for _ in range(options.num_per_step): if not options.go: args = '-p15 %s %u' % (what, int(v)) try: print 'generating new input: ' + args ret = generate_input(args.split()) except Exception, errstr: print >> sys.stderr, 'generate_weight_inputs failed for: ' + args + ': ' + str( errstr) return -1 if ret != 0: print >> sys.stderr, 'generate_weight_inputs failed for: ' + args return -1 else: cmd = get_path_to_tools_root() + 'run_test.py' cmd += " -G '-p15 %s %u' -n1" % (what, int(v)) if os.system(cmd) != 0: print >> sys.stderr, 'generate_weight_inputs GO mode failed for: ' + cmd return -1 if v >= options.max: break if options.additive_step_type: v += options.step else: v *= options.step if v > options.max: v = options.max