nengo / nengo-loihi

Run Nengo models on Intel's Loihi chip
https://www.nengo.ai/nengo-loihi/
Other
35 stars 12 forks source link

Passthrough removal broken when connecting from passthrough -> host #213

Open arvoelke opened 5 years ago

arvoelke commented 5 years ago
import nengo
import nengo_loihi
from nengo_loihi.passthrough import convert_passthroughs

with nengo.Network() as model:

    u = nengo.Node(output=1)
    x = nengo.Ensemble(10, 1, label="x")
    passthrough = nengo.Node(size_in=1, label="passthrough")
    y = nengo.Ensemble(10, 1, label="y")
    offchip = nengo.Node(size_in=1, label="offchip")

    nengo.Connection(u, x)
    nengo.Connection(x, passthrough)
    nengo.Connection(passthrough, y)
    nengo.Connection(passthrough, offchip)

    p = nengo.Probe(offchip)

print(convert_passthroughs(model, {u}))

for remove_passthrough in (False, True):
    with nengo_loihi.Simulator(model,
                               remove_passthrough=remove_passthrough) as sim:
        sim.run(1.0)

    print("remove_passthrough=%s, offchip mean=%s" % (
        remove_passthrough, sim.data[p].mean()))
({<Node "passthrough" at 0x7ff72804d7f0>}, {<Connection at 0x7ff7282c3ba8 from <Node "passthrough"> to <Node "offchip">>, <Connection at 0x7ff7284166a0 from <Node "passthrough"> to <Ensemble "y">>, <Connection at 0x7ff73116fef0 from <Ensemble "x"> to <Node "passthrough">>}, {<Connection at 0x7ff7282c3cf8 from <Ensemble "x"> to <Ensemble "y">>})
remove_passthrough=False, offchip mean=0.8331233504684199
remove_passthrough=True, offchip mean=0.0

The passthrough is removed, and no connections are made to replace nengo.Connection(passthrough, offchip). As a result, the offchip probe reports a flat zero, unless of course remove_passthrough is disabled.

tcstewar commented 3 years ago

Here's another network that triggers this bug (or a very related one):

model = nengo.Network()
with model:
    stim = nengo.Node(np.sin)
    s1 = nengo.Node(None, size_in=1)
    out = nengo.Node(None, size_in=1)
    nengo.Connection(stim, s1, synapse=None)
    nengo.Connection(s1, out)

    a = nengo.Ensemble(n_neurons=50, dimensions=1)
    nengo.Connection(s1, a)
    nengo.Connection(a, out)

    p = nengo.Probe(out)

I'm probing out, and it has two inputs: one from the on-chip Ensemble a, and one from s1 which is just an off-chip passthrough Node whose only input is the stimulus Node stim. The result is a probe that just records 0 all the time (rather than recording the sum of a and stim). If you change either of the Nodes from passthroughs to lambda t,x:x Nodes, then the problem goes away.