Пример #1
0
def test_make_subgraph():
    sub = Graph()
    sub.add_component('Head', Passthru)
    sub.add_component('Tail', Passthru)

    sub.connect('Head.OUT', 'Tail.IN')

    sub.export('Head.IN', 'IN')
    sub.export('Tail.OUT', 'OUT')

    PassNet = make_subgraph(sub, name='PassNet')

    assert len(PassNet.inport_definitions) == 2
    assert len(PassNet.outport_definitions) == 2

    graph = Graph()
    capture = graph.add_component('Capture', Capture)

    graph.add_component('Pass', PassNet)
    graph.initialize(5, 'Pass.IN')
    graph.connect('Pass.OUT', 'Capture.IN')

    run_graph(graph)

    assert capture.value == 5
Пример #2
0
def test_get_spec():
    sub = Graph()
    sub.add_component('Head', Passthru)
    sub.add_component('Tail', Passthru)

    sub.connect('Head.OUT', 'Tail.IN')

    sub.export('Head.IN', 'IN')
    sub.export('Tail.OUT', 'OUT')

    PassNet = make_subgraph(sub, name='PassNet')
    spec = PassNet.get_spec()

    assert spec['name'] == 'abc/PassNet'
    assert len(spec['inPorts']) == 2
    assert len(spec['outPorts']) == 2
Пример #3
0
    def add_graph(self, name, graph, **initializations):
        """
        Instantiate a component and add it to the network.

        Parameters
        ----------
        name : str
            name of component within the graph
        graph : ``Graph``
            graph to add

        Returns
        -------
        ``rill.engine.component.Component``
        """
        from rill.engine.subnet import make_subgraph
        comp_type = make_subgraph(name, graph)
        return self.add_component(name, comp_type, **initializations)
Пример #4
0
    def add_graph(self, graph, bases=None, name=None, **initializations):
        """
        Instantiate a component and add it to the network.

        Parameters
        ----------
        graph : ``Graph``
            graph to add
        bases : Union[``SubGraph``, Iterable[``SubGraph``]]
            Base classes to be used when constructing a SubGraph class.
        name : Optional[str]
            name of component within the graph

        Returns
        -------
        ``rill.engine.component.Component``
        """
        from rill.engine.subnet import make_subgraph
        if name is None and graph.name is None:
            raise ValueError(
                'Must provide a name or the graph must have a name.')
        name = name or graph.name
        comp_type = make_subgraph(graph, bases=bases, name=name)
        return self.add_component(name, comp_type, **initializations)
Пример #5
0
 def register_graph_component(self, graph):
     subgraph = make_subgraph(graph)
     self.register_component(subgraph, overwrite=True)
Пример #6
0
 def get_subnet_component(self, graph_id):
     graph = self.get_graph(graph_id)
     Sub = make_subgraph(str(graph_id), graph)
     return Sub