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 30, 2017
1 parent b006b58 commit 08a3674
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ Release History
odd initial dimensionality.
(`#52 <https://github.com/nengo/nengo_spa/issues/52>`_,
`#53 <https://github.com/nengo/nengo_spa/pull/53>`_)
- When building actions the basal ganglia and thalamus will only be created
when actually required.
(`#60 <https://github.com/nengo/nengo_spa/pull/60>`_,
`#42 <https://github.com/nengo/nengo_spa/issues/42>`_)


0.2 (June 22, 2017)
Expand Down
12 changes: 11 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 @@ -221,8 +224,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):
needs_bg = len(self.actions) > 0
needs_bg = len(self.bg_actions) > 0

if len(Network.context) <= 0:
raise NetworkContextError(
Expand All @@ -238,6 +246,8 @@ def build(self):
thalamus.actions.ensembles[i].label = (
'action[{}]: {}'.format(i, a.effects))
thalamus.connect_bg(bg)
else:
bg = thalamus = None

self.construction_context = ConstructionContext(
root_network, bg=bg, thalamus=thalamus)
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 @@ -188,3 +188,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)
actions = spa.Actions(('state1 = state2',))

assert actions.bg is None
assert actions.thalamus is None

0 comments on commit 08a3674

Please sign in to comment.