Skip to content

Commit

Permalink
Composition: fix TERMINAL node detection (#2384)
Browse files Browse the repository at this point in the history
if a TERMINAL node in a Composition that was not in the final
consideration set had an inactive projection to another node, the
TERMINAL role was not assigned because the active/inactive status was
not considered
  • Loading branch information
kmantel authored Apr 12, 2022
1 parent 36c611a commit e941c55
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 4 additions & 1 deletion psyneulink/core/compositions/composition.py
Original file line number Diff line number Diff line change
Expand Up @@ -4566,7 +4566,10 @@ def _determine_origin_and_terminal_nodes_from_consideration_queue(self):
# consideration set. Identifying these assumes that graph_processing has been called/updated,
# which identifies and "breaks" cycles, and assigns FEEDBACK_SENDER to the appropriate consideration set(s).
for node in self.nodes:
if not any([efferent for efferent in node.efferents if efferent.receiver.owner is not self.output_CIM]):
if not any([
efferent.is_active_in_composition(self) for efferent in node.efferents
if efferent.receiver.owner is not self.output_CIM
]):
self._add_node_role(node, NodeRole.TERMINAL)

def _add_node_aux_components(self, node, context=None):
Expand Down
11 changes: 11 additions & 0 deletions tests/composition/test_composition.py
Original file line number Diff line number Diff line change
Expand Up @@ -7351,6 +7351,17 @@ def test_controller_role(self):
assert comp.get_nodes_by_role(NodeRole.CONTROLLER) == [comp.controller]
assert comp.nodes_to_roles[comp.controller] == {NodeRole.CONTROLLER}

def test_inactive_terminal_projection(self):
A = pnl.ProcessingMechanism(name='A')
B = pnl.ProcessingMechanism(name='B')
C = pnl.ProcessingMechanism(name='C')
D = pnl.ProcessingMechanism(name='D')

pnl.MappingProjection(sender=A, receiver=D)
comp = pnl.Composition([[A],[B,C]])

assert comp.nodes_to_roles[A] == {NodeRole.INPUT, NodeRole.OUTPUT, NodeRole.SINGLETON, NodeRole.ORIGIN, NodeRole.TERMINAL}


class TestMisc:

Expand Down

0 comments on commit e941c55

Please sign in to comment.