Skip to content

Commit

Permalink
Feat/report/params (#1953)
Browse files Browse the repository at this point in the history
* • composition.py
  - run():  use rich.Progress for looping through trials

* -

* -

* -

* -

* -

* -

* -

* -

* -

* -

* -

* • composition.py
  - import placed at top

* -

* • composition.py
  - run(): added support for indeterminate progress using rich

* • composition.py
  - run(): clean-up of rich.progress code

* • composition.py
  - run(): clean-up of rich.progress code

* -

* • composition.py
  - run(): added support for indeterminate progress using rich

* • composition.py
  - run(): simulation progress now working properly

* • composition.py
  - run(): added show_progress and show_output args
  - execute(): added show_output arg

* • composition.py
  - run(): modified example in controlsignal.py docstring to pass test

* • composition.py
  - run(): modified example in controlsignal.py docstring to pass test

* -

* • Pulled from current devel

* • composition.py: bug fixes

* -

* • composition.py
  - last commit before implementing PNLprogress

* • composition.py
  - first draft using PNLProgress and _report_output

* • composition.py
  - first draft using PNLProgress and _report_output

* -

* -

* -

* -

* • PNLProgress working

* -

* • PNLProgress:  elaborated for future support of pnl_view

* -

* • progress.py:  added support for showing simulations

* • progress.py:  added support for showing simulations

* -

* -

* -

* • Fixed bug causing crash in test_nested_composition_run

* • Fixed bug causing crash in test_nested_composition_run

* -

* • Codestyle fixes

* • progress.py:
  - fixed simulation progress reporting
  - should consolidate all executions in a given simualation to a single task

• composition.py:
  - limited progress reporting to execute()
    (no longer in run)

• autodiffcomposition.py:
  - execute: added progress reporting
  - still need to handle output report

* -

* -

* -

* • Merged with devel

* -

* • Merged with devel

* -

* -

* -

* -

* -

* -

* • progress.py: working for nested sims

* -

* -

* -

* -

* -

* • composition.py: docstring updated for output and progress reporting

* • progress.py - bug fix
• composition.py - change show_output default to False

* • progress.py - bug fix

* • progress.py - patch trial_num reporting bug (with hack)

* • progress.py: before switch from rich_report to full_report

* -

* -

* -

* • Progress: before modifying PNLProgers._use_rich

* • Progress: implemented CAPTURE option for rich output

* -

* -

* • Preferences.rst - pointed to PreferenceSet.py
• preferenceset.py - created docstring to describe Standard Preferences

* -

* -

* • tests
  - composition:  added test_progress.py with unit tests for PNLProgress
• composition.py
  - execute(): modified context passed to node if it is a mechanism
               (assigns context.source as ContextFlags.COMPOSITION)

* -

* • composition.py and progress.py:
  refactoring show_output and show_progress into: report_output, report_progress, report_simulations, report_to_devices

* -

* -

* • report.py: updated docstrings with new args/attrs

* • report.py:
  - refactored args to use "report" as root
  - added _use_rich_console and _use_rich_capture
  - TODO: allow independent controle of consolse and capture

* • test_report.py: updated to use report_progress and report_to_devices

* -

* • report.py:
  - added independent rich divert and report recording

* -

* -

* -

* -

* -

* -

* -

* -

* -

* • report.py
  - report_output: fixes for simulation reporting

* -

* • composition.py
  - evaluate(): added use of Report context in call to composition.run()

* -

* -

* -

* -

* -

* -

* • report.py: docstring added

* -

* -

* -

* -

* • report.py:  modify to use ReportOutput enum

* -

* -

* • report.py: refactored to use ReportOutput enum

* • report.py: refactored to use ReportDevices enum

* • Project: refactored to use ReportOutput and ReportDevices enums
• Component:
  reportOoutputPref property and setter:  enforce assigment and retrieval of ReportOutput

* • Project: refactored to use ReportProgress and ReportSimulations enums

* -

* -

* • basepreferenceset.py:
  - modified reportOutputPref handling to convert False to ReportOutput.OFF and True to ReportOutput.TERSE

* -

* • report.py: allow reportOutputPrefs to be a list that includes 'params' and a ReportOutput option

* -

* -

* -

* • report.py, composition.py: (..._)progress_report(s) -> (...)run_reports(s)

* -

* • report.py:
  - added ReportOuput.ON as alias to ReportOutput.TERSE
  - fixed bug preventing progress reporting of simulations

* -

* • report.py:  added temporary simulation_depth tracking

* -

* -

* -

* • report.py, composition.py, mechanism.py:
  merged and working with refactor/report/mech_report

* - merged with devel

* • report.py, composition.py:
  fixed indentations of progress report for nested comps and simulations

* -

* • report.py, composition.py:
  elaborated depth tracking to disinguish between nested comps and controller sims

* • report.py - bug fix in simulation reporting

* • report.py, composition.py - implement and use Report._nesting_stack and Report._control_stack

* • report.py, composition.py - replaced _nesting and _control stacks with
single _execution_stack and added _nested and _simulating attributes

* • report.py: refactored to use _print_and_record_reports

* -

* -

* • report.py: refactored _print_and_record_reports

* -

* -

* -

* -

* • test_report.py: added tests for reports involving nested comps and simulations

* -

* -

* • report.py: minor mods

* • report.py:
  - support specification of individual params in reportOutputPref
  - support for indivdual function params still needs to be implemented

* - merged with devel

* • report.py:
  support specific params including functions
  latter still needs work

* • report.py:
  - node_execution_report(): function params now included, and listed at end of params

* • report.py:
  - node_execution_report(): function params now included, and listed at end of params

* -

* • report.py:
  - node_execution_report(): fixed bug in function parameter reporting (used primary function params for any secondary functions)

* • report.py:
  - node_execution_report(): fixed bug in function parameter reporting (used primary function params for any secondary functions)

* -

* -

* • preferenceset.py:  augmented documentation for reportOutputPref and added examples

* -

* -

* -

* -

* -

* -

* -

* -

* -

* -

* -

* -

* • report.py, composition.py, mechanism.py: added arguments and attributes for ReportParams

* • report.py, composition.py, mechanism.py: added arguments and attributes for ReportParams

* • report.py:
  - node_execution_report(): fix bugs

* • composition.py: fix bugs for report_params

* -

* • report.py
  - node_execution_report(): implemented ReportParams.MODULATED

* -

* -

* -

* -

* -

* -

* • report.py: supports ReportParams.MODULATED

* -

* -

* -

Co-authored-by: jdcpni <pniintel55>
  • Loading branch information
jdcpni committed Mar 16, 2021
1 parent 2330f4d commit 97af221
Show file tree
Hide file tree
Showing 4 changed files with 302 additions and 56 deletions.
8 changes: 6 additions & 2 deletions psyneulink/core/components/mechanisms/mechanism.py
Expand Up @@ -2308,6 +2308,7 @@ def execute(self,
context=None,
runtime_params=None,
report_output=None,
report_params=None,
run_report=None
):
"""Carry out a single `execution <Mechanism_Execution>` of the Mechanism.
Expand Down Expand Up @@ -2535,17 +2536,20 @@ def execute(self,

if (context.source == ContextFlags.COMMAND_LINE or
context.execution_phase & (ContextFlags.PROCESSING | ContextFlags.LEARNING)):
from psyneulink.core.compositions.report import Report, ReportOutput
# Use report_output passed to execute from Composition or command line;
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)
Expand Down
76 changes: 54 additions & 22 deletions psyneulink/core/compositions/composition.py
Expand Up @@ -882,18 +882,18 @@

.. _Composition_Execution_Reporting:

*Reporting*. Executing a Composition returns the results of its last `TRIAL <TimeScale.TRIAL>` of execution. If
either `run <Composition.run>` or `learn <Composition.learn>` is called, the results of all `TRIALS <TimeScale.TRIAL>`
executed are available in the Composition's `results <Composition.results>` attribute (see `Results
<Composition_Execution_Results>` for additional details). A report of the results of each
`TRIAL <TimeScale.TRIAL>` can also be generated as the Compostion is executing, using the **report_output** and
**report_progress** arguments of any of the execution methods. **report_output** generates a report of the input and
output the Composition and its `Nodes <Composition_Nodes>`, while **report_progress** shows a progress bar indicating
how many `TRIALS <TimeScale.TRIAL>` have been executed and an estimate of the time remaining to completion (see the
`execute <Composition.execute>`, `run <Composition.run>` and `learn <Composition.learn>` methods for additional
details). These options are both False by default. The values of individual Components (and their `parameters
<Parameters>`) assigned during execution can also be recorded in their `log <Component_Log>` attribute using the
`Log` facility.
*Results, Reporting and Logging*. Executing a Composition returns the results of its last `TRIAL <TimeScale.TRIAL>` of
execution. If either `run <Composition.run>` or `learn <Composition.learn>` is called, the results of all `TRIALS
<TimeScale.TRIAL>` executed are available in the Composition's `results <Composition.results>` attribute (see `Results
<Composition_Execution_Results>` for additional details). A report of the results of each `TRIAL <TimeScale.TRIAL>`
can also be generated as the Compostion is executing, using the **report_output** and **report_progress** arguments
of any of the execution methods. **report_output** (specified using `ReportOutput` options) generates a report of the
input and output of the Composition and its `Nodes <Composition_Nodes>`, and optionally their `Parameters` (specified
in the **report_params** arg using `ReportParams` options); **report_progress** (specified using `ReportProgress`
options) shows a progress bar indicating how many `TRIALS <TimeScale.TRIAL>` have been executed and an estimate of
the time remaining to completion. These options are all OFF by default (see `Report` for additional details).
The values of individual Components (and their `parameters <Parameters>`) assigned during execution can also be
recorded in their `log <Component_Log>` attribute using the `Log` facility.

*Inputs*. All methods of executing a Composition require specification of an **inputs** argument, which designates
the values assigned to the `INPUT` `Nodes <Composition_Nodes>` of the Composition for each `TRIAL <TimeScale.TRIAL>`.
Expand Down Expand Up @@ -2394,7 +2394,8 @@ def input_function(env, result):
from psyneulink.core.components.projections.projection import ProjectionError, DuplicateProjectionError
from psyneulink.core.components.shellclasses import Composition_Base
from psyneulink.core.components.shellclasses import Mechanism, Projection
from psyneulink.core.compositions.report import Report, ReportOutput, ReportProgress, ReportSimulations, ReportDevices
from psyneulink.core.compositions.report import Report,\
ReportOutput, ReportParams, ReportProgress, ReportSimulations, ReportDevices
from psyneulink.core.compositions.showgraph import ShowGraph, INITIAL_FRAME, SHOW_CIM, EXECUTION_SET, SHOW_CONTROLLER
from psyneulink.core.globals.context import Context, ContextFlags, handle_external_context
from psyneulink.core.globals.keywords import \
Expand Down Expand Up @@ -7457,6 +7458,7 @@ def evaluate(
execution_mode=execution_mode,
skip_initialization=True,
report_output=report._report_output,
report_params=report._report_params,
report_progress=report._report_progress,
report_simulations=report._report_simulations,
report_to_devices=report._report_to_devices
Expand Down Expand Up @@ -8023,6 +8025,7 @@ def run(
termination_processing=None,
skip_analyze_graph=False,
report_output:ReportOutput=ReportOutput.OFF,
report_params:ReportParams=ReportParams.OFF,
report_progress=ReportProgress.OFF,
report_simulations=ReportSimulations.OFF,
report_to_devices=None,
Expand Down Expand Up @@ -8127,6 +8130,10 @@ def run(
specifies whether to show output of the Composition and its `Nodes <Composition_Nodes>` trial-by-trial as
it is generated; see `Report_Output` for additional details and `ReportOutput` for options.

report_params : ReportParams : default ReportParams.OFF
specifies whether to show values the `Parameters` of the Composition and its `Nodes <Composition_Nodes>`
as part of the output report; see `Report_Output` for additional details and `ReportParams` for options.

report_progress : ReportProgress : default ReportProgress.OFF
specifies whether to report progress of execution in real time; see `Report_Progress` for additional
details.
Expand Down Expand Up @@ -8418,6 +8425,7 @@ def run(

with Report(self,
report_output=report_output,
report_params=report_params,
report_progress=report_progress,
report_simulations=report_simulations,
report_to_devices=report_to_devices,
Expand Down Expand Up @@ -8461,6 +8469,7 @@ def run(
skip_initialization=True,
execution_mode=execution_mode,
report_output=report_output,
report_params=report_params,
report_progress=report_progress,
report_simulations=report_simulations,
report=report,
Expand Down Expand Up @@ -8632,17 +8641,21 @@ def learn(
called after each minibatch is executed

report_output : ReportOutput : default ReportOutput.OFF
specifies whether to show output of the Composition and its `Nodes <Composition_Nodes>` trial-by-trial as
it is generated; see `Report_Output` for additional details and `ReportOutput` for options.
specifies whether to show output of the Composition and its `Nodes <Composition_Nodes>` trial-by-trial
as it is generated; see `Report_Output` for additional details and `ReportOutput` for options.

report_params : ReportParams : default ReportParams.OFF
specifies whether to show values the `Parameters` of the Composition and its `Nodes <Composition_Nodes>`
as part of the output report; see `Report_Output` for additional details and `ReportParams` for options.

report_progress : ReportProgress : default ReportProgress.OFF
specifies whether to report progress of execution in real time; see `Report_Progress` for additional
details.

report_simulations : ReportSimulatons : default ReportSimulations.OFF
specifies whether to show output and/or progress for `simulations <OptimizationControlMechanism_Execution>`
executed by the Composition's `controller <Composition_Controller>`; see `Report_Simulations` for
additional details.
specifies whether to show output and/or progress for `simulations
<OptimizationControlMechanism_Execution>` executed by the Composition's `controller
<Composition_Controller>`; see `Report_Simulations` for additional details.

report_to_devices : list(ReportDevices) : default ReportDevices.CONSOLE
specifies where output and progress should be reported; see `Report_To_Devices` for additional
Expand Down Expand Up @@ -8757,6 +8770,7 @@ def execute(
skip_initialization=False,
execution_mode:pnlvm.ExecutionMode = pnlvm.ExecutionMode.Python,
report_output:ReportOutput=ReportOutput.OFF,
report_params:ReportOutput=ReportParams.OFF,
report_progress:ReportProgress=ReportProgress.OFF,
report_simulations:ReportSimulations=ReportSimulations.OFF,
report_to_devices:ReportDevices=None,
Expand Down Expand Up @@ -8826,6 +8840,10 @@ def execute(
specifies whether to show output of the Composition and its `Nodes <Composition_Nodes>` for the
execution; see `Report_Output` for additional details and `ReportOutput` for options.

report_params : ReportParams : default ReportParams.OFF
specifies whether to show values the `Parameters` of the Composition and its `Nodes <Composition_Nodes>`
for the execution; see `Report_Output` for additional details and `ReportParams` for options.

report_progress : ReportProgress : default ReportProgress.OFF
specifies whether to report progress of the execution; see `Report_Progress` for additional details.

Expand All @@ -8846,6 +8864,7 @@ def execute(

with Report(self,
report_output=report_output,
report_params=report_params,
report_progress=report_progress,
report_simulations=report_simulations,
report_to_devices=report_to_devices,
Expand Down Expand Up @@ -9147,7 +9166,14 @@ def execute(
execution_sets.__next__()

# Add TRIAL header and Composition's input to output report (now that they are known)
report.report_output(self, run_report, execution_scheduler, report_output, 'trial_init', context)
report.report_output(caller=self,
report_num=run_report,
scheduler=execution_scheduler,
report_output=report_output,
report_params=report_params,
content='trial_init',
context=context
)

for next_execution_set in execution_sets:

Expand Down Expand Up @@ -9222,6 +9248,7 @@ def execute(
report.report_output(self, run_report,
execution_scheduler,
report_output,
report_params,
'time_step_init',
context,
nodes_to_report=True)
Expand Down Expand Up @@ -9293,6 +9320,7 @@ def execute(
port._update(context=context)
node.execute(context=mech_context,
report_output=report_output,
report_params=report_params,
run_report=run_report,
runtime_params=execution_runtime_params,
)
Expand Down Expand Up @@ -9360,6 +9388,7 @@ def execute(
pnlvm.ExecutionMode.Python
ret = node.execute(context=context,
report_output=report_output,
report_params=report_params,
report_progress=report_progress,
execution_mode=nested_execution_mode)

Expand All @@ -9380,6 +9409,7 @@ def execute(
run_report,
execution_scheduler,
report_output,
report_params,
'node',
context,
node=node)
Expand Down Expand Up @@ -9428,8 +9458,9 @@ def execute(


# Complete TIME_STEP entry for output report
report.report_output(self, run_report, execution_scheduler, report_output, 'time_step', context,
nodes_to_report= nodes_to_report)
report.report_output(self, run_report, execution_scheduler,
report_output, report_params, 'time_step', context,
nodes_to_report= nodes_to_report)

context.remove_flag(ContextFlags.PROCESSING)

Expand Down Expand Up @@ -9497,7 +9528,8 @@ def execute(
output_values.append(port.parameters.value._get(context))

# Complete TRIAL entry for output report, and report progress
report.report_output(self, run_report, execution_scheduler, report_output, 'trial', context)
report.report_output(self, run_report, execution_scheduler, report_output,
report_params, 'trial', context)
report.report_progress(self, run_report, context)

# UPDATE TIME and RETURN ***********************************************************************************
Expand Down

0 comments on commit 97af221

Please sign in to comment.