11 from __future__
import print_function
13 from pygraph.algorithms.accessibility
import connected_components
14 from pygraph.algorithms.critical
import critical_path
15 from pygraph.algorithms.cycles
import find_cycle
16 from pygraph.classes.digraph
import digraph
20 data = open(filename).
read()
24 for algo
in workflow[
"algorithms"]:
26 name = algo[
"name"] +
"_algo"
28 for input
in algo[
"inputs"]:
31 if not gr.has_node(input):
33 if not gr.has_edge((input, name)):
34 gr.add_edge((input, name), wt=0)
35 for output
in algo[
"outputs"]:
38 if not gr.has_node(output):
39 gr.add_nodes([output])
40 if not gr.has_edge((name, output)):
42 gr.add_edge((name, output), wt=algo[
"runtimes_wall"][0] * 100)
50 cycle = find_cycle(gr)
56 print(
"Removed loop by deleting edge (%s,%s)" % (cycle[-1], cycle[0]))
57 gr.del_edge((cycle[-1], cycle[0]))
58 print(
"\nIN TOTAL %i CYCLES\n" % (n_cycles))
63 cc = connected_components(gr)
67 for k, v
in cc.iteritems():
68 cc_size[v] = cc_size[v] + 1
69 print(
"Connected components have the following size:")
72 print(
"NUMBER OF CONNECTED COMPONENTS: %i" % (len(cc_size.keys())))
78 cp = critical_path(gr)
80 for edge
in gr.edges():
81 total_time += gr.edge_weight(edge)
84 edges = [tuple(cp[i : i + 2])
for i
in range(0, len(cp))]
86 critical_time += gr.edge_weight(edge)
88 print(
"Total time : %s" % total_time)
89 print(
"Critical path: %s" % critical_time)
90 print(
"POSSIBLE SPEEDUP: %s" % (total_time / critical_time))
96 for edge
in gr.edges():
97 if edge[0].endswith(
"_algo"):
98 algoname = edge[0].rstrip(
"_algo")
102 algoname = edge[1].rstrip(
"_algo")
106 if algoname
not in known_names:
107 algorithms[algoname] = {
112 "runtimes_wall": [1000],
114 known_names.add(algoname)
116 algorithms[algoname][
"inputs"].append(product)
118 algorithms[algoname][
"outputs"].append(product)
119 algorithms[algoname][
"runtimes_wall"] = [
120 gr.edge_weight(edge) / 100,
122 out = open(filename,
"w")
123 algorithm_list = [item
for item
in algorithms.values()]
124 workflow = {
"algorithms": algorithm_list}
125 out.write(workflow.__repr__())
130 if __name__ ==
"__main__":
131 filename =
"Athena.json"
137 if had_to_fix_cycles: