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

Merged
merged 320 commits into from
Mar 17, 2022

Conversation

jdcpni
Copy link
Collaborator

@jdcpni jdcpni commented Mar 16, 2022

• doc_requirements.txt:
pin sphinx_autodoc_typehints < v.1.16.0; error on v1.16 and v1.17; error:
https://github.com/PrincetonUniversity/PsyNeuLink/runs/5573651890?check_suite_focus=true

• composition.py:

  • _instantiate_input_dict(): refactor to accept inputs for InputPorts of nested Nodes
  • remove _build_predicted_inputs_dict() (since state_feature_values is now formatted properly as input)
  • add helper method _get_external_cim_input_port()
  • add helper method _get_input_receivers()
  • _parse_names_in_inputs(): support Port.full_name as keys in inputs dict

• mechanism.py:

  • Mechanism_Base: replaced input_labels and output_labels with labeled_input_values and labeled_output_values respectively

• port.py, inputport.py, outputport.py, parameterport.py:

  • Port_Base: impelment labeled_value property (and value_label alias) that returns calls get_label()
  • deleted label attributes of InputPort and OutputPort (replaced by Port_Base.labeled_value)
  • added get_label() stub on ParameterPort with error message

• optimizationcontrolmechanism:
- support specification of INPUT Nodes and/or their InputPorts
in nested Composition of agent_rep in set and dict formats
- refactor state_feature_values as dict used as predicted_inputs / feature_values arg of evaluate()
- _get_agent_rep_input_nodes()
- rename as _get_agent_rep_input_receivers(), call composition._get_input_receivers()
- default behavior is now to return list of INPUT Node InputPorts rather than INPUT Nodes themselves

jdcpni and others added 30 commits November 19, 2021 18:02
  - _instantiate_monitor_for_control_input_ports -> _parse_monitor_control_input_ports
  - refactored to support allow_probes option on ocm
  __init__: move controller to after add_nodes and add_linear_pathway
  _instantiate_control_projections:
     weird requirement for double-call to controller._instantiate_control_signal
  restored parameter spec that causes crash ('threshold',Decision2)
…trol specs

- composition.py
  - _get_control_signals_for_composition:  (see 11/20/21)
      - added (but commented out change) to "if node.controller" to "if not node.controller"
      - changed append to extend
  - _instantiation_control_projection:
      - got rid of try and except double-call to controller._instantiate_control_signals
      -  outdented call to self.controller._activate_projections_for_composition at end

- controlmechanism.py:
    - _check_for_duplicates:  add warning and return duplicates

- optimizationcontrolmechanism._instantiate_control_signals:
    - add call to self.agent_rep._get_control_signals_for_composition() to get local control specs (on mechs in comp)
    - eliminate duplicates with control_signal specs on OCM
    - instantiate local + ocm control_signals

- parameterestimationcomposition.py
  - added context to various calls
   - test_parameterestimationcomposition
   - test_composition/test_partially_overlapping_control_specs (ADDED IN THIS COMMINT)

- All relevant changes to this branch are marked as "11/21/21."
  However, most are commented out as they break other things.

- The tests above both involve local control specifications (on mechanism within a nested comp)
  and on the OCM for the outer composition, some of which are for the same nested mechs

- Both tests fail with:
   "AttributeError: 'NoneType' object has no attribute '_get_by_time_scale'" (in component.py LINE 3276)
   This may be due to a problem with context setting, since the error is because the modulation Parameter
   of the ControlProjection is returning "None" rather than "multiplicative_param" (when called with get(context)),
   whereas "multiplicative_param" is returned with a call to get() (i.e., with no context specified)

- Most of test_partially_overlapping_control_specs is passed if
   changes marked "11/21/21 NEW" in optimizationcontrolmechanism.py (LINE 1390) are implemented,
   but it does not properly route ControlProjections through parameter_CIMS (see last assert in test).
   Furthermore, test_parameterestimationcompsition fails with the mod param error, even though the
   model has similar structure (i.e., outer composition -- in this case a ParameterEstimationComposition)
   with an OCM that is given control specs that overlap with ones in a nested composition.

- There are also several other things in composition I found puzzling and tried modifying, but that cuased failures:
  - _get_control_signals_for_composition():
      - seems "if node.controller" should be "if **not** node.controller" (emphasis added just for comment)
      - "append" should be "extend"
  - _instantiate_control_projection():
      -  call to self.controller._activate_projections_for_composition (at end of method) should not be indented
  - rename _check_projection_initialization_status -> _check_controller_initialization_status
  - add _check_nodes_initialization_status(context=context)
    (and calls it with _check_controller_initialization_status)
@lgtm-com
Copy link
Contributor

lgtm-com bot commented Mar 16, 2022

This pull request introduces 2 alerts and fixes 2 when merging a382d47 into 2cd6de2 - view on LGTM.com

new alerts:

  • 1 for Unused local variable
  • 1 for Unused import

fixed alerts:

  • 2 for Unused local variable

jdcpni and others added 11 commits March 16, 2022 09:12
  - _parse_names_in_inputs(): support Port.full_name as keys in inputs dict

• mechanism.py:
  - Mechanism_Base: replaced input_labels and output_labels with labeled_input_values and labeled_output_values respectively

• port.py, inputport.py, outputport.py, parameterport.py:
  - Port_Base: impelment labeled_value property (and value_label alias) that returns calls get_label()
  - deleted label attributes of InputPort and OutputPort (replaced by Port_Base.labeled_value)
  - added get_label() stub on ParameterPort with error message
  comment out 'sphinx_autodoc_typehints' (crashing for sphinx_autodoc_typehints v.1.17.0)
  restore 'sphinx_autodoc_typehints'

• doc_requirements.txt:
  pin sphinx_autodoc_typehints < v.1.16.0;  error on v1.16 and v1.17;  error:
  https://github.com/PrincetonUniversity/PsyNeuLink/runs/5573651890?check_suite_focus=true
@lgtm-com
Copy link
Contributor

lgtm-com bot commented Mar 16, 2022

This pull request introduces 1 alert and fixes 5 when merging 16f66cb into 0210bfe - view on LGTM.com

new alerts:

  • 1 for Unused local variable

fixed alerts:

  • 3 for Unused import
  • 2 for Unused local variable

@github-actions
Copy link

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

diff -r docs-base/AutodiffComposition.html docs-head/AutodiffComposition.html
444,445c444,445
< default variable. If <strong>inputs</strong> is not specified, the <a class="reference internal" href="Component.html#component-variable"><span class="std std-ref">default_variable</span></a> for
< 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> Node is used as its input (see <a class="reference internal" href="Composition.html#composition-execution-inputs"><span class="std std-ref">Input Formats</span></a> for
---
> default variable. If <strong>inputs</strong> is not specified, the <a class="reference internal" href="Component.html#component-variable"><span class="std std-ref">default_variable</span></a>
> for 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> Node is used as its input (see <a class="reference internal" href="Composition.html#composition-execution-inputs"><span class="std std-ref">Input Formats</span></a> for
diff -r docs-base/Component.html docs-head/Component.html
562c562,563
< <li><p><strong>default_variable</strong> (<em>scalar</em><em>, </em><em>list</em><em> or </em><em>array : default</em><em> [</em><em>[</em><em>0</em><em>]</em><em>]</em>) – specifies template for the input to the Component’s <a class="reference internal" href="#psyneulink.core.components.component.Component.function" title="psyneulink.core.components.component.Component.function"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">function</span></code></a>.</p></li>
---
> <li><p><strong>default_variable</strong> (<em>scalar</em><em>, </em><em>list</em><em> or </em><em>array : default</em><em> [</em><em>[</em><em>0</em><em>]</em><em>]</em>) – specifies template for the input to the Component’s <a class="reference internal" href="#psyneulink.core.components.component.Component.function" title="psyneulink.core.components.component.Component.function"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">function</span></code></a>, and the value used as the
> input to the Component if none is provided on execution (see <code class="xref any docutils literal notranslate"><span class="pre">Component_Variable</span></code> for additional information).</p></li>
diff -r docs-base/Composition.html docs-head/Composition.html
606,607c606,607
< outer Composition, are assigned <a class="reference internal" href="#id22" 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="#id22" 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="#id22" 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="#id0" 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="#id0" 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="#id22" 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="#id22" 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="#id22" 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
696,697c696,697
< Composition.  If the Composition has an <a class="reference internal" href="#id22" 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="#id22" 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="#id0" 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="#id0" 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
744c744
< <a class="reference internal" href="#id22" 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,
746c746
< The outputs of <a class="reference internal" href="#id22" 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="#id0" 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="#id0" 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
966c966
< <figure class="align-default" id="id23">
---
> <figure class="align-default" id="id25">
972c972
< and in italics, above each Mechanism).</span><a class="headerlink" href="#id23" 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>
999c999
< <figure class="align-default" id="id24">
---
> <figure class="align-default" id="id26">
1007c1007
< 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="#id24" title="Permalink to this image">¶</a></p>
---
> 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="#id26" title="Permalink to this image">¶</a></p>
1025c1025
< <figure class="align-default" id="id25">
---
> <figure class="align-default" id="id27">
1029c1029
< method with the argument <code class="docutils literal notranslate"><span class="pre">animate={'show_learning':True}</span></code>.</span><a class="headerlink" href="#id25" title="Permalink to this image">¶</a></p>
---
> method with the argument <code class="docutils literal notranslate"><span class="pre">animate={'show_learning':True}</span></code>.</span><a class="headerlink" href="#id27" title="Permalink to this image">¶</a></p>
1144,1145c1144,1146
< <p>All <code class="xref any docutils literal notranslate"><span class="pre">methods</span> <span class="pre">of</span> <span class="pre">executing</span></code> method), which designates the values assigned
< to the <a class="reference internal" href="#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="#psyneulink.core.compositions.composition.NodeRole.TARGET" title="psyneulink.core.compositions.composition.NodeRole.TARGET"><code class="xref any
...

See CI logs for the full diff.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.04%) to 84.061% when pulling f9ed505 on refactor/ocm/state_features_all_as_input_ports into 0210bfe on devel.

@jdcpni jdcpni merged commit ef07e57 into devel Mar 17, 2022
@jdcpni jdcpni deleted the refactor/ocm/state_features_all_as_input_ports branch March 17, 2022 02:29
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.

None yet

3 participants