def insert_many(self, name_value_pairs):
"""
Insert values into many nodes of a computation simultaneously
Following insertation, the nodes will have state UPTODATE, and all their descendents will be COMPUTABLE or STALE. In the case of inserting many nodes, some of which are descendents of others, this ensures that the inserted nodes have correct status, rather than being set as STALE when their ancestors are inserted.
If an attempt is made to insert a value into a node that does not exist, a ``NonExistentNodeException`` will be raised, and none of the nodes will be inserted.
:param name_value_pairs: Each tuple should be a pair (name, value), where name is the name of the node to insert the value into.
:type name_value_pairs: List of tuples
"""
LOG.debug('Inserting value into nodes {}'.format(", ".join(str(name) for name, value in name_value_pairs)))
for name, value in name_value_pairs:
if name not in self.dag:
raise NonExistentNodeException('Node {} does not exist'.format(str(name)))
stale = set()
computable = set()
for name, value in name_value_pairs:
self._set_state_and_value(name, States.UPTODATE, value)
stale.update(nx.dag.descendants(self.dag, name))
computable.update(self.dag.successors(name))
names = set([name for name, value in name_value_pairs])
stale.difference_update(names)
computable.difference_update(names)
for name in stale:
self._set_state(name, States.STALE)
for name in computable:
self._try_set_computable(name)
评论列表
文章目录