File: errors.py

package info (click to toggle)
pynn 0.10.1-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,156 kB
  • sloc: python: 25,612; cpp: 320; makefile: 117; sh: 80
file content (94 lines) | stat: -rw-r--r-- 2,578 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# encoding: utf-8
"""
Defines exceptions for the PyNN API

    InvalidParameterValueError
    NonExistentParameterError
    InvalidDimensionsError
    ConnectionError
    InvalidModelError
    RoundingWarning
    NothingToWriteError
    InvalidWeightError
    NotLocalError
    RecordingError

:copyright: Copyright 2006-2022 by the PyNN team, see AUTHORS.
:license: CeCILL, see LICENSE for details.
"""


class InvalidParameterValueError(ValueError):
    """Inappropriate parameter value"""
    pass


class NonExistentParameterError(KeyError):
    """
    Model parameter does not exist.
    """

    def __init__(self, parameter_name, model_name, valid_parameter_names=['unknown']):
        Exception.__init__(self)
        self.parameter_name = parameter_name
        self.model_name = model_name
        self.valid_parameter_names = sorted(valid_parameter_names)

    def __str__(self):
        return "%s (valid parameters for %s are: %s)" % (self.parameter_name,
                                                         self.model_name,
                                                         ", ".join(self.valid_parameter_names))


class InvalidDimensionsError(ValueError):
    """Argument has inappropriate shape/dimensions."""
    pass


class ConnectionError(Exception):
    """Attempt to create an invalid connection or access a non-existent connection."""
    pass


class InvalidModelError(Exception):
    """Attempt to use a non-existent model type."""
    pass


class NoModelAvailableError(Exception):
    """The simulator does not implement the requested model."""
    pass


class RoundingWarning(Warning):
    """The argument has been rounded to a lower level of precision by the simulator."""
    pass


class NothingToWriteError(IOError):
    """There is no data available to write."""
    pass


class InvalidWeightError(ValueError):
    """Invalid value for the synaptic weight."""
    pass


class NotLocalError(Exception):
    """Attempt to access a cell or connection that does not exist on this node (but exists elsewhere)."""
    pass


class RecordingError(Exception):  # subclass AttributeError?
    """Attempt to record a variable that does not exist for this cell type."""

    def __init__(self, variable, cell_type):
        self.variable = variable
        self.cell_type = cell_type

    def __str__(self):
        msg = "Cannot record %s from cell type %s. Available variables are %s"
        return msg % (self.variable,
                      self.cell_type.__class__.__name__,
                      ",".join(self.cell_type.recordable))