Skip to content

Commit

Permalink
Composition: use graph_processing for node role determination
Browse files Browse the repository at this point in the history
with the use of graph structure conditions, the scheduler graph may be
different than the composition graph
  • Loading branch information
kmantel committed Nov 10, 2023
1 parent 77557ad commit b4aa369
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions psyneulink/core/compositions/composition.py
Original file line number Diff line number Diff line change
Expand Up @@ -2892,6 +2892,7 @@ def input_function(env, result):
import networkx
import numpy as np
import pint
import toposort
from PIL import Image
from beartype import beartype

Expand Down Expand Up @@ -4958,12 +4959,12 @@ def _determine_origin_and_terminal_nodes_from_consideration_queue(self):
controller may not be NodeRole.TERMINAL, so if the ObjectiveMechanism is the only node in the last entry
of the consideration queue, then the second-to-last entry is NodeRole.TERMINAL instead.
"""
queue = self.scheduler.consideration_queue
queue = list(toposort.toposort(self.graph_processing.dependency_dict))

for node in list(queue)[0]:
for node in queue[0]:
self._add_node_role(node, NodeRole.ORIGIN)

for node in list(queue)[-1]:
for node in queue[-1]:
if NodeRole.CONTROLLER_OBJECTIVE not in self.get_roles_by_node(node):
self._add_node_role(node, NodeRole.TERMINAL)
elif len(queue[-1]) < 2:
Expand Down Expand Up @@ -5170,7 +5171,9 @@ def _determine_node_roles(self, context=None):
Assignment criteria:

ORIGIN:
- all Nodes that are in first consideration_set (i.e., self.scheduler.consideration_queue[0]).
- all Nodes that are in first consideration_set (i.e.,
self.graph_processing.consideration_queue[0]).

.. _note::
- this takes account of any Projections designated as feedback by graph_processing
(i.e., self.graph.comp_to_vertex[efferent].feedback == EdgeType.FEEDBACK)
Expand Down Expand Up @@ -5275,8 +5278,8 @@ def _determine_node_roles(self, context=None):
for node_role_pair in self.required_node_roles:
self._add_node_role(node_role_pair[0], node_role_pair[1])

# Get ORIGIN and TERMINAL Nodes using self.scheduler.consideration_queue
if self.scheduler.consideration_queue:
# Get ORIGIN and TERMINAL Nodes using self.graph_processing.consideration_queue
if self.graph_processing:
self._determine_origin_and_terminal_nodes_from_consideration_queue()

# INPUT
Expand Down

0 comments on commit b4aa369

Please sign in to comment.