Skip to content

Commit

Permalink
treewide: inherit all component Exceptions from ComponentError (Princ…
Browse files Browse the repository at this point in the history
…etonUniversity#2595)

useful for checking for categories of pnl component errors all at once
  • Loading branch information
kmantel authored Feb 4, 2023
1 parent 2e55a2e commit 58a4bea
Show file tree
Hide file tree
Showing 59 changed files with 201 additions and 343 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

from psyneulink.core import llvm as pnlvm
from psyneulink.core.components.functions.function import (
DEFAULT_SEED, Function_Base, _random_state_getter,
DEFAULT_SEED, Function_Base, FunctionError, _random_state_getter,
_seed_setter, is_function_type,
)
from psyneulink.core.globals.context import ContextFlags, handle_external_context
Expand All @@ -66,9 +66,8 @@
DIRECTION = 'direction'
SIMULATION_PROGRESS = 'simulation_progress'

class OptimizationFunctionError(Exception):
def __init__(self, error_value):
self.error_value = error_value
class OptimizationFunctionError(FunctionError):
pass


def _num_estimates_getter(owning_component, context):
Expand Down
10 changes: 3 additions & 7 deletions psyneulink/core/components/mechanisms/mechanism.py
Original file line number Diff line number Diff line change
Expand Up @@ -1087,7 +1087,7 @@
import typecheck as tc

from psyneulink.core import llvm as pnlvm
from psyneulink.core.components.component import Component
from psyneulink.core.components.component import Component, ComponentError
from psyneulink.core.components.functions.function import FunctionOutputType
from psyneulink.core.components.functions.nonstateful.transferfunctions import Linear
from psyneulink.core.components.ports.inputport import DEFER_VARIABLE_SPEC_TO_MECH_MSG, InputPort
Expand Down Expand Up @@ -1125,12 +1125,8 @@
MechanismRegistry = {}


class MechanismError(Exception):
def __init__(self, error_value):
self.error_value = error_value

def __str__(self):
return repr(self.error_value)
class MechanismError(ComponentError):
pass


class MechParamsDict(UserDict):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@
from psyneulink.core.components.functions.nonstateful.transferfunctions import Identity
from psyneulink.core.components.functions.nonstateful.combinationfunctions import Concatenate
from psyneulink.core.components.functions.nonstateful.combinationfunctions import LinearCombination
from psyneulink.core.components.mechanisms.mechanism import Mechanism, Mechanism_Base
from psyneulink.core.components.mechanisms.mechanism import Mechanism, Mechanism_Base, MechanismError
from psyneulink.core.components.mechanisms.modulatory.modulatorymechanism import ModulatoryMechanism_Base
from psyneulink.core.components.ports.inputport import InputPort
from psyneulink.core.components.ports.modulatorysignals.controlsignal import ControlSignal
Expand Down Expand Up @@ -640,10 +640,10 @@ def _is_control_spec(spec):
return False


class ControlMechanismError(Exception):
def __init__(self, error_value, data=None):
self.error_value = error_value
class ControlMechanismError(MechanismError):
def __init__(self, message, data=None):
self.data = data
return super().__init__(message)


def validate_monitored_port_spec(owner, spec_list):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import numpy as np
import typecheck as tc

from psyneulink.core.components.mechanisms.modulatory.control.controlmechanism import ControlMechanism
from psyneulink.core.components.mechanisms.modulatory.control.controlmechanism import ControlMechanism, ControlMechanismError
from psyneulink.core.components.mechanisms.processing.objectivemechanism import ObjectiveMechanism
from psyneulink.core.globals.defaults import defaultControlAllocation
from psyneulink.core.globals.keywords import CONTROL, INPUT_PORTS, NAME
Expand All @@ -50,9 +50,8 @@
]


class DefaultControlMechanismError(Exception):
def __init__(self, error_value):
self.error_value = error_value
class DefaultControlMechanismError(ControlMechanismError):
pass


class DefaultControlMechanism(ControlMechanism):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@
import numpy as np
import typecheck as tc

from psyneulink.core.components.mechanisms.modulatory.control.controlmechanism import ControlMechanism
from psyneulink.core.components.mechanisms.modulatory.control.controlmechanism import ControlMechanism, ControlMechanismError
from psyneulink.core.components.ports.modulatorysignals.gatingsignal import GatingSignal
from psyneulink.core.components.ports.port import _parse_port_spec
from psyneulink.core.globals.defaults import defaultGatingAllocation
Expand Down Expand Up @@ -222,9 +222,8 @@ def _is_gating_spec(spec):
return False


class GatingMechanismError(Exception):
def __init__(self, error_value):
self.error_value = error_value
class GatingMechanismError(ControlMechanismError):
pass


