12 from pygraph.algorithms.accessibility
import connected_components
13 from pygraph.algorithms.critical
import critical_path
14 from pygraph.algorithms.cycles
import find_cycle
15 from pygraph.classes.digraph
import digraph
19 data = open(filename).
read()
23 for algo
in workflow[
"algorithms"]:
25 name = algo[
"name"] +
"_algo"
27 for input
in algo[
"inputs"]:
30 if not gr.has_node(input):
32 if not gr.has_edge((input, name)):
33 gr.add_edge((input, name), wt=0)
34 for output
in algo[
"outputs"]:
37 if not gr.has_node(output):
38 gr.add_nodes([output])
39 if not gr.has_edge((name, output)):
41 gr.add_edge((name, output), wt=algo[
"runtimes_wall"][0] * 100)
49 cycle = find_cycle(gr)
55 print(
"Removed loop by deleting edge (%s,%s)" % (cycle[-1], cycle[0]))
56 gr.del_edge((cycle[-1], cycle[0]))
57 print(
"\nIN TOTAL %i CYCLES\n" % (n_cycles))
62 cc = connected_components(gr)
66 for k, v
in cc.iteritems():
67 cc_size[v] = cc_size[v] + 1
68 print(
"Connected components have the following size:")
71 print(
"NUMBER OF CONNECTED COMPONENTS: %i" % (len(cc_size.keys())))
77 cp = critical_path(gr)
79 for edge
in gr.edges():
80 total_time += gr.edge_weight(edge)
83 edges = [tuple(cp[i : i + 2])
for i
in range(0, len(cp))]
85 critical_time += gr.edge_weight(edge)
87 print(
"Total time : %s" % total_time)
88 print(
"Critical path: %s" % critical_time)
89 print(
"POSSIBLE SPEEDUP: %s" % (total_time / critical_time))
95 for edge
in gr.edges():
96 if edge[0].endswith(
"_algo"):
97 algoname = edge[0].rstrip(
"_algo")
101 algoname = edge[1].rstrip(
"_algo")
105 if algoname
not in known_names:
106 algorithms[algoname] = {
111 "runtimes_wall": [1000],
113 known_names.add(algoname)
115 algorithms[algoname][
"inputs"].append(product)
117 algorithms[algoname][
"outputs"].append(product)
118 algorithms[algoname][
"runtimes_wall"] = [
119 gr.edge_weight(edge) / 100,
121 out = open(filename,
"w")
122 algorithm_list = [item
for item
in algorithms.values()]
123 workflow = {
"algorithms": algorithm_list}
124 out.write(workflow.__repr__())
129 if __name__ ==
"__main__":
130 filename =
"Athena.json"
136 if had_to_fix_cycles: