Skip to content

Commit

Permalink
Fix/input state specs (#518)
Browse files Browse the repository at this point in the history
* -

* Merge branch 'devel' of https://github.com/PrincetonUniversity/PsyNeuLink into CURRENT

# Conflicts:
#	tests/mechanisms/test_transfer_mechanism.py

* Merge branch 'devel' of https://github.com/PrincetonUniversity/PsyNeuLink into CURRENT

# Conflicts:
#	tests/mechanisms/test_transfer_mechanism.py

* • Mechanism, PathwayProjection
  - fixed bugs related to input_state specifications
  • Loading branch information
jdcpni authored Nov 9, 2017
1 parent 22ecfbc commit 84ce4fc
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 16 deletions.
34 changes: 27 additions & 7 deletions Scripts/Scratch Pad.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,13 +370,12 @@ def __init__(self, error_value):
# g = pnl.GatingMechanism(gating_signals=[{pnl.MECHANISM:m,
# pnl.NAME:pnl.DECISION_VARIABLE}])

my_mech = pnl.TransferMechanism(default_variable=[[0],[0]])

print(my_mech.input_states)

print(my_mech.parameter_states)
print(my_mech.output_states)

# my_mech = pnl.TransferMechanism(default_variable=[[0],[0]])
#
# print(my_mech.input_states)
#
# print(my_mech.parameter_states)
# print(my_mech.output_states)

# mech_A = pnl.TransferMechanism(input_states=['MY INPUT'])
# print(mech_A.input_states)
Expand Down Expand Up @@ -411,6 +410,27 @@ def __init__(self, error_value):
# for projection in my_mech.output_states[0].efferents:
# print(projection.name)

# FROM KEVIN: -------------------------------------

# WORKING:
# I = pnl.InputState(reference_value=[0,0,0])
# pnl.TransferMechanism(input_states=[I])

# p = pnl.MappingProjection()
# T = pnl.TransferMechanism(input_states=[{pnl.VARIABLE: [0, 0, 0], pnl.PROJECTIONS:[p]}])
#
# p = pnl.MappingProjection()
# T = pnl.TransferMechanism(default_variable=[0, 0], input_states=[p])

#-------------
# m = pnl.TransferMechanism()
# i = pnl.InputState(owner=m, reference_value=[0, 0, 0])

# m = pnl.TransferMechanism(default_variable=[0, 0, 0])
# i = pnl.InputState(owner=m, reference_value=[0, 0, 0])


# --------------------------------------------------------------------------------------------------

# My_Transfer_Mech_A = TransferMechanism(
# function=Logistic(
Expand Down
27 changes: 21 additions & 6 deletions psyneulink/components/mechanisms/mechanism.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,12 +707,18 @@ class `UserList <https://docs.python.org/3.6/library/collections.html?highlight=
import numpy as np
import typecheck as tc

from psyneulink.components.component import Component, ExecutionStatus, function_type, method_type
from psyneulink.components.component import Component, InitStatus, ExecutionStatus, function_type, method_type
from psyneulink.components.shellclasses import Function, Mechanism, Projection, State
from psyneulink.components.states.inputstate import InputState
from psyneulink.components.states.state import _parse_state_spec
from psyneulink.globals.defaults import timeScaleSystemDefault
from psyneulink.globals.keywords import CHANGED, COMMAND_LINE, EVC_SIMULATION, EXECUTING, FUNCTION_PARAMS, INITIALIZING, INIT_FUNCTION_METHOD_ONLY, INIT__EXECUTE__METHOD_ONLY, INPUT_STATES, INPUT_STATE_PARAMS, MECHANISM_TIME_SCALE, MONITOR_FOR_CONTROL, MONITOR_FOR_LEARNING, NO_CONTEXT, OUTPUT_STATES, OUTPUT_STATE_PARAMS, PARAMETER_STATE_PARAMS, PROCESS_INIT, SEPARATOR_BAR, SET_ATTRIBUTE, SYSTEM_INIT, TIME_SCALE, UNCHANGED, VALIDATE, VARIABLE, kwMechanismComponentCategory, kwMechanismExecuteFunction
from psyneulink.globals.keywords import \
CHANGED, COMMAND_LINE, EVC_SIMULATION, EXECUTING, FUNCTION_PARAMS, \
INITIALIZING, INIT_FUNCTION_METHOD_ONLY, INIT__EXECUTE__METHOD_ONLY, \
INPUT_STATES, INPUT_STATE_PARAMS, MECHANISM_TIME_SCALE, MONITOR_FOR_CONTROL, MONITOR_FOR_LEARNING, \
NO_CONTEXT, OUTPUT_STATES, OUTPUT_STATE_PARAMS, PARAMETER_STATE_PARAMS, PROCESS_INIT, SEPARATOR_BAR, \
SET_ATTRIBUTE, SYSTEM_INIT, TIME_SCALE, UNCHANGED, VALIDATE, VARIABLE, VALUE, REFERENCE_VALUE, \
kwMechanismComponentCategory, kwMechanismExecuteFunction
from psyneulink.globals.preferences.preferenceset import PreferenceLevel
from psyneulink.globals.registry import register_category
from psyneulink.globals.utilities import AutoNumber, ContentAddressableList, append_type_to_name, convert_to_np_array, iscompatible, kwCompatibilityNumeric
Expand Down Expand Up @@ -1280,10 +1286,19 @@ def _parse_arg_input_states(self, input_states):
except KeyError:
pass
elif isinstance(parsed_spec, (Projection, Mechanism, State)):
try:
variable = parsed_spec.value
except AttributeError:
variable = parsed_spec.instance_defaults.variable
if parsed_spec.init_status is InitStatus.DEFERRED_INITIALIZATION:
args = parsed_spec.init_args
if REFERENCE_VALUE in args:
variable = args[REFERENCE_VALUE]
elif VALUE in args:
variable = args[VALUE]
elif VARIABLE in args:
variable = args[VARIABLE]
else:
try:
variable = parsed_spec.value
except AttributeError:
variable = parsed_spec.instance_defaults.variable
else:
variable = parsed_spec.instance_defaults.variable

Expand Down
10 changes: 7 additions & 3 deletions psyneulink/components/projections/pathway/pathwayprojection.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ def __init__(self,

def _assign_default_projection_name(self, state, sender_name=None, receiver_name=None):

from psyneulink.components.mechanisms.mechanism import Mechanism

# If the name is not a default name, leave intact
if not self.className + '-' in self.name:
return self.name

Expand All @@ -98,12 +101,13 @@ def _assign_default_projection_name(self, state, sender_name=None, receiver_name
self.name = self.className + " from " + sender_name + " to " + receiver_name

elif self.init_status is InitStatus.DEFERRED_INITIALIZATION:
if self.init_args[RECEIVER]:
if self.init_args[SENDER]:
sender = self.init_args[SENDER]
if sender.owner:
if isinstance(sender.owner, Mechanism):
sender_name = "{}[{}]".format(sender.owner.name, sender_name)
if self.init_args[RECEIVER]:
receiver = self.init_args[RECEIVER]
if receiver.owner:
if isinstance(receiver.owner, Mechanism):
receiver_name = "{}[{}]".format(receiver.owner.name, receiver_name)
projection_name = self.className + " from " + sender_name + " to " + receiver_name
self.init_args[NAME] = self.init_args[NAME] or projection_name
Expand Down

0 comments on commit 84ce4fc

Please sign in to comment.