Skip to content

Commit

Permalink
Merge pull request #1954 from kmantel/update-master
Browse files Browse the repository at this point in the history
Update master
  • Loading branch information
kmantel authored Mar 16, 2021
2 parents a2d06bf + 94de081 commit d105add
Show file tree
Hide file tree
Showing 11 changed files with 1,024 additions and 366 deletions.
16 changes: 16 additions & 0 deletions psyneulink/core/components/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -3475,6 +3475,22 @@ def log_values(self, entries):
"""
self.log.log_values(entries)

def _propagate_most_recent_context(self, context=None, visited=None):
if visited is None:
visited = set([self])

if context is None:
context = self.most_recent_context

self.most_recent_context = context

# TODO: avoid duplicating objects in _dependent_components
# throughout psyneulink or at least condense these methods
for obj in self._dependent_components:
if obj not in visited:
visited.add(obj)
obj._propagate_most_recent_context(context, visited)

@property
def _dict_summary(self):
from psyneulink.core.compositions.composition import Composition
Expand Down
45 changes: 26 additions & 19 deletions psyneulink/core/components/mechanisms/mechanism.py
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,7 @@ class `UserList <https://docs.python.org/3.6/library/collections.html?highlight=
from psyneulink.core.globals.registry import register_category, remove_instance_from_registry
from psyneulink.core.globals.utilities import \
ContentAddressableList, append_type_to_name, convert_all_elements_to_np_array, convert_to_np_array, \
iscompatible, kwCompatibilityNumeric
iscompatible, kwCompatibilityNumeric, convert_to_list
from psyneulink.core.scheduling.condition import Condition, TimeScale

__all__ = [
Expand Down Expand Up @@ -2307,7 +2307,9 @@ def execute(self,
input=None,
context=None,
runtime_params=None,
report_output=False
report_output=None,
report_params=None,
run_report=None
):
"""Carry out a single `execution <Mechanism_Execution>` of the Mechanism.
Expand Down Expand Up @@ -2530,23 +2532,28 @@ def execute(self,
if not self.parameters.execute_until_finished._get(context):
break

# REPORT EXECUTION if called from command line
# If called by a Composition, it handles reporting.
if context.source == ContextFlags.COMMAND_LINE:
# FIX: 3/11/21 THIS SHOULD BE REFACTORED TO USE Report.report_output rather than printing directly
from psyneulink.core.compositions.report import ReportOutput
if (self.prefs.reportOutputPref is not ReportOutput.OFF
and (context.execution_phase & ContextFlags.PROCESSING | ContextFlags.LEARNING)):
from psyneulink.core.compositions.report import Report
from rich import print
if self.prefs.reportOutputPref is ReportOutput.TERSE:
print(f'{self.name} executed')
else:
print(Report.node_execution_report(self,
input_val=self.get_input_values(context),
output_val=self.output_port.parameters.value._get(context),
report_output=True,
context=context))
# REPORT EXECUTION

if (context.source == ContextFlags.COMMAND_LINE or
context.execution_phase & (ContextFlags.PROCESSING | ContextFlags.LEARNING)):
from psyneulink.core.compositions.report import Report, ReportOutput, ReportParams
# Use report_output and report_params options passed to execute from Composition or command line;
# otherwise try to get from Mechanism's reportOutputPref
report_output = report_output or next((pref for pref in convert_to_list(self.prefs.reportOutputPref)
if isinstance(pref, ReportOutput)), None)
report_params = report_params or next((pref for pref in convert_to_list(self.prefs.reportOutputPref)
if isinstance(pref, ReportParams)), None)
if report_output is not ReportOutput.OFF:
with Report(self, context=context) as report:
report.report_output(caller=self,
report_num=run_report,
scheduler=None,
report_output=report_output,
report_params=report_params,
content='node',
context=context,
node=self)

return value

def _get_variable_from_input(self, input, context=None):
Expand Down
Loading

0 comments on commit d105add

Please sign in to comment.