MCPcopy Create free account
hub / github.com/microsoft/Cream / plot

Function plot

CDARTS/lib/utils/visualize.py:7–60  ·  view source on GitHub ↗

make DAG plot and save to file_path as .png

(genotype, file_path, caption=None)

Source from the content-addressed store, hash-verified

5
6
7def plot(genotype, file_path, caption=None):
8 """ make DAG plot and save to file_path as .png """
9 edge_attr = {
10 'fontsize': '20',
11 'fontname': 'times'
12 }
13 node_attr = {
14 'style': 'filled',
15 'shape': 'rect',
16 'align': 'center',
17 'fontsize': '20',
18 'height': '0.5',
19 'width': '0.5',
20 'penwidth': '2',
21 'fontname': 'times'
22 }
23 g = Digraph(
24 format='png',
25 edge_attr=edge_attr,
26 node_attr=node_attr,
27 engine='dot')
28 g.body.extend(['rankdir=LR'])
29
30 # input nodes
31 g.node("c_{k-2}", fillcolor='darkseagreen2')
32 g.node("c_{k-1}", fillcolor='darkseagreen2')
33
34 # intermediate nodes
35 n_nodes = len(genotype)
36 for i in range(n_nodes):
37 g.node(str(i), fillcolor='lightblue')
38
39 for i, edges in enumerate(genotype):
40 for op, j in edges:
41 if j == 0:
42 u = "c_{k-2}"
43 elif j == 1:
44 u = "c_{k-1}"
45 else:
46 u = str(j-2)
47
48 v = str(i)
49 g.edge(u, v, label=op, fillcolor="gray")
50
51 # output node
52 g.node("c_{k}", fillcolor='palegoldenrod')
53 for i in range(n_nodes):
54 g.edge(str(i), "c_{k}", fillcolor="gray")
55
56 # add image caption
57 if caption:
58 g.attr(label=caption, overlap='false', fontsize='20', fontname='times')
59
60 g.render(file_path, view=False)
61
62
63if __name__ == '__main__':

Callers 2

mainFunction · 0.90
visualize.pyFile · 0.70

Calls 1

nodeMethod · 0.80

Tested by

no test coverage detected