diff --git a/Scripts/Scratch Pad.py b/Scripts/Scratch Pad.py index f7d3531fa86..42c037bad72 100644 --- a/Scripts/Scratch Pad.py +++ b/Scripts/Scratch Pad.py @@ -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]}]) @@ -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 # -------------------------------------------------------------------------------------------------- diff --git a/psyneulink/components/component.py b/psyneulink/components/component.py index 916e1c48d80..95b4a5bc335 100644 --- a/psyneulink/components/component.py +++ b/psyneulink/components/component.py @@ -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 @@ -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) diff --git a/psyneulink/components/mechanisms/mechanism.py b/psyneulink/components/mechanisms/mechanism.py index 32d80ca9ead..b8686f3b610 100644 --- a/psyneulink/components/mechanisms/mechanism.py +++ b/psyneulink/components/mechanisms/mechanism.py @@ -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) @@ -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