Ejemplo n.º 1
0
 def _create_nodes(self, stream, graph):
     assert (isinstance(stream['Nodes'], list))
     for i, node in enumerate(stream['Nodes']):
         try:
             node = eval(node)
             task = eval(node['task'])
             n = Node(func=task, kwargs=node['kwargs'])
             graph.add_node(i, {'ptr': n})
         except:
             print "create graph.node %d fail" % (i)
             raise
Ejemplo n.º 2
0
 def setUp(self):
     self.G = TestDAGWorker(debug=True)
     self.G.add_edge(0, 1, weight=2)
     self.G.add_edge(0, 2, weight=2)
     self.G.add_edge(2, 3, weight=2)
     for i in range(0,4):
         n = Node(func=nsum, args=(1,2))
         self.G.add_node(i, {'ptr': n})
     self.assertTrue(nx.is_directed_acyclic_graph(self.G))
     self.assertTrue(nx.ancestors(self.G,0) == set([]))
     self.assertTrue(nx.descendants(self.G,0) == set([1,2,3]))
     self.G.set_start_to_run(0)
     self.G.start()
Ejemplo n.º 3
0
 def setUp(self):
     self.G = TestDAGWorker(debug=True)
     for i in range(1,3):
         self.G.add_edge(i-1, i, weight=1)
     for i in range(0,3):
         n = Node(func=nsum, args=(1,2))
         self.G.add_node(i, {'ptr': n})
     # no cycle, loop 
     self.assertTrue(nx.is_directed_acyclic_graph(self.G))
     self.assertTrue(nx.topological_sort(self.G) == [0,1,2])
     self.assertTrue(nx.ancestors(self.G,0) == set([]))
     self.assertTrue(nx.descendants(self.G,0) == set([1,2]))
     self.G.set_start_to_run(0)
     self.G.start()
Ejemplo n.º 4
0
 def setUp(self):
     self.G = TestDAGWorker(debug=True)
     self.G.add_edge(0,1, weight=2)
     self.G.add_edge(1,2, weight=2)
     self.G.add_edge(0,2, weight=2)
     self.G.add_edge(0,3, weight=2)
     self.G.add_edge(3,2, weight=2)
     for i in range(0,4):
         n = Node(func=nsum, args=(1,2))
         self.G.add_node(i, {'ptr': n})
     # no cycle, loop 
     self.assertTrue(nx.is_directed_acyclic_graph(self.G))
     self.G.set_start_to_run(0)
     self.G.start()
Ejemplo n.º 5
0
    def _bind_start_task(self,
                         graph,
                         node,
                         nkwargs={},
                         init=False,
                         callback=None):
        if self._cst['start_tasks']:
            stream = self._cst['start_tasks'].pop(0)
        else:
            tasks = self._sample_hisitem_tasks(nkwargs)
            ptr, args = random.sample(tasks, 1)[0]
            stream = ptr(*args)

        task, kwargs = eval(stream['task']), stream['kwargs']
        graph.node[node]['ptr'] = Node(func=task, kwargs=kwargs)

        if init:
            self._update_init_task(graph, node)
        if callback:
            callback(graph, node)
Ejemplo n.º 6
0
 def setUp(self):
     self.G = TestDAGWorker(deubg=True)
     n = Node(func=nsum, args=(1,2))
     self.G.add_node(0, {'ptr': n})