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

GatingMechanism: properly set gating_allocation as value alias #2191

Merged
merged 1 commit into from
Nov 18, 2021
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
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