The Gaudi Framework  v32r2 (46d42edc)
graphanalysis Namespace Reference

Functions

def read_graph_from_json (filename)
 
def analyze_and_fix_cycles (gr)
 
def analyze_connected_componets (gr)
 
def analyze_critical_path (gr)
 
def print_graph_to_json (gr, filename)
 

Variables

string filename = "Athena.json"
 
def gr = read_graph_from_json(filename)
 
def had_to_fix_cycles = analyze_and_fix_cycles(gr)
 

Function Documentation

◆ analyze_and_fix_cycles()

def graphanalysis.analyze_and_fix_cycles (   gr)

Definition at line 35 of file graphanalysis.py.

36  has_loop = True
37  n_cycles = 0
38  while has_loop:
39  cycle = find_cycle(gr)
40  if len(cycle) == 0:
41  has_loop = False
42  continue
43  n_cycles += 1
44  print(cycle)
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))
48  return n_cycles > 0 # whether it needed to fix cycles
49 
50 
def analyze_and_fix_cycles(gr)

◆ analyze_connected_componets()

def graphanalysis.analyze_connected_componets (   gr)

Definition at line 51 of file graphanalysis.py.

52  cc = connected_components(gr)
53  cc_size = {}
54  for i in cc.values():
55  cc_size[i] = 0
56  for k, v in cc.iteritems():
57  cc_size[v] = cc_size[v] + 1
58  print("Connected components have the following size:")
59  # for k,v in cc_size.iteritems():
60  # print "%i : %i" %(k,v)
61  print("NUMBER OF CONNECTED COMPONENTS: %i" % (len(cc_size.keys())))
62 
63 
def analyze_connected_componets(gr)

◆ analyze_critical_path()

def graphanalysis.analyze_critical_path (   gr)

Definition at line 64 of file graphanalysis.py.

64 def analyze_critical_path(gr):
65  total_time = 0
66  critical_time = 0
67  cp = critical_path(gr)
68  # calculate total time
69  for edge in gr.edges():
70  total_time += gr.edge_weight(edge)
71 
72  # calculate time of critical path
73  edges = [tuple(cp[i:i + 2]) for i in range(0, len(cp))]
74  for edge in edges:
75  critical_time += gr.edge_weight(edge)
76 
77  print("Total time : %s" % total_time)
78  print("Critical path: %s" % critical_time)
79  print("POSSIBLE SPEEDUP: %s" % (total_time / critical_time))
80 
81 
def analyze_critical_path(gr)
decltype(auto) range(Args &&... args)
Zips multiple containers together to form a single range.

◆ print_graph_to_json()

def graphanalysis.print_graph_to_json (   gr,
  filename 
)

Definition at line 82 of file graphanalysis.py.

82 def print_graph_to_json(gr, filename):
83  algorithms = {} # still make it known to workflow
84  known_names = set()
85  for edge in gr.edges():
86  if edge[0].endswith("_algo"):
87  algoname = edge[0].rstrip("_algo")
88  product = edge[1]
89  reading = False
90  else:
91  algoname = edge[1].rstrip("_algo")
92  product = edge[0]
93  reading = True
94 
95  if algoname not in known_names:
96  algorithms[algoname] = {
97  "name": algoname,
98  "inputs": [],
99  "outputs": [],
100  "runtimes": [1000], # TODO dummy
101  "runtimes_wall": [1000] # TODO dummy
102  }
103  known_names.add(algoname)
104  if reading:
105  algorithms[algoname]["inputs"].append(product)
106  else:
107  algorithms[algoname]["outputs"].append(product)
108  algorithms[algoname]["runtimes_wall"] = [
109  gr.edge_weight(edge) / 100,
110  ]
111  out = open(filename, "w")
112  algorithm_list = [item for item in algorithms.values()]
113  workflow = {"algorithms": algorithm_list}
114  out.write(workflow.__repr__())
115  out.close()
116 
117 
def print_graph_to_json(gr, filename)

◆ read_graph_from_json()

def graphanalysis.read_graph_from_json (   filename)

Definition at line 8 of file graphanalysis.py.

8 def read_graph_from_json(filename):
9  data = open(filename).read()
10  workflow = eval(data)
11  gr = digraph()
12  # create all nodes
13  for algo in workflow["algorithms"]:
14  # to differentiate algos from equally named products
15  name = algo["name"] + "_algo"
16  gr.add_nodes([name])
17  for input in algo["inputs"]:
18  if input == "":
19  input = "dummy"
20  if not gr.has_node(input):
21  gr.add_nodes([input])
22  if not gr.has_edge((input, name)):
23  gr.add_edge((input, name), wt=0)
24  for output in algo["outputs"]:
25  if output == "":
26  output = "dummy"
27  if not gr.has_node(output):
28  gr.add_nodes([output])
29  if not gr.has_edge((name, output)):
30  # the output edge gets the weigth corresponding to the runtime
31  gr.add_edge((name, output), wt=algo["runtimes_wall"][0] * 100)
32  return gr
33 
34 
def read(f, regex='.*', skipevents=0)
Definition: hivetimeline.py:23
def read_graph_from_json(filename)
Definition: graphanalysis.py:8

Variable Documentation

◆ filename

string graphanalysis.filename = "Athena.json"

Definition at line 120 of file graphanalysis.py.

◆ gr

def graphanalysis.gr = read_graph_from_json(filename)

Definition at line 121 of file graphanalysis.py.

◆ had_to_fix_cycles

def graphanalysis.had_to_fix_cycles = analyze_and_fix_cycles(gr)

Definition at line 124 of file graphanalysis.py.