Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/usr/bin/env python
from dagflow.graph import Graph
from dagflow.graphviz import GraphDot
from dagflow.printl import current_level, set_prefix_function
from dagflow.wrappers import *
set_prefix_function(lambda: "{:<2d} ".format(current_level()))
counter = 0
nodeargs = dict(typefunc=lambda: True)
def test_graph_big_01():
"""Create a graph of nodes and test evaluation features"""
g = Graph()
label = None
def plot(suffix=""):
global counter
d = GraphDot(g)
newlabel = label and label + suffix or suffix
if newlabel is not None:
d.set_label(newlabel)
d.savegraph("output/test_graph_big_{:03d}.png".format(counter))
counter += 1
def plotter(fcn, node, inputs, outputs):
plot(f"[start evaluating {node.name}]")
fcn(node, inputs, outputs)
plot(f"[done evaluating {node.name}]")
A1 = g.add_node("A1", **nodeargs)
A2 = g.add_node("A2", auto_freeze=True, label="{name}|frozen", **nodeargs)
A3 = g.add_node("A3", immediate=True, label="{name}|immediate", **nodeargs)
B = g.add_node("B", **nodeargs)
C1 = g.add_node("C1", **nodeargs)
C2 = g.add_node("C2", **nodeargs)
D = g.add_node("D", **nodeargs)
E = g.add_node("E", **nodeargs)
F = g.add_node("F", **nodeargs)
H = g.add_node("H", **nodeargs)
P = g.add_node("P", immediate=True, label="{name}|immediate", **nodeargs)
g._wrap_fcns(toucher, printer, plotter)
A1._add_output("o1", allocatable=False)
A2._add_output("o1", allocatable=False)
P._add_output("o1", allocatable=False)
A3._add_pair("i1", "o1", output_kws={"allocatable": False})
B._add_pair(
("i1", "i2", "i3", "i4"),
("o1", "o2"),
output_kws={"allocatable": False},
)
C1._add_output("o1", allocatable=False)
C2._add_output("o1", allocatable=False)
D._add_pair("i1", "o1", output_kws={"allocatable": False})
D._add_pair("i2", "o2", output_kws={"allocatable": False})
H._add_pair("i1", "o1", output_kws={"allocatable": False})
_, other = F._add_pair("i1", "o1", output_kws={"allocatable": False})
_, final = E._add_pair("i1", "o1", output_kws={"allocatable": False})
(A1, A2, (P >> A3), D[:1]) >> B >> (E, H)
((C1, C2) >> D[:, 1]) >> F
g.print()
g.close()
label = "Initial graph state."
plot()
label = "Read E..."
plot()
plot()
plot()
final.data
label = "Done reading E."
plot()
label = "Taint D."
plot()
plot()
plot()
D.taint()
plot()
label = "Read F..."
other.data
label = "Done reading F."
plot()
label = "Read E..."
plot()
plot()
plot()
final.data
label = "Done reading E."
plot()
label = "Taint A2."
plot()
plot()
plot()
A2.taint()
plot()
label = "Read E..."
plot()
final.data
label = "Done reading E."
plot()
label = "Unfreeze A2 (tainted)."
plot()
plot()
plot()
A2.unfreeze()
plot()
label = "Read E..."
plot()
final.data
label = "Done reading E."
plot()
label = "Unfreeze A2 (not tainted)."
plot()
plot()
plot()
A2.unfreeze()
plot()
label = "Read E..."
plot()
final.data
label = "Done reading E."
plot()
label = "Taint P"
plot()
plot()
plot()
P.taint()
plot()
label = "Read E..."
plot()
final.data
label = "Done reading E."
plot()
label = "Invalidate P"
plot()
plot()
plot()
P.invalid = True
plot()
label = "Validate P"
plot()
plot()
plot()
P.invalid = False
plot()
label = "Read E..."
plot()
final.data
label = "Done reading E."
plot()