Skip to content

Commit

Permalink
GatingMechanism: properly set gating_allocation as value alias
Browse files Browse the repository at this point in the history
  • Loading branch information
kmantel committed Nov 16, 2021
1 parent 819faca commit 3613763
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 41 deletions.
19 changes: 6 additions & 13 deletions psyneulink/core/components/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -3844,21 +3844,14 @@ def _update_parameter_components(self, context=None):
# store all Components in Parameters to be used in
# _dependent_components for _initialize_from_context
for p in self.parameters:
param_value = p._get(context)
try:
param_value = p._get(context)
try:
param_value = param_value.__self__
except AttributeError:
pass
param_value = param_value.__self__
except AttributeError:
pass

if isinstance(param_value, Component) and param_value is not self:
self._parameter_components.add(param_value)
# ControlMechanism and GatingMechanism have Parameters that only
# throw these errors
except Exception as e:
# cannot import the specific exceptions due to circularity
if 'attribute is not implemented on' not in str(e):
raise
if isinstance(param_value, Component) and param_value is not self:
self._parameter_components.add(param_value)

@property
def _dependent_components(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,29 +227,6 @@ class GatingMechanismError(Exception):
def __init__(self, error_value):
self.error_value = error_value

def _gating_allocation_getter(owning_component=None, context=None):
return owning_component.control_allocation

def _gating_allocation_setter(value, owning_component=None, context=None):
owning_component.parameters.control_allocation._set(np.array(value), context)
return value

# def _control_allocation_getter(owning_component=None, context=None):
# from psyneulink.core.components.mechanisms.modulatory.controlmechanism import ControlMechanism
# from psyneulink.core.components.ports.modulatorysignals.controlsignal import ControlSignal
# raise GatingMechanismError(f"'control_allocation' attribute is not implemented on {owning_component.name}; "
# f"consider using a {ControlMechanism.__name__} instead, "
# f"or a {ControlMechanism.__name__} if both {ControlSignal.__name__}s and "
# f"{GatingSignal.__name__}s are needed.")
#
# def _control_allocation_setter(value, owning_component=None, context=None, **kwargs):
# from psyneulink.core.components.mechanisms.modulatory.controlmechanism import ControlMechanism
# from psyneulink.core.components.ports.modulatorysignals.controlsignal import ControlSignal
# raise GatingMechanismError(f"'control_allocation' attribute is not implemented on {owning_component.name}; "
# f"consider using a {ControlMechanism.__name__} instead, "
# f"or a {ControlMechanism.__name__} if both {ControlSignal.__name__}s and "
# f"{GatingSignal.__name__}s are needed.")


class GatingMechanism(ControlMechanism):
"""
Expand Down Expand Up @@ -430,12 +407,9 @@ class Parameters(ControlMechanism.Parameters):
:read only: True
"""
# This must be a list, as there may be more than one (e.g., one per control_signal)
value = Parameter(np.array([defaultGatingAllocation]), aliases='control_allocation', pnl_internal=True)
gating_allocation = Parameter(
value = Parameter(
np.array([defaultGatingAllocation]),
getter=_gating_allocation_getter,
setter=_gating_allocation_setter,
read_only=True,
aliases=['control_allocation', 'gating_allocation'],
pnl_internal=True
)

Expand Down

0 comments on commit 3613763

Please sign in to comment.