class GatingMechanism(ControlMechanism):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1213,12 +1213,8 @@ def _state_feature_values_getter(owning_component=None, context=None):
return state_feature_values


class OptimizationControlMechanismError(Exception):
def __init__(self, error_value):
self.error_value = error_value

def __str__(self):
return repr(self.error_value)
class OptimizationControlMechanismError(ControlMechanismError):
pass


def _control_allocation_search_space_getter(owning_component=None, context=None):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@

from psyneulink.core.components.component import parameter_keywords
from psyneulink.core.components.functions.nonstateful.learningfunctions import BackPropagation
from psyneulink.core.components.mechanisms.mechanism import Mechanism_Base
from psyneulink.core.components.mechanisms.mechanism import Mechanism_Base, MechanismError
from psyneulink.core.components.mechanisms.modulatory.modulatorymechanism import ModulatoryMechanism_Base
from psyneulink.core.components.mechanisms.processing.objectivemechanism import ObjectiveMechanism
from psyneulink.core.components.ports.modulatorysignals.learningsignal import LearningSignal
Expand Down Expand Up @@ -641,12 +641,8 @@ class LearningTiming(Enum):
DefaultTrainingMechanism = ObjectiveMechanism


class LearningMechanismError(Exception):
def __init__(self, error_value):
self.error_value = error_value

def __str__(self):
return repr(self.error_value)
class LearningMechanismError(MechanismError):
pass


def _learning_signal_getter(owning_component=None, context=None):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
"""

from psyneulink.core.components.mechanisms.mechanism import Mechanism_Base
from psyneulink.core.components.mechanisms.mechanism import Mechanism_Base, MechanismError
from psyneulink.core.globals.keywords import ADAPTIVE_MECHANISM
from psyneulink.core.globals.parameters import check_user_specified
from psyneulink.core.globals.preferences.preferenceset import PreferenceLevel
Expand All @@ -148,9 +148,8 @@
]


class ModulatoryMechanismError(Exception):
def __init__(self, error_value):
self.error_value = error_value
class ModulatoryMechanismError(MechanismError):
pass


class ModulatoryMechanism_Base(Mechanism_Base):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
from psyneulink.core.components.functions.function import Function
from psyneulink.core.components.functions.stateful.integratorfunctions import AdaptiveIntegrator
from psyneulink.core.components.mechanisms.processing.processingmechanism import ProcessingMechanism_Base
from psyneulink.core.components.mechanisms.mechanism import Mechanism
from psyneulink.core.components.mechanisms.mechanism import Mechanism, MechanismError
from psyneulink.core.globals.keywords import \
DEFAULT_VARIABLE, INTEGRATOR_MECHANISM, VARIABLE, PREFERENCE_SET_NAME
from psyneulink.core.globals.parameters import Parameter, check_user_specified
Expand All @@ -102,12 +102,8 @@
# IntegratorMechanism parameter keywords:
DEFAULT_RATE = 0.5

class IntegratorMechanismError(Exception):
def __init__(self, error_value):
self.error_value = error_value

def __str__(self):
return repr(self.error_value)
class IntegratorMechanismError(MechanismError):
pass


class IntegratorMechanism(ProcessingMechanism_Base):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@
import typecheck as tc

from psyneulink.core.components.functions.nonstateful.combinationfunctions import LinearCombination
from psyneulink.core.components.mechanisms.mechanism import MechanismError
from psyneulink.core.components.mechanisms.processing.processingmechanism import ProcessingMechanism_Base
from psyneulink.core.components.ports.inputport import InputPort, INPUT_PORT
from psyneulink.core.components.ports.outputport import OutputPort
Expand Down Expand Up @@ -400,12 +401,8 @@
DEFAULT_MONITORED_PORT_MATRIX = None


class ObjectiveMechanismError(Exception):
def __init__(self, error_value):
self.error_value = error_value

def __str__(self):
return repr(self.error_value)
class ObjectiveMechanismError(MechanismError):
pass


class ObjectiveMechanism(ProcessingMechanism_Base):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@

from psyneulink.core.components.functions.nonstateful.transferfunctions import SoftMax
from psyneulink.core.components.functions.nonstateful.selectionfunctions import OneHot
from psyneulink.core.components.mechanisms.mechanism import Mechanism_Base, Mechanism
from psyneulink.core.components.mechanisms.mechanism import Mechanism_Base, Mechanism, MechanismError
from psyneulink.core.components.ports.inputport import InputPort
from psyneulink.core.components.ports.outputport import OutputPort
from psyneulink.core.globals.keywords import \
Expand All @@ -108,9 +108,8 @@
]


class ProcessingMechanismError(Exception):
def __init__(self, error_value):
self.error_value = error_value
class ProcessingMechanismError(MechanismError):
pass


# # These are defined here because STANDARD_DEVIATION AND VARIANCE
Expand Down Expand Up @@ -217,13 +216,6 @@ def _validate_inputs(self, inputs=None):
# ProcessingMechanism parameter keywords:
DEFAULT_RATE = 0.5

class ProcessingMechanismError(Exception):
def __init__(self, error_value):
self.error_value = error_value

def __str__(self):
return repr(self.error_value)


class ProcessingMechanism(ProcessingMechanism_Base):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -883,12 +883,8 @@
logger = logging.getLogger(__name__)


class TransferError(Exception):
def __init__(self, error_value):
self.error_value = error_value

def __str__(self):
return repr(self.error_value)
class TransferError(MechanismError):
pass


def _integrator_mode_setter(value, owning_component=None, context=None):
Expand Down
8 changes: 2 additions & 6 deletions psyneulink/core/components/ports/inputport.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,12 +613,8 @@

DEFER_VARIABLE_SPEC_TO_MECH_MSG = "InputPort variable not yet defined, defer to Mechanism"

class InputPortError(Exception):
def __init__(self, error_value):
self.error_value = error_value

def __str__(self):
return repr(self.error_value)
class InputPortError(PortError):
pass


class InputPort(Port_Base):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@
from psyneulink.core.components.functions.nonstateful.transferfunctions import Exponential, Linear, CostFunctions, \
TransferWithCosts
from psyneulink.core.components.functions.stateful.integratorfunctions import SimpleIntegrator
from psyneulink.core.components.ports.modulatorysignals.modulatorysignal import ModulatorySignal
from psyneulink.core.components.ports.modulatorysignals.modulatorysignal import ModulatorySignal, ModulatorySignalError
from psyneulink.core.components.ports.outputport import _output_port_variable_getter
from psyneulink.core.globals.context import ContextFlags
from psyneulink.core.globals.defaults import defaultControlAllocation
Expand Down Expand Up @@ -440,13 +440,8 @@
COST_OPTIONS = 'cost_options'


class ControlSignalError(Exception):
def __init__(self, error_value):
self.error_value = error_value


def __str__(self):
return repr(self.error_value)
class ControlSignalError(ModulatorySignalError):
pass


class ControlSignal(ModulatorySignal):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@
import typecheck as tc

from psyneulink.core.components.ports.modulatorysignals.controlsignal import ControlSignal
from psyneulink.core.components.ports.modulatorysignals.modulatorysignal import ModulatorySignalError
from psyneulink.core.components.ports.outputport import _output_port_variable_getter
from psyneulink.core.globals.defaults import defaultGatingAllocation
from psyneulink.core.globals.keywords import \
Expand All @@ -261,12 +262,8 @@
]


class GatingSignalError(Exception):
def __init__(self, error_value):
self.error_value = error_value

def __str__(self):
return repr(self.error_value)
class GatingSignalError(ModulatorySignalError):
pass


gating_signal_keywords = {GATE}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@
import numpy as np
import typecheck as tc

from psyneulink.core.components.ports.modulatorysignals.modulatorysignal import ModulatorySignal
from psyneulink.core.components.ports.modulatorysignals.modulatorysignal import ModulatorySignal, ModulatorySignalError
from psyneulink.core.components.ports.outputport import PRIMARY
from psyneulink.core.globals.keywords import \
LEARNING_PROJECTION, LEARNING_SIGNAL, OUTPUT_PORT_PARAMS, PARAMETER_PORT, PARAMETER_PORTS, RECEIVER
Expand All @@ -204,13 +204,8 @@
]


class LearningSignalError(Exception):
def __init__(self, error_value):
self.error_value = error_value


def __str__(self):
return repr(self.error_value)
class LearningSignalError(ModulatorySignalError):
pass


class LearningSignal(ModulatorySignal):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@

from psyneulink.core.components.component import component_keywords
from psyneulink.core.components.ports.outputport import OutputPort
from psyneulink.core.components.ports.port import PortError
from psyneulink.core.globals.context import ContextFlags
from psyneulink.core.globals.defaults import defaultModulatoryAllocation
from psyneulink.core.globals.keywords import \
Expand Down Expand Up @@ -439,12 +440,8 @@ def _is_modulatory_spec(spec, include_matrix_spec=True):
modulation_type_keywords = [MULTIPLICATIVE_PARAM, ADDITIVE_PARAM, OVERRIDE, DISABLE]


class ModulatorySignalError(Exception):
def __init__(self, error_value):
self.error_value = error_value

def __str__(self):
return repr(self.error_value)
class ModulatorySignalError(PortError):
pass


class ModulatorySignal(OutputPort):
Expand Down
Loading

0 comments on commit 58a4bea

Please sign in to comment.