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/mechanism/preprocess variable #531

Merged
merged 30 commits into from
Nov 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
e725a33
-
jdcpni Nov 4, 2017
cb04745
Merge branch 'devel' of https://github.com/PrincetonUniversity/PsyNeu…
jdcpni Nov 5, 2017
ea3b359
Merge branch 'devel' of https://github.com/PrincetonUniversity/PsyNeu…
jdcpni Nov 9, 2017
0c24e98
Merge branch 'devel' of https://github.com/PrincetonUniversity/PsyNeu…
jdcpni Nov 9, 2017
7b545b4
Merge branch 'devel' of https://github.com/PrincetonUniversity/PsyNeu…
jdcpni Nov 9, 2017
d5d6d6d
• State
jdcpni Nov 12, 2017
6f095fb
• State
jdcpni Nov 12, 2017
f4dd3d1
• State
jdcpni Nov 12, 2017
d3df60b
Merge branch 'devel' of https://github.com/PrincetonUniversity/PsyNeu…
jdcpni Nov 12, 2017
d96b946
• State
jdcpni Nov 13, 2017
04cdd30
• State
jdcpni Nov 13, 2017
a8b0f91
• State, Projection
jdcpni Nov 13, 2017
af796d2
-
jdcpni Nov 13, 2017
9186346
-
jdcpni Nov 13, 2017
78181d4
-
jdcpni Nov 13, 2017
f3f713c
• Utilities
jdcpni Nov 13, 2017
dd342e2
• Utilities
jdcpni Nov 13, 2017
ddbe7d3
• Utilities
jdcpni Nov 13, 2017
bbbe722
-
jdcpni Nov 13, 2017
9fa9ee6
-
jdcpni Nov 13, 2017
576800b
-
jdcpni Nov 13, 2017
7ca2984
-
jdcpni Nov 14, 2017
fe18840
-
jdcpni Nov 14, 2017
fcebf28
Merge branches 'devel' and 'docs/State_and_Projections/docstring_revs…
jdcpni Nov 14, 2017
185dd85
-
jdcpni Nov 14, 2017
2d85143
-
jdcpni Nov 14, 2017
7475d25
-
jdcpni Nov 14, 2017
d428b97
-
jdcpni Nov 14, 2017
11ad8c4
• Mechanism, Component
jdcpni Nov 14, 2017
2855c80
• Mechanism, Component
jdcpni Nov 14, 2017
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
6 changes: 1 addition & 5 deletions Scripts/Scratch Pad.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ def __init__(self, error_value):
# print(projection.name)

I = pnl.InputState(reference_value=[0,0,0])
pnl.TransferMechanism(input_states=[I])
pnl.TransferMechanism(name='TEMP', input_states=[I])

p = pnl.MappingProjection()
T = pnl.TransferMechanism(input_states=[{pnl.VARIABLE: [0, 0, 0], pnl.PROJECTIONS:[p]}])
Expand Down Expand Up @@ -530,10 +530,6 @@ def __init__(self, error_value):
# my_control_mech = pnl.ControlMechanism(control_signals=[{pnl.MECHANISM: my_mech,
# pnl.PARAMETER_STATES: [pnl.DRIFT_RATE, pnl.THRESHOLD]}])

m = pnl.TransferMechanism(default_variable=[0, 0, 0])
i = pnl.InputState(owner=m, variable=[0, 0, 0])
T = pnl.TransferMechanism(input_states=[i])

assert True

