@@ -54,8 +54,8 @@ def compile(cls, source_net, compiled_net):
54
54
compiled_net .add_edges_from (source_net .edges (data = True ))
55
55
56
56
# Compile the nodes to computation nodes
57
- for name , data in compiled_net .nodes_iter (data = True ):
58
- state = source_net .node [name ]
57
+ for name , data in compiled_net .nodes (data = True ):
58
+ state = source_net .nodes [name ][ 'attr_dict' ]
59
59
if '_output' in state and '_operation' in state :
60
60
raise ValueError ("Cannot compile: both _output and _operation present "
61
61
"for node '{}'" .format (name ))
@@ -92,7 +92,7 @@ def compile(cls, source_net, compiled_net):
92
92
uses_observed = []
93
93
94
94
for node in nx .topological_sort (source_net ):
95
- state = source_net .node [node ]
95
+ state = source_net .nodes [node ][ 'attr_dict' ]
96
96
if state .get ('_observable' ):
97
97
observable .append (node )
98
98
cls .make_observed_copy (node , compiled_net )
@@ -113,14 +113,14 @@ def compile(cls, source_net, compiled_net):
113
113
else :
114
114
link_parent = parent
115
115
116
- compiled_net .add_edge (link_parent , obs_node , source_net [parent ][node ].copy ())
116
+ compiled_net .add_edge (link_parent , obs_node , ** source_net [parent ][node ].copy ())
117
117
118
118
# Check that there are no stochastic nodes in the ancestors
119
119
for node in uses_observed :
120
120
# Use the observed version to query observed ancestors in the compiled_net
121
121
obs_node = observed_name (node )
122
122
for ancestor_node in nx .ancestors (compiled_net , obs_node ):
123
- if '_stochastic' in source_net .node .get (ancestor_node , {}):
123
+ if '_stochastic' in source_net .nodes .get (ancestor_node , {}):
124
124
raise ValueError ("Observed nodes must be deterministic. Observed "
125
125
"data depends on a non-deterministic node {}."
126
126
.format (ancestor_node ))
@@ -148,11 +148,10 @@ def make_observed_copy(cls, node, compiled_net, operation=None):
148
148
raise ValueError ("Observed node {} already exists!" .format (obs_node ))
149
149
150
150
if operation is None :
151
- compiled_dict = compiled_net .node [node ].copy ()
151
+ compiled_dict = compiled_net .nodes [node ].copy ()
152
152
else :
153
153
compiled_dict = dict (operation = operation )
154
-
155
- compiled_net .add_node (obs_node , compiled_dict )
154
+ compiled_net .add_node (obs_node , ** compiled_dict )
156
155
return obs_node
157
156
158
157
@@ -176,8 +175,8 @@ def compile(cls, source_net, compiled_net):
176
175
instruction_node_map = dict (_uses_batch_size = '_batch_size' , _uses_meta = '_meta' )
177
176
178
177
for instruction , _node in instruction_node_map .items ():
179
- for node , d in source_net .nodes_iter (data = True ):
180
- if d .get (instruction ):
178
+ for node , d in source_net .nodes (data = True ):
179
+ if d [ 'attr_dict' ] .get (instruction ):
181
180
if not compiled_net .has_node (_node ):
182
181
compiled_net .add_node (_node )
183
182
compiled_net .add_edge (_node , node , param = _node [1 :])
@@ -203,8 +202,8 @@ def compile(cls, source_net, compiled_net):
203
202
logger .debug ("{} compiling..." .format (cls .__name__ ))
204
203
205
204
_random_node = '_random_state'
206
- for node , d in source_net .nodes_iter (data = True ):
207
- if '_stochastic' in d :
205
+ for node , d in source_net .nodes (data = True ):
206
+ if '_stochastic' in d [ 'attr_dict' ] :
208
207
if not compiled_net .has_node (_random_node ):
209
208
compiled_net .add_node (_random_node )
210
209
compiled_net .add_edge (_random_node , node , param = 'random_state' )
@@ -230,7 +229,7 @@ def compile(cls, source_net, compiled_net):
230
229
231
230
outputs = compiled_net .graph ['outputs' ]
232
231
output_ancestors = nbunch_ancestors (compiled_net , outputs )
233
- for node in compiled_net .nodes ():
232
+ for node in list ( compiled_net .nodes () ):
234
233
if node not in output_ancestors :
235
234
compiled_net .remove_node (node )
236
235
return compiled_net
0 commit comments