Skip to content

Commit

Permalink
Revert "Refactor/mechanism/preprocess variable (#531)"
Browse files Browse the repository at this point in the history
This reverts commit 7a8b1fc.
  • Loading branch information
kmantel committed Nov 15, 2017
1 parent 034d616 commit 72b0ab8
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 80 deletions.
6 changes: 5 additions & 1 deletion 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(name='TEMP', input_states=[I])
pnl.TransferMechanism(input_states=[I])

p = pnl.MappingProjection()
T = pnl.TransferMechanism(input_states=[{pnl.VARIABLE: [0, 0, 0], pnl.PROJECTIONS:[p]}])
Expand Down Expand Up @@ -530,6 +530,10 @@ 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: 0 additions & 8 deletions psyneulink/components/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -796,8 +796,6 @@ 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 @@ -886,12 +884,6 @@ 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: 63 additions & 71 deletions psyneulink/components/mechanisms/mechanism.py
Original file line number Diff line number Diff line change
Expand Up @@ -1097,6 +1097,69 @@ 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 @@ -1205,77 +1268,6 @@ def __init__(self,
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

0 comments on commit 72b0ab8

Please sign in to comment.