예제 #1
0
    def testSubgraph(self):
        with Multigraph('sub') as sg:
            source1 = GeneratorSource('s1')
            source2 = GeneratorSource('s2', )
            p = components.Product('prod')
            p << InputPort('IN1')
            p << InputPort('IN2')
            source1.outputs.OUT >> p.inputs.IN1
            source2.outputs.OUT >> p.inputs.IN2
            source1.inputs.gen.set_initial_packet(range(5))
            source2.inputs.gen.set_initial_packet(range(5))
            sg.outputs.export(p.outputs.OUT, "OUT")

        with Multigraph('b') as g:
            g.add_node(sg)
            printer = components.ShowInputs('show')
            printer << InputPort('IN')
            print(sg.outputs.OUT == p.outputs.OUT)
            sg.outputs.OUT >> printer.inputs.IN
        print(p.outputs.OUT.component)
        print(sg.outputs.OUT.component)
        print(list(g.iterarcs()))
        print(list(g.iternodes()))
        g()
        with open('/tmp/graph.dot', 'w+') as of:
            of.write(g.dot())
예제 #2
0
 def testConnectingToNonExisting(self):
     source1 = GeneratorSource('s1', (i for i in range(5)))
     source2 = GeneratorSource('s2', (i for i in range(5)))
     p = components.Product('prod')
     p << InputPort('i')
     p >> OutputPort('OUT')
     p.inputs.j
     source1.outputs.OUT >> p.inputs.i
     source2.outputs.OUT >> p.inputs.j
예제 #3
0
 def testSplit(self):
     source1 = components.Product(
         's1',
         (i for i in range(3)),
         (i for i in range(3)),
     )
     splitter = components.Split('split in two')
     splitter.outputs.add(OutputPort('a'))
     splitter.outputs.add(OutputPort('b'))
     shower = ShowInputs('printer')
     shower.inputs.add(InputPort('a'))
     shower.inputs.add(InputPort('b'))
     graph = Multigraph()
     graph.connect(source1.outputs.OUT, splitter.inputs.IN)
     graph.connect(splitter.outputs.a, shower.inputs.a)
     graph.connect(splitter.outputs.b, shower.inputs.b)
     graph()
예제 #4
0
 def testProduct(self):
     source1 = GeneratorSource('s1')
     source2 = GeneratorSource('s2')
     range(5) >> source1.inputs.gen
     range(5) >> source2.inputs.gen
     p = components.Product('prod')
     printer = ShowInputs('printer')
     printer.inputs.add(InputPort('IN'))
     p.inputs.add(InputPort('i'))
     p.inputs.add(InputPort('j'))
     p.outputs.add(OutputPort('OUT'))
     g = Multigraph('cul')
     g.connect(source1.outputs.OUT, p.inputs.i)
     g.connect(source2.outputs.OUT, p.inputs.j)
     g.connect(p.outputs.OUT, printer.inputs.IN)
     print(list(g.iterarcs()))
     print(g.dot())
     g()
예제 #5
0
 def testNiceConnection(self):
     with Multigraph() as g:
         source1 = GeneratorSource('s1', (i for i in range(5)))
         source2 = GeneratorSource('s2', (i for i in range(5)))
         p = components.Product('prod')
         printer = components.ShowInputs('print')
         # #Add ports
         p << InputPort('i')
         p << InputPort('j')
         p >> OutputPort('OUT')
         printer << InputPort('IN')
         #Connect ports
         source1.outputs.OUT >> p.inputs.i
         source2.outputs.OUT >> p.inputs.j
         p.outputs.OUT >> printer.inputs.IN
         # # #Add components
         # g = g + source1 + source2 + p + printer
         print(g.dot())
     g()
예제 #6
0
 def testCountWithReset(self):
     with Multigraph('test') as g:
         source1 = GeneratorSource('s1')
         source2 = GeneratorSource('s2')
         range(5) >> source1.inputs.gen
         range(5) >> source2.inputs.gen
         reset = components.WaitRandom('s3')
         p = components.Product('prod')
         c = components.Count('count')
         printer = ShowInputs('printer')
         printer.inputs.add(InputPort('IN'))
         p.inputs.add(InputPort('i'))
         p.inputs.add(InputPort('j'))
         g.connect(reset.outputs.OUT, c.inputs.reset)
         g.connect(source1.outputs.OUT, p.inputs.i)
         g.connect(source2.outputs.OUT, p.inputs.j)
         g.connect(p.outputs.OUT, c.inputs.IN)
         g.connect(c.outputs.count, printer.inputs.IN)
     print(list(g.iterarcs()))
     print(g.dot())
     g()
예제 #7
0
    def testSubnet(self):
        with Multigraph('sub') as sg:
            source1 = GeneratorSource('s1')
            source2 = GeneratorSource('s2', )
            p = components.Product('prod')
            p << InputPort('IN1')
            p << InputPort('IN2')
            source1.outputs.OUT >> p.inputs.IN1
            source2.outputs.OUT >> p.inputs.IN2
            source1.inputs.gen.set_initial_packet(range(5))
            source2.inputs.gen.set_initial_packet(range(5))
            sg.outputs.export(p.outputs.OUT, "OUT")

        with Multigraph('b') as g:
            sg = pyperator.subnet.Subnet.from_graph(sg)
            print(sg.outputs)
            printer = components.ShowInputs('show')
            printer << InputPort('IN')
            sg.outputs.OUT >> printer.inputs.IN
        g()
        with open('/tmp/graph.dot', 'w+') as of:
            of.write(g.dot())