Beispiel #1
0
    def __init__(self,
                 arg: pype_input_type = None,
                 name: Optional[Hashable] = None):
        """

        """
        # graphs for data flow and data dependency
        self.flow = _WrapDiGraph()
        self.flow.add_wrap(task.pype_input.wrap())
        self.dependencies = _WrapDiGraph()
        # validation state and counts
        self.validated = False
        # dict for outputs of last call
        self.outputs = {}
        self._partials = {}
        # add first task to pype
        if arg is not None:  # add task to pype
            with suppress(TypeError):
                arg = self.__class__._registered_pypes.get(arg, arg)
            _connect_to_pype(self, arg, inplace=True)
        self.register(name or getattr(arg, "name", None))
Beispiel #2
0
 def test_combine_two_digraphs(self):
     """ ensure adding two networks combines all sets and dicts but does
     not modify the original networks """
     # create 2 networks
     edges1 = [(ws[1], ws[2]), (ws[3], ws[4])]
     edges2 = [(ws[5], ws[6]), (ws[7], ws[8]), (ws[1], ws[4])]
     d1 = _WrapDiGraph(edges=edges1)
     d2 = _WrapDiGraph(edges=edges2)
     # create new network
     d3 = d1 | d2
     # ensure nodes updated
     assert set(ws[num] for num in range(1, 9)) == set(d3.wraps)
     # ensure edges updated
     assert set(edges1 + edges2) == set(d3.edges)
     # make sure old graphs didn't change
     assert d3 is not d1 and d3 is not d2
     assert set(d1.edges) == set(edges1)
     assert set(d2.edges) == set(edges2)
     assert set(d2.neighbors(ws[1])) == {ws[4]}
     assert {**d1.tasks, **d2.tasks} == d3.tasks
     assert {**d1.wraps, **d2.wraps} == d3.wraps
Beispiel #3
0
def pype_net1():
    """ a simple network that uses the input pype """
    digraph = _WrapDiGraph()
    digraph.add_edge([(pype_input.wrap(), ws[1]), (ws[1], ws[2]),
                      (ws[2], ws[3])])
    return digraph
Beispiel #4
0
def filled_digraph():
    """ create a digraph that is populated with some wraps """
    digraph = _WrapDiGraph()
    digraph.add_wrap([ws[1], ws[2], ws[3], ws[4]])
    digraph.add_edge([(ws[2], ws[3]), (ws[1], ws[2]), (ws[3], ws[4])])
    return digraph
Beispiel #5
0
def digraph():
    """ init an empty digraph """
    return _WrapDiGraph()
Beispiel #6
0
 def test_init_graph_with_wraps(self, digraph):
     wraps = list(ws.values())
     graph = _WrapDiGraph(wraps=wraps)
     assert set(wraps) == set(graph.wraps)