def _get_calc_nodes(self, name):
g = nx.DiGraph()
g.add_nodes_from(self.dag.nodes())
g.add_edges_from(self.dag.edges())
for n in nx.ancestors(g, name):
node = self.dag.node[n]
state = node[_AN_STATE]
if state == States.UPTODATE or state == States.PINNED:
g.remove_node(n)
ancestors = nx.ancestors(g, name)
for n in ancestors:
if state == States.UNINITIALIZED and len(self.dag.pred[n]) == 0:
raise Exception("Cannot compute {} because {} uninitialized".format(name, n))
if state == States.PLACEHOLDER:
raise Exception("Cannot compute {} because {} is placeholder".format(name, n))
ancestors.add(name)
nodes_sorted = nx.topological_sort(g)
return [n for n in nodes_sorted if n in ancestors]
评论列表
文章目录