1 from pygraph.classes.digraph
import digraph
2 from pygraph.algorithms.cycles
import find_cycle
3 from pygraph.algorithms.accessibility
import connected_components
4 from pygraph.algorithms.critical
import critical_path
8 data = open(filename).
read()
12 for algo
in workflow[
"algorithms"]:
14 name = algo[
"name"] +
"_algo" 16 for input
in algo[
"inputs"]:
19 if not gr.has_node(input):
21 if not gr.has_edge((input, name)):
22 gr.add_edge((input, name), wt=0)
23 for output
in algo[
"outputs"]:
26 if not gr.has_node(output):
27 gr.add_nodes([output])
28 if not gr.has_edge((name, output)):
30 gr.add_edge((name, output), wt=algo[
"runtimes_wall"][0] * 100)
38 cycle = find_cycle(gr)
44 print "Removed loop by deleting edge (%s,%s)" % (cycle[-1], cycle[0])
45 gr.del_edge((cycle[-1], cycle[0]))
46 print "\nIN TOTAL %i CYCLES\n" % (n_cycles)
51 cc = connected_components(gr)
55 for k, v
in cc.iteritems():
56 cc_size[v] = cc_size[v] + 1
57 print "Connected components have the following size:" 60 print "NUMBER OF CONNECTED COMPONENTS: %i" % (len(cc_size.keys()))
66 cp = critical_path(gr)
68 for edge
in gr.edges():
69 total_time += gr.edge_weight(edge)
72 edges = [tuple(cp[i:i + 2])
for i
in range(0, len(cp))]
74 critical_time += gr.edge_weight(edge)
76 print "Total time : %s" % total_time
77 print "Critical path: %s" % critical_time
78 print "POSSIBLE SPEEDUP: %s" % (total_time / critical_time)
84 for edge
in gr.edges():
85 if edge[0].endswith(
"_algo"):
86 algoname = edge[0].rstrip(
"_algo")
90 algoname = edge[1].rstrip(
"_algo")
94 if algoname
not in known_names:
95 algorithms[algoname] = {
"name": algoname,
99 "runtimes_wall": [1000]
101 known_names.add(algoname)
103 algorithms[algoname][
"inputs"].append(product)
105 algorithms[algoname][
"outputs"].append(product)
106 algorithms[algoname][
"runtimes_wall"] = [
107 gr.edge_weight(edge) / 100, ]
108 out = open(filename,
"w")
109 algorithm_list = [item
for item
in algorithms.values()]
110 workflow = {
"algorithms": algorithm_list}
111 out.write(workflow.__repr__())
116 if __name__ ==
"__main__":
117 filename =
"Athena.json" 123 if had_to_fix_cycles:
def analyze_connected_componets(gr)
def print_graph_to_json(gr, filename)
def analyze_critical_path(gr)
def read(f, regex='.*', skipevents=0)
def analyze_and_fix_cycles(gr)
decltype(auto) range(Args &&...args)
Zips multiple containers together to form a single range.
def read_graph_from_json(filename)