Exemplo n.º 1
0
def bench_cpu(test_path: str, randomize=False):
    """
    Bench both opt1 and opt2 execution time using the graph generated for the performance tests. The execution times
    are printed in the terminal. In order to process bigger rand-graphs and save time, matrices W and D are
    directly passed to the retimer that executes opt2, avoiding to be computed twice per graph.
    """
    path = os.getcwd() + '/' + test_path
    perf_test = [file for file in os.listdir(path)]
    for file in sorted(perf_test):
        print(file)
        graph = utils.load_graph(path + '/' + file)
        retimer = rt.Retimer(graph.copy())

        if randomize is True:
            graph = utils.node_randomizer(retimer.graph)
            nx.nx_agraph.write_dot(graph, path + '/np-{}'.format(file))

        max_clock = max([
            weight['component_delay'] for (node, weight) in graph.nodes.data()
        ])

        init = time.time()
        retimer.retime('opt1')
        end = time.time()
        print("opt1 {}".format(end - init))
        assert max_clock == retimer.opt.min_clock
        nretimer = rt.Retimer(graph.copy())
        nretimer.opt.w = retimer.wd.w
        nretimer.opt.d = retimer.wd.d
        del retimer
        nretimer.opt.opt('opt2')
        assert max_clock == nretimer.opt.min_clock
        del nretimer
Exemplo n.º 2
0
def random_test(test_path: str):
    """
    Run a random test to test the correctness of the algorithms. In order to do this a random graph is
    generated, some edges are pruned and some weights are moved along the circuit paths.

    The graph generated has at least one register per edge.

    After the edges has been randomly moved the script runs both opt1 and opt2 and checks that the clock
    found by both algorithms is the same as the initial one.
    """
    path = os.getcwd() + '/' + test_path
    perf_test = [file for file in os.listdir(path)]
    for file in sorted(perf_test):
        graph = utils.load_graph(path + '/' + file)
        retimer = rt.Retimer(graph)
        print("file")
        print(file)
        max_clock = max([
            weight['component_delay']
            for (node, weight) in retimer.graph.nodes.data()
        ])
        print("theoretical clock")
        print(max_clock)
        retimer.graph = utils.node_randomizer(retimer.graph)
        retimer.retime('opt1')
        assert max_clock == retimer.opt.min_clock
        retimer = rt.Retimer(retimer.graph)
        retimer.retime('opt2')
        assert max_clock == retimer.opt.min_clock

    print("All tests passed")
Exemplo n.º 3
0
def correlator_test(correlator_dimension=None):
    """
    Run OPT1 and OPT2 on the correlator circuit presented in the paper. If no parameter
    is passed the exact one is chosen, otherwise a correlator with the desired dimension
    will be created.
    """
    path = os.getcwd() + '/corr-graphs'
    perf_test = [file for file in os.listdir(path)]
    if correlator_dimension is None:
        path = path + 'correlator.dot'
        graph = utils.load_graph(path)
    else:
        graph = gn.generate_from_correlator(correlator_dimension)

    if correlator_dimension < 8:
        max_clock = 13
    else:
        max_clock = 14

    retimer = rt.Retimer(graph)
    print("theoretical clock")
    print(max_clock)
    retimer.retime('opt1')
    assert max_clock == retimer.opt.min_clock
    retimer = rt.Retimer(retimer.graph)
    retimer.retime('opt2')
    assert max_clock == retimer.opt.min_clock

    print("All tests passed")
Exemplo n.º 4
0
def bench_memory():
    """
    Bench both opt1 and opt2 memory consumption using the graph generated for the performance tests. The execution times
    are printed in the terminal. In order to process bigger rand-graphs and save time, matrices W and D are
    directly passed to the retimer that executes opt2, avoiding to be computed twice per graph.
    """
    path = os.getcwd() + '/perf-graphs/randomized'
    perf_test = [file for file in os.listdir(path)]
    for file in sorted(perf_test):
        print(file)
        graph = utils.load_graph(path + '/' + file)
        max_clock = max([
            weight['component_delay'] for (node, weight) in graph.nodes.data()
        ])
        retimer = rt.Retimer(graph.copy())
        profile_memory(retimer, 'opt1')
        assert max_clock == retimer.opt.min_clock
        nretimer = rt.Retimer(graph.copy())
        del retimer
        profile_memory(nretimer, 'opt2')
        assert max_clock == nretimer.opt.min_clock
        del nretimer
Exemplo n.º 5
0
def profile(test_path: str, randomize=False):
    """
    Profile both opt1 and opt2 using the graph generated for the performance tests.
    cProfiler output files can be visualized with snakeviz
    """

    path = os.getcwd() + '/' + test_path
    perf_test = [file for file in os.listdir(path)]
    for file in sorted(perf_test):
        print(file)
        graph = utils.load_graph(path + '/' + file)
        retimer = rt.Retimer(graph.copy())

        if randomize is True:
            graph = utils.node_randomizer(retimer.graph)
            nx.nx_agraph.write_dot(graph, path + 'np-{}'.format(file))

        max_clock = max([
            weight['component_delay'] for (node, weight) in graph.nodes.data()
        ])
        pr = cProfile.Profile()
        pr.enable()
        retimer.retime('opt1')
        pr.disable()
        assert max_clock == retimer.opt.min_clock
        pr.dump_stats(os.getcwd() +
                      '/profile-results-optimized/{}-opt1.out'.format(file))
        del retimer

        nretimer = rt.Retimer(graph.copy())
        pr = cProfile.Profile()
        pr.enable()
        nretimer.retime('opt2')
        assert max_clock == nretimer.opt.min_clock
        pr.disable()
        pr.dump_stats(os.getcwd() +
                      '/profile-results-optimized/{}-opt2.out'.format(file))
        del nretimer
Exemplo n.º 6
0
def run(path: str, printwd: bool, optimizer: str, output: str):
    graph = utilities.load_graph(path)
    retimer = rt.Retimer(graph, printwd)
    retimer.retime(optimizer)
    rt.save_graph(retimer.retimed_graph, output)