Пример #1
0
def main(argv=sys.argv):
    if len(argv) != 2:
        die("""usage: check_with_diff.py INPUT_GRAPH
Checks the current mst for a given input file and reports the diff, if any.  It
does not do anything smart in terms of caching the correctness checker's output,
so it will be recomputed every time this is run.
""")
    else:
        input_graph = argv[1]

    if not os.path.exists(input_graph):
        die("%s not found" % input_graph)

    # get our mst output
    mst = get_path_to_mst_binary(make_sure_it_exists=False)
    mst_out = random_tmp_filename(10)
    if os.system('%s %s > %s' % (mst, input_graph, mst_out)) != 0:
        quiet_remove(mst_out)
        die("failed to run mst (or exited with an error code)")

    # get the checker's output
    checker = get_path_to_checker_binary(make_sure_it_exists=True)
    checker_out = random_tmp_filename(10)
    if os.system('%s %s true > %s' % (checker, input_graph, checker_out)) != 0:
        quiet_remove(mst_out)
        quiet_remove(checker_out)
        die("failed to run checker (or exited with an error code)")

    # check just the MST weight first
    mst_w = extract_answer(mst_out)
    checker_w = extract_answer(checker_out)
    fmt = '%.1f'  # tolerance to 1 decimal place
    str_mst_w = fmt % mst_w
    str_checker_w = fmt % checker_w
    if str_mst_w == str_checker_w:
        print 'Weights match! %s %s' % (str_mst_w, str_checker_w)
        quiet_remove(mst_out)
        quiet_remove(checker_out)
        return 0
    else:
        print 'Weight mistmatch, comparing vertices!! (checker_mst (%s) - our_mst (%s) = %s)' % (
            str(checker_w), str(mst_w), str(checker_w - mst_w))

    # sort them
    mst_out2 = random_tmp_filename(10)
    checker_out2 = random_tmp_filename(10)
    sort_and_order = get_path_to_project_root(
    ) + 'src/input/sort_and_order.py '
    os.system(sort_and_order + mst_out + ' 1 > ' + mst_out2)
    os.system(sort_and_order + checker_out + ' 1 > ' + checker_out2)

    # compare them
    os.system('diff %s %s && echo Edges are the same!' %
              (checker_out2, mst_out2))
    quiet_remove(mst_out)
    quiet_remove(mst_out2)
    quiet_remove(checker_out)
    quiet_remove(checker_out2)
    return 0
Пример #2
0
def main(argv=sys.argv):
    if len(argv) != 2:
        die("""usage: check_with_diff.py INPUT_GRAPH
Checks the current mst for a given input file and reports the diff, if any.  It
does not do anything smart in terms of caching the correctness checker's output,
so it will be recomputed every time this is run.
""")
    else:
        input_graph = argv[1]

    if not os.path.exists(input_graph):
        die("%s not found" % input_graph)

    # get our mst output
    mst = get_path_to_mst_binary(make_sure_it_exists=False)
    mst_out = random_tmp_filename(10)
    if os.system('%s %s > %s' % (mst, input_graph, mst_out)) != 0:
        quiet_remove(mst_out)
        die("failed to run mst (or exited with an error code)")

    # get the checker's output
    checker = get_path_to_checker_binary(make_sure_it_exists=True)
    checker_out = random_tmp_filename(10)
    if os.system('%s %s true > %s' % (checker, input_graph, checker_out)) != 0:
        quiet_remove(mst_out)
        quiet_remove(checker_out)
        die("failed to run checker (or exited with an error code)")

    # check just the MST weight first
    mst_w = extract_answer(mst_out)
    checker_w = extract_answer(checker_out)
    fmt = '%.1f' # tolerance to 1 decimal place
    str_mst_w = fmt % mst_w
    str_checker_w = fmt % checker_w
    if str_mst_w == str_checker_w:
        print 'Weights match! %s %s' % (str_mst_w, str_checker_w)
        quiet_remove(mst_out)
        quiet_remove(checker_out)
        return 0
    else:
        print 'Weight mistmatch, comparing vertices!! (checker_mst (%s) - our_mst (%s) = %s)' % (str(checker_w), str(mst_w), str(checker_w - mst_w))

    # sort them
    mst_out2 = random_tmp_filename(10)
    checker_out2 = random_tmp_filename(10)
    sort_and_order = get_path_to_project_root() + 'src/input/sort_and_order.py '
    os.system(sort_and_order + mst_out + ' 1 > ' + mst_out2)
    os.system(sort_and_order + checker_out + ' 1 > ' + checker_out2)

    # compare them
    os.system('diff %s %s && echo Edges are the same!' % (checker_out2, mst_out2))
    quiet_remove(mst_out)
    quiet_remove(mst_out2)
    quiet_remove(checker_out)
    quiet_remove(checker_out2)
    return 0
