Skip to content

Commit

Permalink
Only create basal ganglia and thalamus if required.
Browse files Browse the repository at this point in the history
Fixes #42.
  • Loading branch information
jgosmann committed Jun 29, 2017
1 parent 82e33dc commit 11dedc6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
10 changes: 9 additions & 1 deletion nengo_spa/actions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
"""Parsing of SPA actions."""

from itertools import chain

from nengo.exceptions import NetworkContextError, SpaParseError
from nengo.network import Network
from nengo_spa.modules.basalganglia import BasalGanglia
Expand Down Expand Up @@ -211,8 +214,13 @@ def _parse_and_add(self, parser, action, name=None):
if name is not None:
self.named_actions[name] = ast

@property
def bg_actions(self):
return [a for a in chain(self.actions, self.named_actions.values())
if isinstance(a, Action)]

def build(self, bg=None, thalamus=None):
needs_bg = len(self.actions) > 0
needs_bg = len(self.bg_actions) > 0

if len(Network.context) <= 0:
raise NetworkContextError(
Expand Down
10 changes: 10 additions & 0 deletions nengo_spa/tests/test_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,13 @@ def test_provides_access_to_constructed_objects_of_effect():
else:
raise AssertionError("Unexpected object constructed for Bind.")
assert n_connections == 2 and n_bind == 1


def test_bg_and_thalamus_only_created_when_required():
with spa.Network() as model:
model.state1 = spa.State(16)
model.state2 = spa.State(16)
bg, thalamus, _ = spa.Actions('state1 = state2').build()

assert bg is None
assert thalamus is None

0 comments on commit 11dedc6

Please sign in to comment.