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 15, 2019
1 parent f9baeb5 commit 4f996cd
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 2 deletions.
9 changes: 7 additions & 2 deletions nengo_loihi/builder/probe.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,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
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,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
19 changes: 19 additions & 0 deletions nengo_loihi/tests/test_splitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,25 @@ def test_split_remove_passthrough(remove_passthrough):
assert pd == (set(), set(), 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])

splitter_directive = SplitterDirective(model, remove_passthrough=True)

assert splitter_directive.passthrough_directive == (set(), set(), set())

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


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

0 comments on commit 4f996cd

Please sign in to comment.