def recipes_to_graph(recipes): """ Given a list of recipes, will create a func dep graph for each which it will then compose. :param recipes: A list of recipe object :return: A combined graph where the 'starts' attribute for each node has been set """ result_graph = nx.DiGraph() for r in recipes: # Turn recipe to graph and get top nodes r_graph = r.to_DiGraph() top_nodes = get_top_nodes(r_graph) top_nodes = [x[0] for x in top_nodes ] # Get only names of nodes not attributes # Iterate over each node in graph for node in r_graph.nodes(data=True): work = node[0] attributes = node[1] # If node is a top node, it has its starts attribute set to the recipe name attributes['starts'] = set() if work in top_nodes: attributes['starts'].add(r.name) # If this node is already in the result_graph we store elements from its start attributes # in the r_graph node, as to retain it after compose. if work in result_graph: res_set = result_graph.node[work]['starts'] attributes['starts'].update(res_set) # Attributes of r_graph take presedence over result_graph's result_graph = nx.compose(result_graph, r_graph) return result_graph
def __nested_remixgroup(dg1, remix_group): print "============= nested remix_group ================ \n" dg2 = nx.DiGraph() data = json.loads(remix_group.networkx_data) dg2.add_nodes_from(data['nodes']) dg2.add_edges_from(data['edges']) print "========== MERGED GROUP NODES: " + str(dg1.nodes()) # FIXME: this combines the graphs correctly # recheck the time-bound concept dg1 = nx.compose(dg1, dg2) print dg1.nodes() return dg1
def create_graph(): """Composes the graphs of the different plugins into a single graph. """ # load plugins mgr = extension.ExtensionManager( namespace='doconv.converter', invoke_on_load=True, propagate_map_exceptions=True, ) # check that all plugin dependencies are installed mgr.map_method("check_dependencies") # create conversion graph based on found plugins plugin_graphs = mgr.map_method("get_supported_conversions_graph") logger.debug("Loaded plugins: {0}".format(mgr.names())) G = nx.DiGraph() for graph in plugin_graphs: G = nx.compose(G, graph) return G