From b4aa369918d4c0cc1cb7d0b4c6b59682e5577176 Mon Sep 17 00:00:00 2001 From: Katherine Mantel Date: Fri, 10 Nov 2023 22:45:31 +0000 Subject: [PATCH] Composition: use graph_processing for node role determination with the use of graph structure conditions, the scheduler graph may be different than the composition graph --- psyneulink/core/compositions/composition.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/psyneulink/core/compositions/composition.py b/psyneulink/core/compositions/composition.py index 930ba8cc3f7..f2295015da4 100644 --- a/psyneulink/core/compositions/composition.py +++ b/psyneulink/core/compositions/composition.py @@ -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 @@ -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: @@ -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) @@ -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