Esempio n. 1
0
def test_precompute_remove_passthrough():
    with nengo.Network() as net:
        host = nengo.Node(0, label="host")
        onchip1 = nengo.Ensemble(1, 1, label="onchip1")
        passthrough1 = nengo.Node(size_in=1, label="passthrough1")
        onchip2 = nengo.Ensemble(1, 1, label="onchip2")
        passthrough2 = nengo.Node(size_in=1, label="passthrough2")
        onchip3 = nengo.Ensemble(1, 1, label="onchip3")

        nengo.Connection(host, onchip1)
        nengo.Connection(onchip1, passthrough1)
        nengo.Connection(passthrough1, onchip2)
        nengo.Connection(onchip2, passthrough2)
        nengo.Connection(passthrough2, onchip3)

    split = Split(net, precompute=True, remove_passthrough=True)

    assert split.precomputable(host)
    assert not split.on_chip(host)

    for obj in (onchip1, passthrough1, onchip2, passthrough2, onchip3):
        assert not split.precomputable(obj)

    for obj in (onchip1, onchip2, onchip3):
        assert split.on_chip(obj)
Esempio n. 2
0
def test_place_ensembles():
    # builder will move the learning stuff onto the host

    with nengo.Network() as net:
        add_params(net)
        offchip = nengo.Ensemble(10, 1, label="offchip")
        net.config[offchip].on_chip = False
        direct = nengo.Ensemble(1,
                                1,
                                neuron_type=nengo.Direct(),
                                label="direct")
        with nengo.Network():
            onchip = nengo.Ensemble(20, 1, label="onchip")
        pre = nengo.Ensemble(10, 1, label="pre")
        post = nengo.Ensemble(10, 1, label="post")
        error = nengo.Ensemble(10, 1, label="error")
        conn = nengo.Connection(pre, post, learning_rule_type=nengo.PES())
        nengo.Connection(error, conn.learning_rule)

    split = Split(net)
    assert not split.on_chip(offchip)
    assert not split.on_chip(direct)
    assert split.on_chip(onchip)
    assert split.on_chip(pre)
    assert not split.on_chip(post)
    assert not split.on_chip(error)

    for obj in net.all_ensembles + net.all_nodes:
        assert not split.precomputable(obj)

    with pytest.raises(BuildError, match="Locations are only established"):
        split.on_chip(conn)
Esempio n. 3
0
def test_split_pre_from_host():
    with nengo.Network() as net:
        add_params(net)
        pre_1 = nengo.Node(0, label="pre_1")
        pre_2 = nengo.Ensemble(10, 1, label="pre_2")
        pre_3 = nengo.Node(size_in=1, label="pre_3")
        pre_4 = nengo.Ensemble(1, 1, label="pre_4")
        pre_5 = nengo.Probe(pre_4)

        onchip = nengo.Ensemble(1, 1, label="onchip")
        post1 = nengo.Ensemble(10, 1, label="post1")
        post2 = nengo.Node(size_in=1, label="post2")
        post3 = nengo.Probe(post2, label="post3")

        nengo.Connection(pre_1, pre_2)
        nengo.Connection(pre_2, pre_3)
        nengo.Connection(pre_3, pre_4)
        nengo.Connection(pre_4.neurons, onchip)
        nengo.Connection(onchip, post1)
        nengo.Connection(post1, post2)

        net.config[pre_2].on_chip = False
        net.config[pre_4].on_chip = False
        net.config[post1].on_chip = False

    split = Split(net, precompute=True)

    host_precomputable = {pre_1, pre_2, pre_3, pre_4, pre_5}
    for obj in host_precomputable:
        assert not split.on_chip(obj)
        assert split.precomputable(obj)

    host_nonprecomputable = {post1, post2, post3}
    for obj in host_nonprecomputable:
        assert not split.on_chip(obj)
        assert not split.precomputable(obj)

    assert split.on_chip(onchip)
    assert not split.precomputable(onchip)

    assert not split.precomputable(nengo.Node(0, add_to_container=False))