Skip to content

Commit

Permalink
Parameters: use toposort_key for dependency ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
kmantel committed Dec 19, 2023
1 parent 96dfa6f commit b655fff
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions psyneulink/core/globals/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ def _recurrent_transfer_mechanism_matrix_setter(value, owning_component=None, co
from psyneulink.core.globals.context import time as time_object
from psyneulink.core.globals.log import LogCondition, LogEntry, LogError
from psyneulink.core.globals.utilities import call_with_pruned_args, copy_iterable_with_shared, \
get_alias_property_getter, get_alias_property_setter, get_deepcopy_with_shared, unproxy_weakproxy, create_union_set, safe_equals, get_function_sig_default_value
get_alias_property_getter, get_alias_property_setter, get_deepcopy_with_shared, toposort_key, unproxy_weakproxy, create_union_set, safe_equals, get_function_sig_default_value
from psyneulink.core.rpc.graph_pb2 import Entry, ndArray

__all__ = [
Expand Down Expand Up @@ -620,27 +620,27 @@ def _dependency_order_key(self, names=False):
types.FunctionType: a function that may be passed in as sort
key so that any Parameter is placed before its dependencies
"""
parameter_function_ordering = list(toposort.toposort({
p.name: p.dependencies for p in self if p.dependencies is not None
}))
parameter_function_ordering = list(
itertools.chain.from_iterable(parameter_function_ordering)
)
def handle_names(param_or_name):
try:
param = getattr(self, param_or_name)
except (AttributeError, TypeError):
param = param_or_name

if names:
def ordering(p):
try:
return parameter_function_ordering.index(p)
except ValueError:
return -1
else:
def ordering(p):
try:
return parameter_function_ordering.index(p.name)
except ValueError:
return -1
if names:
return param.name
else:
return param

dependency_dict = {}
for param in self:
try:
deps = {handle_names(dep) for dep in param.dependencies}
except TypeError:
deps = {}

dependency_dict[handle_names(param)] = deps

return ordering
return toposort_key(dependency_dict)

@property
def _in_dependency_order(self):
Expand Down

0 comments on commit b655fff

Please sign in to comment.