Skip to content

Commit

Permalink
Raise BuildError if learning objects are on_chip
Browse files Browse the repository at this point in the history
Fixes #208 and #209.
  • Loading branch information
arvoelke committed Mar 29, 2019
1 parent 4cfb5da commit dd6f526
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
8 changes: 8 additions & 0 deletions nengo_loihi/new_splitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,18 @@ def __init__(self, network, precompute=False, remove_passthrough=True):
if (conn.learning_rule_type is not None
and isinstance(post, Ensemble)
and post in self._chip_objects):
if network.config[post].on_chip:
raise BuildError("Post ensemble (%r) of learned "
"connection (%r) must not be configured "
"as on_chip." % (post, conn))
self._chip_objects.remove(post)
elif (isinstance(post, LearningRule)
and isinstance(pre, Ensemble)
and pre in self._chip_objects):
if network.config[pre].on_chip:
raise BuildError("Pre ensemble (%r) of error "
"connection (%r) must not be configured "
"as on_chip." % (pre, conn))
self._chip_objects.remove(pre)

# Step 4. Mark passthrough nodes for removal
Expand Down
28 changes: 28 additions & 0 deletions nengo_loihi/tests/test_new_splitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,31 @@ def test_already_moved_to_host():
splitter_directive = SplitterDirective(net)
with pytest.raises(ValueError, match="must be on chip"):
splitter_directive.move_to_host(u)


def test_chip_learning_errors():
with nengo.Network() as net:
add_params(net)

a = nengo.Ensemble(100, 1)
b = nengo.Ensemble(100, 1)
net.config[b].on_chip = True

nengo.Connection(a, b, learning_rule_type=nengo.PES())

with pytest.raises(BuildError, match="Post ensemble"):
SplitterDirective(net)

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

a = nengo.Ensemble(100, 1)
b = nengo.Ensemble(100, 1)
error = nengo.Ensemble(100, 1)
net.config[error].on_chip = True

conn = nengo.Connection(a, b, learning_rule_type=nengo.PES())
nengo.Connection(error, conn.learning_rule)

with pytest.raises(BuildError, match="Pre ensemble"):
SplitterDirective(net)

0 comments on commit dd6f526

Please sign in to comment.