nengo-loihi icon indicating copy to clipboard operation
nengo-loihi copied to clipboard

`on_chip` param lost when made in subnetwork

Open studywolf opened this issue 4 years ago • 4 comments

I found this unexpected

import nengo
import nengo_loihi

def make_subnet():

    with nengo.Network() as subnet:
        nengo_loihi.add_params(subnet)
        subnet.ens = nengo.Ensemble(100, 1)
        subnet.config[subnet.ens].on_chip=False
    return subnet

with nengo.Network() as net:
    nengo_loihi.add_params(net)

    subnet = make_subnet()
    print(net.config[subnet.ens].on_chip)

prints out None

studywolf avatar Jun 17 '20 17:06 studywolf

I think if you do print(subnet.config[subnet.ens].on_chip) it will work as expected (because that's where you set it, not net.config).

drasmuss avatar Jun 17 '20 17:06 drasmuss

What's more important is that setting on_chip on the subnet does not appear to work.

with nengo_loihi.Simulator(net) as sim:
    def print_ensembles(name, model):
        if len(model.params) == 0:
            return

        n_ensembles = len(set(obj for obj in model.params if isinstance(obj, nengo.Ensemble)))
        print("%s: %d ensembles" % (name, n_ensembles))

    print_ensembles("host_pre", sim.model.host_pre)
    print_ensembles("host", sim.model.host)
    print_ensembles("loihi", sim.model)

results in

loihi: 2 ensembles

for Travis's code above.

If I add net.config[subnet.ens].on_chip = False to Travis's code then I get the expected

host: 1 ensembles
loihi: 1 ensembles

hunse avatar Jun 17 '20 18:06 hunse

Ah yeah, related to https://github.com/nengo/nengo/issues/1601, basically NengoLoihi only looks at the top-level config, it doesn't check nested configs at all I don't think.

drasmuss avatar Jun 17 '20 18:06 drasmuss

Yeah, related to that, though it's even a bit trickier because the splitting is pre-builder, so even though we're setting/unsetting model.config and thus have access to the current network config when building the ensemble, we don't have this when we're splitting.

Here's a sketch of a fix, https://github.com/nengo/nengo-loihi/tree/config-on-chip

hunse avatar Jun 17 '20 18:06 hunse