Пример #3
0
def benchmark(mst_binary, input_graph, out, rev, trial_num, for_time):
    rel_input_graph = ppinput(input_graph)
    if not print_benchmark(rel_input_graph, out, rev, trial_num, for_time):
        trial_num = -1  # cancel logging

    # determine how to save the output
    kill_out = False
    if for_time or out != '/dev/null':
        # disable /dev/null for performance experiments so we can get the weight for now ...
        if out == '/dev/null':
            out = random_tmp_filename(10, 'weight-for-time')
            kill_out = True

        save_cmd = '> ' + out
    else:
        # save just the first line of output so we can get the weight
        out = random_tmp_filename(10, 'weight')
        save_cmd = '| head -n 1 > ' + out
        kill_out = True

    # run mst (and time it)
    time_file = random_tmp_filename(10, 'time')
    cmd = '/usr/bin/time -f %%U -o %s %s %s %s' % (time_file, mst_binary,
                                                   input_graph, save_cmd)
    ret = os.system(cmd)
    if ret != 0:
        print >> sys.stderr, "mst exited with error: " + cmd
        quiet_remove(time_file)
        return
    try:
        time_sec = extract_answer(time_file)
    except CheckerError, e:
        print >> sys.stderr, "failed to read time file: " + str(e)
        return
Пример #4
0
def benchmark(mst_binary, input_graph, out, rev, trial_num, for_time):
    rel_input_graph = ppinput(input_graph)
    if not print_benchmark(rel_input_graph, out, rev, trial_num, for_time):
        trial_num = -1  # cancel logging

    # determine how to save the output
    kill_out = False
    if for_time or out != '/dev/null':
        # disable /dev/null for performance experiments so we can get the weight for now ...
        if out == '/dev/null':
            out = random_tmp_filename(10, 'weight-for-time')
            kill_out = True

        save_cmd = '> ' + out
    else:
        # save just the first line of output so we can get the weight
        out = random_tmp_filename(10, 'weight')
        save_cmd = '| head -n 1 > ' + out
        kill_out = True

    # run mst (and time it)
    time_file = random_tmp_filename(10, 'time')
    cmd = '/usr/bin/time -f %%U -o %s %s %s %s' % (time_file, mst_binary, input_graph, save_cmd)
    ret = os.system(cmd)
    if ret != 0:
        print >> sys.stderr, "mst exited with error: " + cmd
        quiet_remove(time_file)
        return
    try:
        time_sec = extract_answer(time_file)
    except CheckerError, e:
        print >> sys.stderr, "failed to read time file: " + str(e)
        return
Пример #5
0
    if ret != 0:
        print >> sys.stderr, "mst exited with error: " + cmd
        quiet_remove(time_file)
        return
    try:
        time_sec = extract_answer(time_file)
    except CheckerError, e:
        print >> sys.stderr, "failed to read time file: " + str(e)
        return
    quiet_remove(time_file)

    # try to get the weight (if we output the result somewhere)
    mst_weight = -1.0
    if out != "/dev/null":
        try:
            mst_weight = extract_answer(out)
        except CheckerError, e:
            print >> sys.stderr, "failed to read weight file: " + str(e)
            return
        str_mst_weight = '  mst_weight=' + str(mst_weight)
        if kill_out:
            quiet_remove(out)  # was a temporary file we created
    else:
        str_mst_weight = ''

    # check to see if we are supposed to log the result
    print('benchmark result ===> time=%.2f' + str_mst_weight) % time_sec
    if trial_num < 0 and for_time:
        return

    # extract properties of the graph
Пример #6
0
    if ret != 0:
        print >> sys.stderr, "mst exited with error: " + cmd
        quiet_remove(time_file)
        return
    try:
        time_sec = extract_answer(time_file)
    except CheckerError, e:
        print >> sys.stderr, "failed to read time file: " + str(e)
        return
    quiet_remove(time_file)

    # try to get the weight (if we output the result somewhere)
    mst_weight = -1.0
    if out != "/dev/null":
        try:
            mst_weight = extract_answer(out)
        except CheckerError, e:
            print >> sys.stderr, "failed to read weight file: " + str(e)
            return
        str_mst_weight = '  mst_weight=' + str(mst_weight)
        if kill_out:
            quiet_remove(out) # was a temporary file we created
    else:
        str_mst_weight = ''

    # check to see if we are supposed to log the result
    print ('benchmark result ===> time=%.2f'+str_mst_weight) % time_sec
    if trial_num < 0 and for_time:
        return

    # extract properties of the graph