Skip to content

Commit

Permalink
Composition: warn when using nested compositions with absolute time (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
kmantel authored Aug 7, 2021
1 parent b17e999 commit 8eed471
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions psyneulink/core/compositions/composition.py
Original file line number Diff line number Diff line change
Expand Up @@ -5510,6 +5510,31 @@ def _check_for_unnecessary_feedback_projections(self):
)
)

def _check_for_nesting_with_absolute_conditions(self, scheduler, termination_conds=None):
if any(isinstance(n, Composition) for n in self.nodes):
interval_conds = set()
fixed_point_conds = set()
for _, cond in scheduler.get_absolute_conditions(termination_conds).items():
if len(cond.absolute_intervals) > 0:
interval_conds.add(cond)
if scheduler.mode == SchedulingMode.EXACT_TIME:
if len(cond.absolute_fixed_points) > 0:
fixed_point_conds.add(cond)

warn_str = f'{self} contains a nested Composition, which may cause unexpected behavior in absolute time conditions or failure to terminate execution.'
warn = False
if len(interval_conds) > 0:
warn_str += '\nFor repeating intervals:\n\t'
warn_str += '\n\t'.join([f'{cond.owner}: {cond}\n\t\tintervals: {cond.absolute_intervals}' for cond in interval_conds])
warn = True
if len(fixed_point_conds) > 0:
warn_str += '\nIn EXACT_TIME SchedulingMode, strict time points:\n\t'
warn_str += '\n\t'.join([f'{cond.owner}: {cond}\n\t\tstrict time points: {cond.absolute_fixed_points}' for cond in fixed_point_conds])
warn = True

if warn:
warnings.warn(warn_str)

# ******************************************************************************************************************
# PATHWAYS
# ******************************************************************************************************************
Expand Down Expand Up @@ -8317,6 +8342,7 @@ def run(
self._analyze_graph(context=context)

self._check_for_unnecessary_feedback_projections()
self._check_for_nesting_with_absolute_conditions(scheduler, termination_processing)

# set auto logging if it's not already set, and if log argument is True
if log:
Expand Down

0 comments on commit 8eed471

Please sign in to comment.