• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

SpiNNakerManchester / sPyNNaker / 6903300058

17 Nov 2023 11:18AM UTC coverage: 63.17% (+1.6%) from 61.531%
6903300058

Pull #1342

github

Christian-B
oops
Pull Request #1342: Type Annotations and Checking

1961 of 4484 branches covered (0.0%)

Branch coverage included in aggregate %.

4169 of 5103 new or added lines in 234 files covered. (81.7%)

193 existing lines in 78 files now uncovered.

12745 of 18796 relevant lines covered (67.81%)

0.68 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

28.75
/spynnaker/pyNN/models/current_sources/step_current_source.py
1
# Copyright (c) 2017 The University of Manchester
2
#
3
# Licensed under the Apache License, Version 2.0 (the "License");
4
# you may not use this file except in compliance with the License.
5
# You may obtain a copy of the License at
6
#
7
#     https://www.apache.org/licenses/LICENSE-2.0
8
#
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS,
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
# See the License for the specific language governing permissions and
13
# limitations under the License.
14

15
from typing import Dict, Mapping, Sequence
1✔
16
from spinn_utilities.overrides import overrides
1✔
17
from spinn_front_end_common.interface.ds import DataType
1✔
18
from spinn_front_end_common.utilities.constants import BYTES_PER_WORD
1✔
19
from spynnaker.pyNN.data import SpynnakerDataView
1✔
20
from spynnaker.pyNN.exceptions import SpynnakerException
1✔
21
from .abstract_current_source import (
1✔
22
    AbstractCurrentSource, CurrentSourceIDs, CurrentParameter)
23

24

25
class StepCurrentSource(AbstractCurrentSource):
1✔
26
    """
27
    Current source where the amplitude changes based on a time array.
28
    """
29
    __slots__ = (
1✔
30
        "__amplitudes",
31
        "__times",
32
        "__parameters",
33
        "__parameter_types")
34

35
    def __init__(
1✔
36
            self, times: Sequence[int] = (), amplitudes: Sequence[float] = ()):
37
        """
38
        :param list(int) times:
39
        :param list(float) amplitudes:
40
        """
41
        # There's probably no need to actually store these as you can't
42
        # access them directly in pynn anyway
43
        time_convert_ms = SpynnakerDataView.get_simulation_time_step_per_ms()
×
NEW
44
        self.__times = [
×
45
            int(times[i] * time_convert_ms) for i in range(len(times))]
UNCOV
46
        self.__amplitudes = amplitudes
×
47

NEW
48
        if len(times) != len(amplitudes):
×
49
            raise SpynnakerException(
×
50
                f"In StepCurrentSource, len(times) is {len(times)}, "
51
                f" but len(amplitudes) is {len(amplitudes)}")
52

NEW
53
        self.__parameter_types = {
×
54
            'times': DataType.UINT32,  # arrays?
55
            'amplitudes': DataType.S1615}
56

NEW
57
        self.__parameters: Dict[str, CurrentParameter] = {
×
58
            'times': self.__times,
59
            'amplitudes': self.__amplitudes}
60

61
        super().__init__()
×
62

63
    @overrides(AbstractCurrentSource.set_parameters)
1✔
64
    def set_parameters(self, **parameters: CurrentParameter):
1✔
65
        for key, value in parameters.items():
×
66
            if key not in self.__parameters.keys():
×
67
                # throw an exception
68
                raise SpynnakerException(f"{key} is not a parameter of {self}")
×
NEW
69
            if not isinstance(value, Sequence):
×
NEW
70
                raise TypeError
×
71
            if key == 'times':
×
72
                time_convert_ms = SpynnakerDataView.\
×
73
                    get_simulation_time_step_per_ms()
74
                self.__times = [
×
75
                    int(value[i] * time_convert_ms) for i in range(len(value))]
76
                value = self.__times
×
77
            else:
78
                # Check length: if longer, need to remap
NEW
79
                if len(self.__amplitudes) < len(value):
×
80
                    if self.population is not None:
×
81
                        SpynnakerDataView.set_requires_mapping()
×
82

83
                self.__amplitudes = value
×
84
            self.__parameters[key] = value
×
85

86
        # Check the arrays are still the same lengths
NEW
87
        if len(self.__times) != len(self.__amplitudes):
×
88
            raise SpynnakerException(
×
89
                f"In StepCurrentSource, len(times) is {len(self.__times)}, "
90
                f"but len(amplitudes) is {len(self.__amplitudes)}")
91

92
        # Parameters have been set, so if multi-run then it will have been
93
        # injected already; if not then it can just be ignored
94
        if self.app_vertex is not None:
×
95
            for m_vertex in self.app_vertex.machine_vertices:
×
96
                m_vertex.set_reload_required(True)
×
97

98
    @property
1✔
99
    @overrides(AbstractCurrentSource.parameters)
1✔
100
    def parameters(self) -> Mapping[str, CurrentParameter]:
1✔
UNCOV
101
        return self.__parameters
×
102

103
    @property
1✔
104
    @overrides(AbstractCurrentSource.parameter_types)
1✔
105
    def parameter_types(self) -> Mapping[str, DataType]:
1✔
UNCOV
106
        return self.__parameter_types
×
107

108
    @property
1✔
109
    @overrides(AbstractCurrentSource.current_source_id)
1✔
110
    def current_source_id(self) -> int:
1✔
111
        return CurrentSourceIDs.STEP_CURRENT_SOURCE.value
×
112

113
    @overrides(AbstractCurrentSource.get_sdram_usage_in_bytes)
1✔
114
    def get_sdram_usage_in_bytes(self) -> int:
1✔
115
        # The parameters themselves take up this amount of space
116
        # ((len(times) + length_val)) * 2) + ID
117
        sdram_for_parameters = ((len(self.__times) + 1) * 2) * BYTES_PER_WORD
×
118

119
        # For each_source there is the last amplitude holder and index
120
        sdram_for_on_core_calcs = 2 * BYTES_PER_WORD
×
121

122
        return sdram_for_parameters + sdram_for_on_core_calcs
×
123
        # return sdram_for_parameters
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc