1 from __future__
import print_function
2 from pygraph.classes.digraph
import digraph
3 from pygraph.algorithms.cycles
import find_cycle
4 from pygraph.algorithms.accessibility
import connected_components
5 from pygraph.algorithms.critical
import critical_path
9 data = open(filename).
read()
13 for algo
in workflow[
"algorithms"]:
15 name = algo[
"name"] +
"_algo" 17 for input
in algo[
"inputs"]:
20 if not gr.has_node(input):
22 if not gr.has_edge((input, name)):
23 gr.add_edge((input, name), wt=0)
24 for output
in algo[
"outputs"]:
27 if not gr.has_node(output):
28 gr.add_nodes([output])
29 if not gr.has_edge((name, output)):
31 gr.add_edge((name, output), wt=algo[
"runtimes_wall"][0] * 100)
39 cycle = find_cycle(gr)
45 print(
"Removed loop by deleting edge (%s,%s)" % (cycle[-1], cycle[0]))
46 gr.del_edge((cycle[-1], cycle[0]))
47 print(
"\nIN TOTAL %i CYCLES\n" % (n_cycles))
52 cc = connected_components(gr)
56 for k, v
in cc.iteritems():
57 cc_size[v] = cc_size[v] + 1
58 print(
"Connected components have the following size:")
61 print(
"NUMBER OF CONNECTED COMPONENTS: %i" % (len(cc_size.keys())))
67 cp = critical_path(gr)
69 for edge
in gr.edges():
70 total_time += gr.edge_weight(edge)
73 edges = [tuple(cp[i:i + 2])
for i
in range(0, len(cp))]
75 critical_time += gr.edge_weight(edge)
77 print(
"Total time : %s" % total_time)
78 print(
"Critical path: %s" % critical_time)
79 print(
"POSSIBLE SPEEDUP: %s" % (total_time / critical_time))
85 for edge
in gr.edges():
86 if edge[0].endswith(
"_algo"):
87 algoname = edge[0].rstrip(
"_algo")
91 algoname = edge[1].rstrip(
"_algo")
95 if algoname
not in known_names:
96 algorithms[algoname] = {
101 "runtimes_wall": [1000]
103 known_names.add(algoname)
105 algorithms[algoname][
"inputs"].append(product)
107 algorithms[algoname][
"outputs"].append(product)
108 algorithms[algoname][
"runtimes_wall"] = [
109 gr.edge_weight(edge) / 100,
111 out = open(filename,
"w")
112 algorithm_list = [item
for item
in algorithms.values()]
113 workflow = {
"algorithms": algorithm_list}
114 out.write(workflow.__repr__())
119 if __name__ ==
"__main__":
120 filename =
"Athena.json" 126 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)