Пример #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_network_export():
    graph = Graph()
    passthru = graph.add_component("Pass", SlowPass, DELAY=0.1)

    graph.export('Pass.OUT', 'OUT')
    graph.export('Pass.IN', 'IN')

    assert len(graph.inports.keys()) == 1
    assert len(graph.outports.keys()) == 1
Пример #3
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
Пример #4
0
def get_graph(graph_name):
    graph = Graph(name=graph_name)

    gen = graph.add_component('Generate', GenerateTestData)
    gen.metadata['x'] = 5
    gen.metadata['y'] = 5

    passthru = graph.add_component('Pass', Passthru)
    outside = graph.add_component('Outside', Passthru)

    graph.connect('Generate.OUT', 'Pass.IN')
    graph.connect('Outside.OUT', 'Pass.IN')
    graph.initialize(5, 'Generate.COUNT')
    graph.export('Pass.OUT', 'OUTPORT')
    graph.export('Outside.IN', 'INPORT')
    return graph, gen, passthru, outside
Пример #5
0
def test_network_apply():
    graph = Graph()
    graph.add_component('Add1', Add)
    graph.add_component('Add2', Add)

    graph.connect('Add1.OUT', 'Add2.IN1')

    graph.export('Add1.IN1', 'IN1')
    graph.export('Add1.IN2', 'IN2')
    graph.export('Add2.IN2', 'IN3')
    graph.export('Add2.OUT', 'OUT')

    outputs = run_graph(graph, {
        'IN1': 1,
        'IN2': 3,
        'IN3': 6
    }, capture_results=True)

    assert outputs['OUT'] == 10
Пример #6
0
def test_network_apply_with_outputs():
    graph = Graph()
    graph.add_component('Add1', Add)
    graph.add_component('Add2', Add)
    graph.add_component('Kick', Kick)

    graph.connect('Add1.OUT', 'Add2.IN1')

    graph.export('Add1.IN1', 'IN1')
    graph.export('Add1.IN2', 'IN2')
    graph.export('Add2.IN2', 'IN3')
    graph.export('Add2.OUT', 'OUT')
    graph.export('Kick.OUT', 'Kick_OUT')

    outputs = run_graph(graph, {'IN1': 1, 'IN2': 3, 'IN3': 6}, ['OUT'])

    assert outputs == {'OUT': 10}
Пример #7
0
def test_export_serialization():
    graph = Graph()

    graph.add_component('Head', SlowPass, DELAY=0.01)
    graph.add_component('Tail', SlowPass, DELAY=0.01)

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

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

    definition = graph.to_dict()
    expected = {
        'processes': {
            'Head': {
                'component': 'rill.components.timing/SlowPass',
                'metadata': {}
            },
            'Tail': {
                'component': 'rill.components.timing/SlowPass',
                'metadata': {}
            }
        },
        'connections': [
            {
                'src': {'data': 0.01},
                'tgt': {
                    'process': 'Head',
                    'port': 'DELAY'
                }
            },
            {
                'src': {'data': 0.01},
                'tgt': {
                    'process': 'Tail',
                    'port': 'DELAY'
                }
            },
            {
                'src': {
                    'process': 'Head',
                    'port': 'OUT'
                },
                'tgt': {
                    'process': 'Tail',
                    'port': 'IN'
                }
            }
        ],
        'inports': {
            'IN': {
                'process': 'Head',
                'port': 'IN',
                'metadata': {}
            }
        },
        'outports': {
            'OUT': {
                'process': 'Tail',
                'port': 'OUT',
                'metadata': {}
            }
        }
    }

    # Order of connections array shouldn't matter
    definition['connections'] = sorted(definition['connections'], key=str)
    expected['connections'] = sorted(expected['connections'], key=str)

    assert definition == expected