Ejemplo n.º 1
0
def module_graph(graph, project_name, cfg, title=None, alpha=1, edgecolor="k", untypedcolor='royalblue', typedcolor='darkorange', output=None):
    """
        Show module-dependence graph.
        Args:
        - graph        = The modulegraph object to plot
        - fname        = Filename the graph was parsed from. Used to save output.
        - title        = Title of plot
        Options:
        - alpha        = opacity of nodes
        - boundaries   = Edges to color Red and THICK
        - edgecolor    = Normal edge color
        - untypedcolor = Node color for untyped modules
        - typedcolor   = Node color for typed modules
    """
    ## Make networkx graph
    g = nx.DiGraph()
    for mn in graph.get_module_names():
        g.add_node(mn)
    for (src,dst) in graph.edges_iter():
        g.add_edge(src,dst)
    ## Make pyplot
    pos = nx.circular_layout(g, scale=1)
    fig,ax1 = plt.subplots()
    # Untyped nodes, or the default
    nx.draw_networkx_nodes(g, pos, node_size=1000, alpha=alpha
                           ,nodelist=[mn for mn in graph.get_module_names() if config.untyped_at(cfg, graph.index_of_module(mn))]
                           ,node_color=untypedcolor)
    # Typed nodes
    nx.draw_networkx_nodes(g, pos, node_size=1000, alpha=alpha
                           ,nodelist=[mn for mn in graph.get_module_names() if config.typed_at(cfg, graph.index_of_module(mn))]
                           ,node_color=typedcolor)
    nx.draw_networkx_labels(g, pos, dict([(k,k) for k in graph.get_module_names()]))
    nx.draw_networkx_edges(g, pos, edge_color=edgecolor, alpha=alpha)
    ## Draw boundaries
    boundaries = [(src,dst) for (src,dst) in graph.edges_iter()
                  if config.is_boundary(cfg, graph.index_of_module(src), graph.index_of_module(dst))]
    nx.draw_networkx_edges(g, pos, edgelist=boundaries, edge_color="r", width=4)
    output = output or "%s/%s-module-graph-%s.png" % (constants.OUTPUT_DIR, project_name, cfg)
    title = title or "%s-modulegraph-%s.png" % (project_name, cfg)
    ax1.set_title(title)
    plt.axis("off")
    plt.savefig(output)
    plt.clf()
    plt.close()
    print("Saved module graph to '%s'" % output)
    return output
Ejemplo n.º 2
0
def main(tabfile, dgraph):
    """ (-> Path-String GraphDict Result)
        Input: a .tab file, an overall summary of running all configurations
               of a project.
        Output: a Result object.
    """
    print("Collecting results from ground truth data '%s'" % tabfile)
    fname = util.strip_suffix(tabfile).rsplit("/", 1)[-1]
    num_modules = count_modules(tabfile)
    num_configs = 2 ** num_modules
    print("Project contains %s modules (%s configurations)" % (num_modules, num_configs))
    u_raw = all_cells_matching(tabfile, config.is_untyped)
    g_raw = all_cells_matching(tabfile, lambda x: not (config.is_typed(x) or config.is_untyped(x)))
    t_raw = all_cells_matching(tabfile, config.is_typed)
    ugt_violin = plot.violin([u_raw, g_raw, t_raw]
                            ,"%s_untyped-vs-gradual-vs-typed" % fname
                            ,"Configuration"
                            ,"Runtime (ms)"
                            ,xlabels=["untyped","gradual\n(all configs)","typed"]) if u_raw and g_raw and t_raw else None
    # Collect absolute BEST and WORST times+configs
    ten_percent = max(3, min(10, int(0.10 * num_configs)))
    best_cfg_and_times  = best_rows(tabfile
                        ,ten_percent
                        ,lambda acc,tmp: tmp[1] < acc[1]
                        ,lambda row:(row[0], int(statistics.mean([int(x) for x in row[1::]]))))
    worst_cfg_and_times = best_rows(tabfile
                        ,ten_percent
                        ,lambda acc,tmp: acc[1] < tmp[1]
                        ,lambda row:(row[0], int(statistics.mean([int(x) for x in row[1::]]))))
    stats = {
        "title"    : fname
        ,"runs"    : count_runs(tabfile)
        ,"graph"   : dgraph
        ,"ugt"     : {"img" : ugt_violin
                     ,"summary" : {"untyped" : basic_row_stats(u_raw)
                                  ,"gradual" : basic_row_stats(g_raw)
                                  ,"typed"   : basic_row_stats(t_raw)}}
        ,"best"    : [config.basic_stats(v[0], v[1], dgraph)
                      for v in best_cfg_and_times if v is not None]
        ,"worst"   : [config.basic_stats(v[0], v[1], dgraph)
                      for v in worst_cfg_and_times if v is not None]
        ,"bucketed": plot.violin(bucketize(tabfile, config.num_typed_modules, num_modules)
                           ,"%s_by-typed-modules" % fname
                           ,"Number of Typed Modules"
                           ,"Runtime (ms)"
                           ,positions=range(0, 1+num_modules)
                           ,xlabels=range(0, 1+num_modules))
        ,"fixed"   : [plot.double_violin([bucketize(tabfile, config.num_typed_modules, num_modules, pred=lambda cfg: config.untyped_at(cfg, v[0]))
                                    ,bucketize(tabfile, config.num_typed_modules, num_modules, pred=lambda cfg: config.typed_at(cfg, v[0]))]
                                    ,"%s_fixing-%s" % (fname, k)
                                    ,"Number of Typed Modules"
                                    ,"Runtime (ms)"
                                    ,legend=["%s is untyped" % k
                                            ,"%s is typed" % k])
                      for (k,v) in sorted(dgraph.items(), key=lambda item:item[1][0])]
    }
    return stats