92def print_graph_to_json(gr, filename):
93 algorithms = {}
94 known_names = set()
95 for edge in gr.edges():
96 if edge[0].endswith("_algo"):
97 algoname = edge[0].rstrip("_algo")
98 product = edge[1]
99 reading = False
100 else:
101 algoname = edge[1].rstrip("_algo")
102 product = edge[0]
103 reading = True
104
105 if algoname not in known_names:
106 algorithms[algoname] = {
107 "name": algoname,
108 "inputs": [],
109 "outputs": [],
110 "runtimes": [1000],
111 "runtimes_wall": [1000],
112 }
113 known_names.add(algoname)
114 if reading:
115 algorithms[algoname]["inputs"].append(product)
116 else:
117 algorithms[algoname]["outputs"].append(product)
118 algorithms[algoname]["runtimes_wall"] = [
119 gr.edge_weight(edge) / 100,
120 ]
121 out = open(filename, "w")
122 algorithm_list = [item for item in algorithms.values()]
123 workflow = {"algorithms": algorithm_list}
124 out.write(workflow.__repr__())
125 out.close()
126
127