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 #2352

Merged
merged 361 commits into from
Mar 21, 2022

Conversation

jdcpni
Copy link
Collaborator

@jdcpni jdcpni commented Mar 21, 2022

• optimizationcontrolmechanism.py:

  • _state_feature_values_getter(): for numeric state_feature, return state_input_port.function(numeric_value)

• test_control.py:

  • test_state_features_in_nested_composition_as_agent_rep():
  • add tests for single state_feature specs
  • add tests for INPUT Node with more than on InputPort

jdcpni and others added 30 commits November 25, 2021 09:47
  - 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_controller and _get_nested_node_CIM_port:
   added support for forced assignment of NodeRole.OUTPUT for nodes specified in OCM.monitor_for_control,
   but referenced 'allow_probes' attribute still needs to be implemented
  - _update_shadow_projections(): fix handling of deep nesting
  - state_feature_function -> state_feature_functions
  - _validate_params:  validate state_feature_functions
  - _update_state_input_ports_for_controller: implement assignment of state_feature_functions
…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)
…Link into refactor/ocm/state_features_all_as_input_ports
  - _state_feature_values_getter(): for numeric state_feature, return state_input_port.functio(numeric_value)
  - test_ocm_state_feature_specs_and_warnings_and_errors() - added tests for single state_feature spec
  - test_state_features_in_nested_composition_as_agent_rep():
    - add tests for single state_feature specs
    - add tests for INPUT Node with more than on InputPort
@github-actions
Copy link

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