# --------------------------------------------------------------------------------------------------
Expand Down
8 changes: 8 additions & 0 deletions psyneulink/components/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,8 @@ def __init__(self,
# Used by run to store return value of execute
self.results = []

default_variable, param_defaults = self._preprocess_variable(default_variable, size, param_defaults)


# ENFORCE REQUIRED CLASS DEFAULTS

Expand Down Expand Up @@ -884,6 +886,12 @@ def __init__(self,

self.init_status = InitStatus.INITIALIZED

def _preprocess_variable(self, variable, size, params):
# TODO:
# this is part of the hack in Mechanism to accept input_states as a way to instantiate default_variable for
# this release should be cleaned ASAP in default_variable overhaul
return variable, params

def __repr__(self):
return '({0} {1})'.format(type(self).__name__, self.name)
#return '{1}'.format(type(self).__name__, self.name)
Expand Down
134 changes: 71 additions & 63 deletions psyneulink/components/mechanisms/mechanism.py
Original file line number Diff line number Diff line change
Expand Up @@ -1097,69 +1097,6 @@ def __init__(self,
raise MechanismError("Direct call to abstract class Mechanism() is not allowed; "
"use a subclass")

# TODO:
# this is a hack to accept input_states as a way to instantiate default_variable for this release
# should be cleaned ASAP in default_variable overhaul
default_variable_from_input_states = None

def spec_incompatible_with_default_error(spec_variable, default_variable):
return MechanismError(
'default variable determined from the specified input_states spec ({0}) '
'is not compatible with the specified default variable ({1})'.format(
spec_variable, default_variable
)
)

# handle specifying through params dictionary
try:
default_variable_from_input_states, input_states_variable_was_specified = \
self._parse_arg_input_states(params[INPUT_STATES])
except (TypeError, KeyError):
pass

if default_variable_from_input_states is None:
# fallback to standard arg specification
default_variable_from_input_states, input_states_variable_was_specified = \
self._parse_arg_input_states(input_states)

if default_variable_from_input_states is not None:
if variable is None:
if size is None:
variable = default_variable_from_input_states
else:
if input_states_variable_was_specified:
size_variable = self._handle_size(size, None)
if iscompatible(size_variable, default_variable_from_input_states):
variable = default_variable_from_input_states
else:
raise MechanismError(
'default variable determined from the specified input_states spec ({0}) '
'is not compatible with the default variable determined from size parameter ({1})'.
format(default_variable_from_input_states, size_variable,
)
)
else:
# do not pass input_states variable as default_variable, fall back to size specification
pass
else:
compatible = iscompatible(self._parse_arg_variable(variable), default_variable_from_input_states)
if size is None:
if input_states_variable_was_specified:
if compatible:
variable = default_variable_from_input_states
else:
raise spec_incompatible_with_default_error(default_variable_from_input_states, variable)
else:
pass
else:
if input_states_variable_was_specified:
if compatible:
variable = default_variable_from_input_states
else:
raise spec_incompatible_with_default_error(default_variable_from_input_states, variable)
else:
pass

# IMPLEMENT **kwargs (PER State)


Expand Down Expand Up @@ -1268,6 +1205,77 @@ def spec_incompatible_with_default_error(spec_variable, default_variable):
self.processes = {}
self.systems = {}


def _preprocess_variable(self, default_variable, size, params):

# TODO:
# this is a hack to accept input_states as a way to instantiate default_variable for this release
# should be cleaned ASAP in default_variable overhaul
default_variable_from_input_states = None

def spec_incompatible_with_default_error(spec_variable, local_default_variable):
return MechanismError(
'default variable determined from the specified input_states spec ({0}) '
'is not compatible with the specified default variable ({1})'.format(
spec_variable, local_default_variable
)
)

# handle specifying through params dictionary
try:
default_variable_from_input_states, input_states_variable_was_specified = \
self._parse_arg_input_states(params[INPUT_STATES])
except (TypeError, KeyError):
pass

if default_variable_from_input_states is None:
# fallback to standard arg specification
default_variable_from_input_states, input_states_variable_was_specified = \
self._parse_arg_input_states(self.input_states)

if default_variable_from_input_states is not None:
if default_variable is None:
if size is None:
default_variable = default_variable_from_input_states
else:
if input_states_variable_was_specified:
size_variable = self._handle_size(size, None)
if iscompatible(size_variable, default_variable_from_input_states):
variable = default_variable_from_input_states
else:
raise MechanismError(
'default variable determined from the specified input_states spec ({0}) '
'is not compatible with the default variable determined from size parameter ({1})'.
format(default_variable_from_input_states, size_variable,
)
)
else:
# do not pass input_states variable as default_variable, fall back to size specification
pass
else:
compatible = iscompatible(self._parse_arg_variable(default_variable),
default_variable_from_input_states)
if size is None:
if input_states_variable_was_specified:
if compatible:
variable = default_variable_from_input_states
else:
raise spec_incompatible_with_default_error(default_variable_from_input_states,
default_variable)
else:
pass
else:
if input_states_variable_was_specified:
if compatible:
variable = default_variable_from_input_states
else:
raise spec_incompatible_with_default_error(default_variable_from_input_states,
default_variable)
else:
pass

return default_variable, params

def _parse_arg_variable(self, variable):
'''
Takes user-inputted argument **variable** and returns an instance_defaults.variable-like
Expand Down