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

Fix/input state specs #518

Merged
merged 6 commits into from
Nov 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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