diff -r docs-base/ComparatorMechanism.html docs-head/ComparatorMechanism.html
374,376c374,376
< <dd><p>used to compare the <a class="reference internal" href="#psyneulink.library.components.mechanisms.processing.objective.comparatormechanism.ComparatorMechanism.sample" title="psyneulink.library.components.mechanisms.processing.objective.comparatormechanism.ComparatorMechanism.sample"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">sample</span></code></a> with the <a class="reference internal" href="#psyneulink.library.components.mechanisms.processing.objective.comparatormechanism.ComparatorMechanism.target" title="psyneulink.library.components.mechanisms.processing.objective.comparatormechanism.ComparatorMechanism.target"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">target</span></code></a>.  It can be any PsyNeuLink <code class="xref any docutils literal notranslate"><span class="pre">CombinationFunction</span></code>,
< or a python function that takes a 2d array with two items and returns a 1d array of the same length
< as the two input items.</p>
---
> <dd><p>used to compare the <a class="reference internal" href="#psyneulink.library.components.mechanisms.processing.objective.comparatormechanism.ComparatorMechanism.sample" title="psyneulink.library.components.mechanisms.processing.objective.comparatormechanism.ComparatorMechanism.sample"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">sample</span></code></a> with the <a class="reference internal" href="#psyneulink.library.components.mechanisms.processing.objective.comparatormechanism.ComparatorMechanism.target" title="psyneulink.library.components.mechanisms.processing.objective.comparatormechanism.ComparatorMechanism.target"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">target</span></code></a>.  It can be any <a class="reference internal" href="CombinationFunctions.html"><span class="doc">CombinationFunction</span></a>,
> or a python function that takes a 2d array with two items and returns a 1d array of the same length as the
> two input items.</p>
diff -r docs-base/Composition.html docs-head/Composition.html
606,607c606,607
< outer Composition, are assigned <a class="reference internal" href="#id26" title="psyneulink.core.compositions.composition.NodeRole.PROBE"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">PROBE</span></code></a> in addition to their other <a class="reference internal" href="#psyneulink.core.compositions.composition.NodeRole" title="psyneulink.core.compositions.composition.NodeRole"><code class="xref any py py-class docutils literal notranslate"><span class="pre">roles</span></code></a> in the
< nested Composition.  The only difference between <a class="reference internal" href="#id26" title="psyneulink.core.compositions.composition.NodeRole.PROBE"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">PROBE</span></code></a> and <a class="reference internal" href="#psyneulink.core.compositions.composition.NodeRole.OUTPUT" title="psyneulink.core.compositions.composition.NodeRole.OUTPUT"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">OUTPUT</span></code></a> Nodes
---
> outer Composition, are assigned <a class="reference internal" href="#id24" title="psyneulink.core.compositions.composition.NodeRole.PROBE"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">PROBE</span></code></a> in addition to their other <a class="reference internal" href="#psyneulink.core.compositions.composition.NodeRole" title="psyneulink.core.compositions.composition.NodeRole"><code class="xref any py py-class docutils literal notranslate"><span class="pre">roles</span></code></a> in the
> nested Composition.  The only difference between <a class="reference internal" href="#id24" title="psyneulink.core.compositions.composition.NodeRole.PROBE"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">PROBE</span></code></a> and <a class="reference internal" href="#psyneulink.core.compositions.composition.NodeRole.OUTPUT" title="psyneulink.core.compositions.composition.NodeRole.OUTPUT"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">OUTPUT</span></code></a> Nodes
611c611
< <a class="reference internal" href="#id26" title="psyneulink.core.compositions.composition.NodeRole.PROBE"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">PROBE</span></code></a> Nodes are <em>not</em> included in the <a class="reference internal" href="#id19" title="psyneulink.core.compositions.composition.Composition.output_values"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">output_values</span></code></a> or <a class="reference internal" href="#psyneulink.core.compositions.composition.Composition.results" title="psyneulink.core.compositions.composition.Composition.results"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">results</span></code></a> for the outermost Composition to which they project (although they <em>are</em> still included
---
> <a class="reference internal" href="#id24" title="psyneulink.core.compositions.composition.NodeRole.PROBE"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">PROBE</span></code></a> Nodes are <em>not</em> included in the <a class="reference internal" href="#id19" title="psyneulink.core.compositions.composition.Composition.output_values"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">output_values</span></code></a> or <a class="reference internal" href="#psyneulink.core.compositions.composition.Composition.results" title="psyneulink.core.compositions.composition.Composition.results"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">results</span></code></a> for the outermost Composition to which they project (although they <em>are</em> still included
615c615
< <a class="reference internal" href="#psyneulink.core.compositions.composition.Composition.include_probes_in_output" title="psyneulink.core.compositions.composition.Composition.include_probes_in_output"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">include_probes_in_output</span></code></a> is True, then any <a class="reference internal" href="#id26" title="psyneulink.core.compositions.composition.NodeRole.PROBE"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">PROBE</span></code></a> Nodes
---
> <a class="reference internal" href="#psyneulink.core.compositions.composition.Composition.include_probes_in_output" title="psyneulink.core.compositions.composition.Composition.include_probes_in_output"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">include_probes_in_output</span></code></a> is True, then any <a class="reference internal" href="#id24" title="psyneulink.core.compositions.composition.NodeRole.PROBE"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">PROBE</span></code></a> Nodes
618c618
< <a class="reference internal" href="#id26" title="psyneulink.core.compositions.composition.NodeRole.PROBE"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">PROBE</span></code></a> Nodes can be visualized, along with any Projections treated differently from those of
---
> <a class="reference internal" href="#id24" title="psyneulink.core.compositions.composition.NodeRole.PROBE"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">PROBE</span></code></a> Nodes can be visualized, along with any Projections treated differently from those of
626c626
< <div><p><a class="reference internal" href="#id26" title="psyneulink.core.compositions.composition.NodeRole.PROBE"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">PROBE</span></code></a> Nodes are useful for <a class="reference internal" href="OptimizationControlMechanism.html#optimizationcontrolmechanism-model-based"><span class="std std-ref">model-based optimization using an</span></a>, in which the value of one or more Nodes in a nested Composition
---
> <div><p><a class="reference internal" href="#id24" title="psyneulink.core.compositions.composition.NodeRole.PROBE"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">PROBE</span></code></a> Nodes are useful for <a class="reference internal" href="OptimizationControlMechanism.html#optimizationcontrolmechanism-model-based"><span class="std std-ref">model-based optimization using an</span></a>, in which the value of one or more Nodes in a nested Composition
650c650,651
< include the InputPorts of the nested Composition.  These can be accessed using the Composition’s <a class="reference internal" href="#id20" title="psyneulink.core.compositions.composition.Composition.external_input_ports"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">exernal_input_ports</span></code></a> attribute.</p>
---
> include the InputPorts of the nested Composition.  These can be accessed using the Composition’s
> <a class="reference internal" href="#psyneulink.core.compositions.composition.Composition.external_input_ports_of_all_input_nodes" title="psyneulink.core.compositions.composition.Composition.external_input_ports_of_all_input_nodes"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">external_input_ports_of_all_input_nodes</span></code></a> attribute.</p>
696,697c697,698
< Composition.  If the Composition has an <a class="reference internal" href="#id26" title="psyneulink.core.compositions.composition.NodeRole.PROBE"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">PROBE</span></code></a> Nodes, then they too project to the Composition’s
< output_CIM.  If the Composition is nested in another, then the <a class="reference internal" href="Mechanism.html#psyneulink.core.components.mechanisms.mechanism.Mechanism_Base.value" title="psyneulink.core.components.mechanisms.mechanism.Mechanism_Base.value"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">values</span></code></a> of the <a class="reference internal" href="#id26" title="psyneulink.core.compositions.composition.NodeRole.PROBE"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">PROBE</span></code></a> Nodes are also included in the Composition’s <a class="reference internal" href="#id19" title="psyneulink.core.compositions.composition.Composition.output_values"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">output_values</span></code></a>;  if it
---
> Composition.  If the Composition has an <a class="reference internal" href="#id24" title="psyneulink.core.compositions.composition.NodeRole.PROBE"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">PROBE</span></code></a> Nodes, then they too project to the Composition’s
> output_CIM.  If the Composition is nested in another, then the <a class="reference internal" href="Mechanism.html#psyneulink.core.components.mechanisms.mechanism.Mechanism_Base.value" title="psyneulink.core.components.mechanisms.mechanism.Mechanism_Base.value"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">values</span></code></a> of the <a class="reference internal" href="#id24" title="psyneulink.core.compositions.composition.NodeRole.PROBE"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">PROBE</span></code></a> Nodes are also included in the Composition’s <a class="reference internal" href="#id19" title="psyneulink.core.compositions.composition.Composition.output_values"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">output_values</span></code></a>;  if it
744c745
< <a class="reference internal" href="#id26" title="psyneulink.core.compositions.composition.NodeRole.PROBE"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">PROBE</span></code></a> Nodes of a nested Composition, like <a class="reference internal" href="#psyneulink.core.compositions.composition.NodeRole.OUTPUT" title="psyneulink.core.compositions.composition.NodeRole.OUTPUT"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">OUTPUT</span></code></a> Nodes,
---
> <a class="reference internal" href="#id24" title="psyneulink.core.compositions.composition.NodeRole.PROBE"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">PROBE</span></code></a> Nodes of a nested Composition, like <a class="reference internal" href="#psyneulink.core.compositions.composition.NodeRole.OUTPUT" title="psyneulink.core.compositions.composition.NodeRole.OUTPUT"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">OUTPUT</span></code></a> Nodes,
746c747
< The outputs of <a class="reference internal" href="#id26" title="psyneulink.core.compositions.composition.NodeRole.PROBE"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">PROBE</span></code></a> Nodes are included in the <a class="reference internal" href="#id19" title="psyneulink.core.compositions.composition.Composition.output_values"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">output_values</span></code></a> and
---
> The outputs of <a class="reference internal" href="#id24" title="psyneulink.core.compositions.composition.NodeRole.PROBE"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">PROBE</span></code></a> Nodes are included in the <a class="reference internal" href="#id19" title="psyneulink.core.compositions.composition.Composition.output_values"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">output_values</span></code></a> and
949c950
< <li><p><em>OUTPUT_MECHANISM</em> – the final <code class="xref any docutils literal notranslate"><span class="pre">Node</span></code> in the learning Pathway, the target <a class="reference internal" href="Mechanism.html#psyneulink.core.components.mechanisms.mechanism.Mechanism_Base.value" title="psyneulink.core.components.mechanisms.mechanism.Mechanism_Base.value"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">value</span></code></a> for which is specified as input to the <code class="xref any docutils literal notranslate"><span class="pre">TARGET_MECHANISM</span></code>; the Node is assigned
---
> <li><p><em>OUTPUT_MECHANISM</em> – the final <a class="reference internal" href="#composition-nodes"><span class="std std-ref">Node</span></a> in the learning Pathway, the target <a class="reference internal" href="Mechanism.html#psyneulink.core.components.mechanisms.mechanism.Mechanism_Base.value" title="psyneulink.core.components.mechanisms.mechanism.Mechanism_Base.value"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">value</span></code></a> for which is specified as input to the <code class="xref any docutils literal notranslate"><span class="pre">TARGET_MECHANISM</span></code>; the Node is assigned
966c967
< <figure class="align-default" id="id27">
---
> <figure class="align-default" id="id25">
972c973
< and in italics, above each Mechanism).</span><a class="headerlink" href="#id27" title="Permalink to this image">¶</a></p>
---
> and in italics, above each Mechanism).</span><a class="headerlink" href="#id25" title="Permalink to this image">¶</a></p>
999c1000
< <figure class="align-default" id="id28">
---
> <figure class="align-default" id="id26">
1007c1008
< one that projects to the ComparatorMechanism and assigned as the <a class="reference internal" href="#psyneulink.core.compositions.composition.NodeRole.OUTPUT" title="psyneulink.core.compositions.composition.NodeRole.OUTPUT"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">OUTPUT</span></code></a> Node.</span><a class="headerlink" href="#id28" title="Permalink to this image">¶</a></p>
---
> one that projects
...

See CI logs for the full diff.

@lgtm-com
Copy link
Contributor

lgtm-com bot commented Mar 21, 2022

This pull request introduces 1 alert when merging 42c3fca into 8fa3011 - view on LGTM.com

new alerts:

  • 1 for Comparison using is when operands support `__eq__`

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.003%) to 84.091% when pulling 42c3fca on refactor/ocm/state_features_all_as_input_ports into 8fa3011 on devel.

@jdcpni jdcpni merged commit b582287 into devel Mar 21, 2022
@jdcpni jdcpni deleted the refactor/ocm/state_features_all_as_input_ports branch March 21, 2022 16:18
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