Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/ocm/state features all as input ports #2351

Merged
merged 348 commits into from
Mar 20, 2022

Conversation

jdcpni
Copy link
Collaborator

@jdcpni jdcpni commented Mar 19, 2022

• processingmechanism.py:

  • init(): modify typecheck for input_ports to allow single items

• optimizationcontrolmechanism.py

  • state_features: allow single spec (None, array, tuple, or Components)
    that is assigned to all INPUT Node InputPorts on agent_rep at time of OCM construction
  • state_feature_default is assigned to all unspecified INPUT Node InputPorts
    (i.e., for those not specified in a list, set or dict that has fewer entries
    than the number of INPUT Nodes on agent_rep when OCM is initially constructed or
    or any that are added to agent_rep afterwards)
  • update docstring for new features

kmantel and others added 30 commits November 22, 2021 23:05
  retore append of control_signals in _instantiate_control_projections()
  restore append of control_signals in _instantiate_control_projections()

• test_composition.py:
  add test_partially_overlapping_local_and_control_mech_control_specs_in_unnested_and_nested_comp
…unnested_and_nested_comp():

  - added clear_registry() to allow names to be reused in both runs of test
  docstring:  added projections entry to list of attributes
  - add_controller:  added call to _add_node_aux_components() for controller
  _add_node_aux_components(): added deletion of item from aux_components if instantiated
  - comment out _add_node_aux_components() (causing new failures)
  - move _instantiate_control_projections to be with _instantiate_control_projections,
       after self.add_node(self.controller.objective_mechanism (to be more orderly)
…rtially_overlapping...

  (with addition of _add_aux_components in add_controller commented out)
…y one test:

    - test_agent_rep_assignement_as_controller_and_replacement
  - add_controller:  few more minor mods;
  still passes all tests
  - __init__: resrict specification to only one of control, modulatory_signals, or control_signals (synonyms)
  - _get_original_senders():  added support for nested composition
    needs to be checked for more than one level
    needs to be refactored to be recursive
  - _update_state_input_ports_for_controller:  fix invalid_state_features to allow input_CIM of nested comp in agent_rep
 - _get_original_senders: made recursive
  - add figure for shadowing
…Link into refactor/ocm/state_features_all_as_input_ports

� Conflicts:
�	psyneulink/core/components/mechanisms/modulatory/control/optimizationcontrolmechanism.py
�	psyneulink/core/components/ports/parameterport.py
�	psyneulink/core/compositions/composition.py
  - __init__(): modify typecheck for input_ports to allow single items
…Link into refactor/ocm/state_features_all_as_input_ports

� Conflicts:
�	psyneulink/core/components/ports/inputport.py
…Link into refactor/ocm/state_features_all_as_input_ports
  - allow single spec (None, array, tuple, or Components) that is assigned to all INPUT Node InputPorts
  - state_feature_default is assigned to all unspecified INPUT Node InputPorts
    (for a list that is shorter than the number, a dict or a set that has fewer,
     or any that are added to agent_rep after controller is initially constructed and added to Composition)
@github-actions
Copy link

This PR causes the following changes to the html docs (ubuntu-latest-3.7-x64):

diff -r docs-base/InputPort.html docs-head/InputPort.html
498c498
< <span class="gp">&gt;&gt;&gt; </span><span class="n">C</span> <span class="o">=</span> <span class="n">ProcessingMechanism</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;Shadowing Mech&#39;</span><span class="p">,</span> <span class="n">input_ports</span><span class="o">=</span><span class="p">[</span><span class="n">B</span><span class="o">.</span><span class="n">input_port</span><span class="p">])</span>
---
> <span class="gp">&gt;&gt;&gt; </span><span class="n">C</span> <span class="o">=</span> <span class="n">ProcessingMechanism</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;Shadowing Mech&#39;</span><span class="p">,</span> <span class="n">input_ports</span><span class="o">=</span><span class="n">B</span><span class="o">.</span><span class="n">input_port</span><span class="p">)</span>
518c518
< <span class="gp">... </span>                                     <span class="n">input_ports</span><span class="o">=</span><span class="p">[</span><span class="n">mech</span><span class="o">.</span><span class="n">input_port</span><span class="p">])</span>
---
> <span class="gp">... </span>                                     <span class="n">input_ports</span><span class="o">=</span><span class="n">mech</span><span class="o">.</span><span class="n">input_port</span><span class="p">)</span>
diff -r docs-base/OptimizationControlMechanism.html docs-head/OptimizationControlMechanism.html
310c310
< its <a class="reference internal" href="ControlMechanism.html#psyneulink.core.components.mechanisms.modulatory.control.controlmechanism.ControlMechanism.net_outcome" title="psyneulink.core.components.mechanisms.modulatory.control.controlmechanism.ControlMechanism.net_outcome"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">net_outcome</span></code></a>.  A OptimizationControlMechanism can be configured to implement
---
> its <a class="reference internal" href="ControlMechanism.html#psyneulink.core.components.mechanisms.modulatory.control.controlmechanism.ControlMechanism.net_outcome" title="psyneulink.core.components.mechanisms.modulatory.control.controlmechanism.ControlMechanism.net_outcome"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">net_outcome</span></code></a>.  An OptimizationControlMechanism can be configured to implement
414,423c414,423
< <li><p><strong>state_features</strong> – specifies the values provided by the OptimizationControlMechanism as the input to its
< <a class="reference internal" href="#psyneulink.core.components.mechanisms.modulatory.control.optimizationcontrolmechanism.OptimizationControlMechanism.agent_rep" title="psyneulink.core.components.mechanisms.modulatory.control.optimizationcontrolmechanism.OptimizationControlMechanism.agent_rep"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">agent_rep</span></code></a>'s <a class="reference internal" href="Composition.html#psyneulink.core.compositions.composition.Composition.evaluate" title="psyneulink.core.compositions.composition.Composition.evaluate"><code class="xref any py py-meth docutils literal notranslate"><span class="pre">evaluate</span></code></a> method, together
< with a selected <a class="reference internal" href="ControlMechanism.html#psyneulink.core.components.mechanisms.modulatory.control.controlmechanism.ControlMechanism.control_allocation" title="psyneulink.core.components.mechanisms.modulatory.control.controlmechanism.ControlMechanism.control_allocation"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">control_allocation</span></code></a>, when that is called to estimate
< or predict the Composition’s <a class="reference internal" href="ControlMechanism.html#psyneulink.core.components.mechanisms.modulatory.control.controlmechanism.ControlMechanism.net_outcome" title="psyneulink.core.components.mechanisms.modulatory.control.controlmechanism.ControlMechanism.net_outcome"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">net_outcome</span></code></a>. These are used to construct the
< <a class="reference internal" href="#psyneulink.core.components.mechanisms.modulatory.control.optimizationcontrolmechanism.OptimizationControlMechanism.state_input_ports" title="psyneulink.core.components.mechanisms.modulatory.control.optimizationcontrolmechanism.OptimizationControlMechanism.state_input_ports"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">state_input_ports</span></code></a> for the OptimizationControlMechanism,
< the <a class="reference internal" href="InputPort.html#psyneulink.core.components.ports.inputport.InputPort.value" title="psyneulink.core.components.ports.inputport.InputPort.value"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">values</span></code></a> of which are assigned as the <a class="reference internal" href="#psyneulink.core.components.mechanisms.modulatory.control.optimizationcontrolmechanism.OptimizationControlMechanism.state_feature_values" title="psyneulink.core.components.mechanisms.modulatory.control.optimizationcontrolmechanism.OptimizationControlMechanism.state_feature_values"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">state_feature_values</span></code></a> and provided to the <strong>predicted_inputs</strong> argument of the
< <a class="reference internal" href="Composition.html#psyneulink.core.compositions.composition.Composition.evaluate" title="psyneulink.core.compositions.composition.Composition.evaluate"><code class="xref any py py-meth docutils literal notranslate"><span class="pre">evaluate</span></code></a> method if <a class="reference internal" href="#psyneulink.core.components.mechanisms.modulatory.control.optimizationcontrolmechanism.OptimizationControlMechanism.agent_rep" title="psyneulink.core.components.mechanisms.modulatory.control.optimizationcontrolmechanism.OptimizationControlMechanism.agent_rep"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">agent_rep</span></code></a> is a <a class="reference internal" href="Composition.html"><span class="doc">Composition</span></a>,
< or the <strong>feature_values</strong> argument if it is a <a class="reference internal" href="CompositionFunctionApproximator.html"><span class="doc">CompositionFunctionApproximator</span></a>.  Accordingly, the specification
< requirements for <strong>state_features</strong> depend on whether the <a class="reference internal" href="#psyneulink.core.components.mechanisms.modulatory.control.optimizationcontrolmechanism.OptimizationControlMechanism.agent_rep" title="psyneulink.core.components.mechanisms.modulatory.control.optimizationcontrolmechanism.OptimizationControlMechanism.agent_rep"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">agent_rep</span></code></a> is a
< <a class="reference internal" href="Composition.html"><span class="doc">Composition</span></a> or a <a class="reference internal" href="CompositionFunctionApproximator.html"><span class="doc">CompositionFunctionApproximator</span></a>, as described in each of the two sections below.</p>
---
> <li><p><strong>state_features</strong> – specifies the sources of input to the OptimizationControlMechanism’s <a class="reference internal" href="#psyneulink.core.components.mechanisms.modulatory.control.optimizationcontrolmechanism.OptimizationControlMechanism.agent_rep" title="psyneulink.core.components.mechanisms.modulatory.control.optimizationcontrolmechanism.OptimizationControlMechanism.agent_rep"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">agent_rep</span></code></a> which, together with a selected <a class="reference internal" href="ControlMechanism.html#psyneulink.core.components.mechanisms.modulatory.control.controlmechanism.ControlMechanism.control_allocation" title="psyneulink.core.components.mechanisms.modulatory.control.controlmechanism.ControlMechanism.control_allocation"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">control_allocation</span></code></a>, are provided as input to it’s <a class="reference internal" href="Composition.html#psyneulink.core.compositions.composition.Composition.evaluate" title="psyneulink.core.compositions.composition.Composition.evaluate"><code class="xref any py py-meth docutils literal notranslate"><span class="pre">evaluate</span></code></a> method
> when that is executed to estimate or predict the Composition’s <a class="reference internal" href="ControlMechanism.html#psyneulink.core.components.mechanisms.modulatory.control.controlmechanism.ControlMechanism.net_outcome" title="psyneulink.core.components.mechanisms.modulatory.control.controlmechanism.ControlMechanism.net_outcome"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">net_outcome</span></code></a>.
> Those sources of input are used to construct the OptimizationControlMechanism’s <a class="reference internal" href="#psyneulink.core.components.mechanisms.modulatory.control.optimizationcontrolmechanism.OptimizationControlMechanism.state_input_ports" title="psyneulink.core.components.mechanisms.modulatory.control.optimizationcontrolmechanism.OptimizationControlMechanism.state_input_ports"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">state_input_ports</span></code></a>, one for each external <a class="reference internal" href="InputPort.html"><span class="doc">InputPort</span></a> (i.e., that is not designated
> as <a class="reference internal" href="InputPort.html#psyneulink.core.components.ports.inputport.InputPort.internal_only" title="psyneulink.core.components.ports.inputport.InputPort.internal_only"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">internal_only</span></code></a>) of each <a class="reference internal" href="Composition.html#psyneulink.core.compositions.composition.NodeRole.INPUT" title="psyneulink.core.compositions.composition.NodeRole.INPUT"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">INPUT</span></code></a> <a class="reference internal" href="Composition.html#composition-nodes"><span class="std std-ref">Node</span></a> of the
> <a class="reference internal" href="#psyneulink.core.components.mechanisms.modulatory.control.optimizationcontrolmechanism.OptimizationControlMechanism.agent_rep" title="psyneulink.core.components.mechanisms.modulatory.control.optimizationcontrolmechanism.OptimizationControlMechanism.agent_rep"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">agent_rep</span></code></a>. The input to each <a class="reference internal" href="#psyneulink.core.components.mechanisms.modulatory.control.optimizationcontrolmechanism.OptimizationControlMechanism.state_input_ports" title="psyneulink.core.components.mechanisms.modulatory.control.optimizationcontrolmechanism.OptimizationControlMechanism.state_input_ports"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">state_input_port</span></code></a>, after being processed by it <a class="reference internal" href="InputPort.html#psyneulink.core.components.ports.inputport.InputPort.function" title="psyneulink.core.components.ports.inputport.InputPort.function"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">function</span></code></a>, is
> assigned as the corresponding value of <a class="reference internal" href="#psyneulink.core.components.mechanisms.modulatory.control.optimizationcontrolmechanism.OptimizationControlMechanism.state_feature_values" title="psyneulink.core.components.mechanisms.modulatory.control.optimizationcontrolmechanism.OptimizationControlMechanism.state_feature_values"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">state_feature_values</span></code></a>,
> the values of which provided as the input to the corresponding InputPorts of the <a class="reference internal" href="Composition.html#psyneulink.core.compositions.composition.NodeRole.INPUT" title="psyneulink.core.compositions.composition.NodeRole.INPUT"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">INPUT</span></code></a> <a class="reference internal" href="Composition.html#psyneulink.core.compositions.composition.Composition.evaluate" title="psyneulink.core.compositions.composition.Composition.evaluate"><code class="xref any py py-meth docutils literal notranslate"><span class="pre">Nodes</span>
> <span class="pre">of</span> <span class="pre">the</span> <span class="pre">agent_rep</span> <span class="pre">each</span> <span class="pre">time</span> <span class="pre">it</span> <span class="pre">is</span> <span class="pre">`evaluated</span></code></a>.  Accordingly, the specification requirements
> for <strong>state_features</strong> depend on whether the <a class="reference internal" href="#psyneulink.core.components.mechanisms.modulatory.control.optimizationcontrolmechanism.OptimizationControlMechanism.agent_rep" title="psyneulink.core.components.mechanisms.modulatory.control.optimizationcontrolmechanism.OptimizationControlMechanism.agent_rep"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">agent_rep</span></code></a> is a <a class="reference internal" href="Composition.html"><span class="doc">Composition</span></a>
> or a <a class="reference internal" href="CompositionFunctionApproximator.html"><span class="doc">CompositionFunctionApproximator</span></a>, as described in each of the two sections below.</p>
431,437c431,436
< <p id="optimizationcontrolmechanism-state-features-automatic-assignment"><em>Automatic assignment.</em> The <strong>state_features</strong> specify the inputs to the Composition assigned as the <a class="reference internal" href="#psyneulink.core.components.mechanisms.modulatory.control.optimizationcontrolmechanism.OptimizationControlMechanism.agent_rep" title="psyneulink.core.components.mechanisms.modulatory.control.optimizationcontrolmechanism.OptimizationControlMechanism.agent_rep"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">agent_rep</span></code></a> when it is executed by the OptimizationControlMechanism to
< <a class="reference internal" href="#optimizationcontrolmechanism-evaluation"><span class="std std-ref">evaluate</span></a> its performance.  The default is for the evaluation to use the
< same values received by the <a class="reference internal" href="#psyneulink.core.components.mechanisms.modulatory.control.optimizationcontrolmechanism.OptimizationControlMechanism.agent_rep" title="psyneulink.core.components.mechanisms.modulatory.control.optimizationcontrolmechanism.OptimizationControlMechanism.agent_rep"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">agent_rep</span></code></a> as its <a class="reference internal" href="Composition.html#composition-execution-inputs"><span class="std std-ref">external inputs</span></a> during its last <a class="reference internal" href="Time.html#psyneulink.core.scheduling.time.TimeScale.TRIAL" title="psyneulink.core.scheduling.time.TimeScale.TRIAL"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">TRIAL</span></code></a> of execution. Accordingly, if
< <strong>state_features</strong> is not specified, a set of <a class="reference internal" href="#psyneulink.core.components.mechanisms.modulatory.control.optimizationcontrolmechanism.OptimizationControlMechanism.state_input_ports" title="psyneulink.core.components.mechanisms.modulatory.control.optimizationcontrolmechanism.OptimizationControlMechanism.state_input_ports"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">state_input_ports</span></code></a>
< is constructed automatically that <a class="reference internal" href="InputPort.html#inputport-shadow-inputs"><span class="std std-ref">shadow the input</span></a> to every <a class="reference internal" href="InputPort.html"><span class="doc">InputPort</span></a> of ever
...

See CI logs for the full diff.

@lgtm-com
Copy link
Contributor

lgtm-com bot commented Mar 19, 2022

This pull request introduces 1 alert when merging c5a01e3 into 404030e - view on LGTM.com

new alerts:

  • 1 for Unused import

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.008%) to 84.091% when pulling c5a01e3 on refactor/ocm/state_features_all_as_input_ports into 404030e on devel.

@jdcpni jdcpni merged commit 8fa3011 into devel Mar 20, 2022
@jdcpni jdcpni deleted the refactor/ocm/state_features_all_as_input_ports branch March 20, 2022 00:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants