Skip to content

Commit

Permalink
Composition: add_projection: also detect feedback from node roles (#2429
Browse files Browse the repository at this point in the history
)

Node roles may be specified in various places, including when specifying
a Pathway. These roles can imply that some projections should be
feedback, and it can be cumbersome to check for these in any place
add_projection may be called to pass feedback=True.

This checks for these roles in Composition.add_projection when adding an
edge to the Graph.

Fixes #2004
  • Loading branch information
kmantel authored Jul 7, 2022
1 parent 20598ad commit bd01378
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
9 changes: 9 additions & 0 deletions psyneulink/core/compositions/composition.py
Original file line number Diff line number Diff line change
Expand Up @@ -5816,6 +5816,15 @@ def add_projection(self,
projection.is_processing = False
# KDM 5/24/19: removing below rename because it results in several existing_projections
# projection.name = f'{sender} to {receiver}'

# check for required role specification of feedback projections
for node, role in self.required_node_roles:
if (
(node == projection.sender.owner and role == NodeRole.FEEDBACK_SENDER)
or (node == projection.receiver.owner and role == NodeRole.FEEDBACK_RECEIVER)
):
feedback = True

self.graph.add_component(projection, feedback=feedback)

try:
Expand Down
14 changes: 14 additions & 0 deletions tests/composition/test_composition.py
Original file line number Diff line number Diff line change
Expand Up @@ -7362,6 +7362,20 @@ def test_inactive_terminal_projection(self):

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

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

icomp = pnl.Composition(pathways=[C])
ocomp = pnl.Composition(pathways=[A, icomp, (B, pnl.NodeRole.FEEDBACK_SENDER), A])

assert ocomp.nodes_to_roles == {
A: {NodeRole.ORIGIN, NodeRole.INPUT, NodeRole.FEEDBACK_RECEIVER},
icomp: {NodeRole.INTERNAL},
B: {NodeRole.TERMINAL, NodeRole.OUTPUT, NodeRole.FEEDBACK_SENDER},
}


class TestMisc:

Expand Down

0 comments on commit bd01378

Please sign in to comment.