Skip to content

Commit

Permalink
Handle sliced probes
Browse files Browse the repository at this point in the history
Closes #205 and #206.
  • Loading branch information
arvoelke authored and tbekolay committed Apr 24, 2019
1 parent 69404da commit d767ec4
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 2 deletions.
10 changes: 8 additions & 2 deletions nengo_loihi/builder/probe.py
@@ -1,5 +1,6 @@
import nengo
from nengo import Ensemble, Connection, Node
from nengo.base import ObjView
from nengo.connection import LearningRule
from nengo.ensemble import Neurons
from nengo.exceptions import BuildError
Expand Down Expand Up @@ -74,10 +75,15 @@ def conn_probe(model, nengo_probe):
model.seeded[conn] = model.seeded[nengo_probe]
model.seeds[conn] = model.seeds[nengo_probe]

if isinstance(nengo_probe.target, ObjView):
target_obj = nengo_probe.target.obj
else:
target_obj = nengo_probe.target

d = conn.size_out
if isinstance(nengo_probe.target, Ensemble):
if isinstance(target_obj, Ensemble):
# probed values are scaled by the target ensemble's radius
scale = nengo_probe.target.radius
scale = target_obj.radius
w = np.diag(scale * np.ones(d))
weights = np.vstack([w, -w])
else:
Expand Down
41 changes: 41 additions & 0 deletions nengo_loihi/tests/test_simulator.py
Expand Up @@ -801,6 +801,47 @@ def test_simulator_passthrough(remove_passthrough, Simulator):
assert conn_y_d not in model.params


def test_slicing_bugs(Simulator, seed):

n = 50
with nengo.Network() as model:
a = nengo.Ensemble(n, 1, label="a")
p0 = nengo.Probe(a[0])
p = nengo.Probe(a)

with Simulator(model) as sim:
sim.run(0.1)

assert np.allclose(sim.data[p0], sim.data[p])
assert a in sim.model.params
assert a not in sim.model.host.params

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

a = nengo.Ensemble(n, 1, label="a")

b0 = nengo.Ensemble(n, 1, label="b0", seed=seed)
model.config[b0].on_chip = False
nengo.Connection(a[0], b0)

b = nengo.Ensemble(n, 1, label="b", seed=seed)
model.config[b].on_chip = False
nengo.Connection(a, b)

p0 = nengo.Probe(b0)
p = nengo.Probe(b)

with Simulator(model) as sim:
sim.run(0.1)

assert np.allclose(sim.data[p0], sim.data[p])
assert a in sim.model.params
assert a not in sim.model.host.params
assert b not in sim.model.params
assert b in sim.model.host.params


def test_network_unchanged(Simulator):
with nengo.Network() as model:
nengo.Ensemble(100, 1)
Expand Down
20 changes: 20 additions & 0 deletions nengo_loihi/tests/test_splitter.py
Expand Up @@ -262,6 +262,26 @@ def test_split_remove_passthrough(remove_passthrough):
assert split.passthrough.to_add == set()


def test_sliced_passthrough_bug():
with nengo.Network() as model:
add_params(model)

a = nengo.Ensemble(1, 1, label="a")
passthrough = nengo.Node(size_in=1, label="passthrough")

nengo.Connection(a, passthrough)
p = nengo.Probe(passthrough[0])

split = Split(model, remove_passthrough=True)

assert len(split.passthrough.to_add) == 0
assert len(split.passthrough.to_remove) == 0

assert split.on_chip(a)
assert not split.on_chip(passthrough)
assert not split.on_chip(p)


def test_precompute_remove_passthrough():
with nengo.Network() as net:
add_params(net)
Expand Down

0 comments on commit d767ec4

Please sign in to comment.