Skip to content

Commit 9c6acb4

Browse files
authored
Merge branch 'master' into pylint
2 parents 79c7d53 + e444814 commit 9c6acb4

21 files changed

Lines changed: 113 additions & 111 deletions

spynnaker/pyNN/connections/spif_live_spikes_connection.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import logging
1616
import struct
1717
from threading import Thread
18-
from typing import Callable, Dict, Iterable, List, Optional, Set, Tuple
18+
from typing import Callable, Dict, Final, Iterable, List, Optional, Set, Tuple
1919
from typing_extensions import TypeAlias
2020
from spinn_utilities.log import FormatAdapter
2121
from spinnman.connections import ConnectionListener
@@ -24,9 +24,10 @@
2424
from spinn_front_end_common.utilities.database import DatabaseConnection
2525
from spinn_front_end_common.utilities.database import DatabaseReader
2626

27-
_EventCB: TypeAlias = Callable[[str, List[int]], None]
28-
_InitCB: TypeAlias = Callable[[str, int, float, float], None]
29-
_StartStopCB: TypeAlias = Callable[[str, 'SPIFLiveSpikesConnection'], None]
27+
_EVENT: Final['TypeAlias'] = Callable[[str, List[int]], None]
28+
_INIT: Final['TypeAlias'] = Callable[[str, int, float, float], None]
29+
_START_STOP: Final['TypeAlias'] = Callable[
30+
[str, 'SPIFLiveSpikesConnection'], None]
3031
logger = FormatAdapter(logging.getLogger(__name__))
3132

3233
_TWO_SKIP = struct.Struct("<2x")
@@ -118,10 +119,10 @@ def __init__(self, receive_labels: Optional[Iterable[str]],
118119
self.__spif_packet_size = events_per_packet * BYTES_PER_WORD
119120
self.__spif_packet_time_us = time_per_packet
120121
self.__key_to_atom_id_and_label: Dict[int, Tuple[int, int]] = dict()
121-
self.__live_event_callbacks: List[List[Tuple[_EventCB, bool]]] = list()
122-
self.__start_resume_callbacks: Dict[str, List[_StartStopCB]] = dict()
123-
self.__pause_stop_callbacks: Dict[str, List[_StartStopCB]] = dict()
124-
self.__init_callbacks: Dict[str, List[_InitCB]] = dict()
122+
self.__live_event_callbacks: List[List[Tuple[_EVENT, bool]]] = list()
123+
self.__start_resume_callbacks: Dict[str, List[_START_STOP]] = dict()
124+
self.__pause_stop_callbacks: Dict[str, List[_START_STOP]] = dict()
125+
self.__init_callbacks: Dict[str, List[_INIT]] = dict()
125126
if receive_labels is not None:
126127
for label in receive_labels:
127128
self.__live_event_callbacks.append(list())
@@ -144,7 +145,7 @@ def add_receive_label(self, label: str) -> None:
144145
self.__pause_stop_callbacks[label] = list()
145146
self.__init_callbacks[label] = list()
146147

147-
def add_init_callback(self, label: str, init_callback: _InitCB) -> None:
148+
def add_init_callback(self, label: str, init_callback: _INIT) -> None:
148149
"""
149150
Add a callback to be called to initialise a vertex.
150151
@@ -161,7 +162,7 @@ def add_init_callback(self, label: str, init_callback: _InitCB) -> None:
161162
self.__init_callbacks[label].append(init_callback)
162163

163164
def add_receive_callback(
164-
self, label: str, live_event_callback: _EventCB,
165+
self, label: str, live_event_callback: _EVENT,
165166
translate_key: bool = True) -> None:
166167
"""
167168
Add a callback for the reception of live events from a vertex.
@@ -184,7 +185,7 @@ def add_receive_callback(
184185
(live_event_callback, translate_key))
185186

186187
def add_start_resume_callback(
187-
self, label: str, start_resume_callback: _StartStopCB) -> None:
188+
self, label: str, start_resume_callback: _START_STOP) -> None:
188189
"""
189190
Add a callback for the start and resume state of the simulation.
190191
@@ -200,7 +201,7 @@ def add_start_resume_callback(
200201
self.__start_resume_callbacks[label].append(start_resume_callback)
201202

202203
def add_pause_stop_callback(
203-
self, label: str, pause_stop_callback: _StartStopCB) -> None:
204+
self, label: str, pause_stop_callback: _START_STOP) -> None:
204205
"""
205206
Add a callback for the pause and stop state of the simulation.
206207
@@ -267,7 +268,7 @@ def __handle_possible_rerun_state(self) -> None:
267268
self.__receiver_connection = None
268269

269270
def __launch_thread(
270-
self, kind: str, label: str, callback: _StartStopCB) -> None:
271+
self, kind: str, label: str, callback: _START_STOP) -> None:
271272
thread = Thread(target=callback, args=(label, self), name=(
272273
f"{kind} callback thread for live_event_connection "
273274
f"{self._local_port}:{self._local_ip_address}"))

spynnaker/pyNN/extra_algorithms/splitter_components/splitter_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
from spynnaker.pyNN.models.neuron.synapse_dynamics import (
2222
AbstractSynapseDynamics, SynapseDynamicsStatic)
2323
from spynnaker.pyNN.models.spike_source import SpikeSourcePoissonVertex
24-
from spynnaker.pyNN.types import Delay_Types
24+
from spynnaker.pyNN.types import DELAYS
2525

2626

2727
def is_direct_poisson_source(
2828
post_vertex: ApplicationVertex, pre_vertex: ApplicationVertex,
2929
connector: AbstractConnector, dynamics: AbstractSynapseDynamics,
30-
delay: Delay_Types) -> bool:
30+
delay: DELAYS) -> bool:
3131
"""
3232
Determine if a given Poisson source can be created by this splitter.
3333

spynnaker/pyNN/models/neural_projections/connectors/abstract_connector.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
from spynnaker.pyNN.data import SpynnakerDataView
4242
from spynnaker.pyNN.types import (
43-
Delay_Types, is_scalar, Weight_Delay_Types, Weight_Types)
43+
DELAYS, is_scalar, WEIGHTS_DELAYS, WEIGHTS)
4444
from spynnaker.pyNN.utilities import utility_calls
4545
from spynnaker.pyNN.exceptions import SpynnakerException
4646

@@ -122,7 +122,7 @@ def set_projection_information(
122122
self.__min_delay = SpynnakerDataView.get_simulation_time_step_ms()
123123

124124
def _get_delay_minimum(
125-
self, delays: Delay_Types, n_connections: int,
125+
self, delays: DELAYS, n_connections: int,
126126
synapse_info: SynapseInformation) -> float:
127127
"""
128128
Get the minimum delay given a float or RandomDistribution.
@@ -148,7 +148,7 @@ def _get_delay_minimum(
148148
raise self.delay_type_exception(delays)
149149

150150
def _get_delay_maximum(
151-
self, delays: Delay_Types, n_connections: int,
151+
self, delays: DELAYS, n_connections: int,
152152
synapse_info: SynapseInformation) -> float:
153153
"""
154154
Get the maximum delay given a float or RandomDistribution.
@@ -195,7 +195,7 @@ def get_delay_minimum(
195195
"""
196196
raise NotImplementedError
197197

198-
def get_delay_variance(self, delays: Delay_Types,
198+
def get_delay_variance(self, delays: DELAYS,
199199
synapse_info: SynapseInformation) -> float:
200200
"""
201201
Get the variance of the delays.
@@ -214,7 +214,7 @@ def get_delay_variance(self, delays: Delay_Types,
214214
raise self.delay_type_exception(delays)
215215

216216
def _get_n_connections_from_pre_vertex_with_delay_maximum(
217-
self, delays: Delay_Types, n_total_connections: int,
217+
self, delays: DELAYS, n_total_connections: int,
218218
n_connections: int, min_delay: float, max_delay: float,
219219
synapse_info: SynapseInformation) -> int:
220220
"""
@@ -294,7 +294,7 @@ def get_n_connections_to_post_vertex_maximum(
294294
"""
295295
raise NotImplementedError
296296

297-
def get_weight_mean(self, weights: Weight_Types,
297+
def get_weight_mean(self, weights: WEIGHTS,
298298
synapse_info: SynapseInformation) -> float:
299299
"""
300300
Get the mean of the weights.
@@ -313,7 +313,7 @@ def get_weight_mean(self, weights: Weight_Types,
313313
raise self.weight_type_exception(synapse_info)
314314

315315
def _get_weight_maximum(
316-
self, weights: Weight_Types, n_connections: int,
316+
self, weights: WEIGHTS, n_connections: int,
317317
synapse_info: SynapseInformation) -> float:
318318
"""
319319
Get the maximum of the weights.
@@ -356,7 +356,7 @@ def get_weight_maximum(self, synapse_info: SynapseInformation) -> float:
356356
"""
357357
raise NotImplementedError
358358

359-
def get_weight_variance(self, weights: Weight_Types,
359+
def get_weight_variance(self, weights: WEIGHTS,
360360
synapse_info: SynapseInformation) -> float:
361361
"""
362362
Get the variance of the weights.
@@ -422,7 +422,7 @@ def _generate_random_values(
422422
return copy_rd.next(n_connections)
423423

424424
def _no_space_exception(
425-
self, values: Weight_Delay_Types,
425+
self, values: WEIGHTS_DELAYS,
426426
synapse_info: SynapseInformation) -> SpynnakerException:
427427
"""
428428
Returns a SpynnakerException about there being no space defined
@@ -438,7 +438,7 @@ def _no_space_exception(
438438
f"{synapse_info.post_population}")
439439

440440
def weight_type_exception(
441-
self, weights: Weight_Types) -> SpynnakerException:
441+
self, weights: WEIGHTS) -> SpynnakerException:
442442
"""
443443
Returns an Exception explaining incorrect weight or delay type
444444
@@ -463,7 +463,7 @@ def weight_type_exception(
463463
else:
464464
return SpynnakerException(f"Unrecognised weight {weights}")
465465

466-
def delay_type_exception(self, delays: Delay_Types) -> SpynnakerException:
466+
def delay_type_exception(self, delays: DELAYS) -> SpynnakerException:
467467
"""
468468
Returns an Exception explaining incorrect delay type
469469
@@ -485,7 +485,7 @@ def delay_type_exception(self, delays: Delay_Types) -> SpynnakerException:
485485
return SpynnakerException(f"Unrecognised delay {delays}")
486486

487487
def _generate_values(
488-
self, values: Weight_Delay_Types, sources: numpy.ndarray,
488+
self, values: WEIGHTS_DELAYS, sources: numpy.ndarray,
489489
targets: numpy.ndarray, n_connections: int, post_slice: Slice,
490490
synapse_info: SynapseInformation,
491491
weights: bool) -> NDArray[float64]:

spynnaker/pyNN/models/neural_projections/connectors/abstract_generate_connector_on_machine.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
from spynnaker.pyNN.models.common.param_generator_data import (
3232
param_generator_params, param_generator_params_size_in_bytes,
3333
param_generator_id, is_param_generatable)
34-
from spynnaker.pyNN.types import (Delay_Types, Weight_Types)
34+
from spynnaker.pyNN.types import (DELAYS, WEIGHTS)
3535
from spynnaker.pyNN.utilities.utility_calls import check_rng
3636

3737
from .abstract_generate_connector_on_host import (
@@ -96,7 +96,7 @@ def generate_on_machine(self, synapse_info: SynapseInformation) -> bool:
9696
check_rng(synapse_info.delays.rng, "RandomDistribution in delay")
9797
return True
9898

99-
def gen_weights_id(self, weights: Weight_Types) -> int:
99+
def gen_weights_id(self, weights: WEIGHTS) -> int:
100100
"""
101101
Get the id of the weight generator on the machine.
102102
@@ -106,7 +106,7 @@ def gen_weights_id(self, weights: Weight_Types) -> int:
106106
"""
107107
return param_generator_id(weights)
108108

109-
def gen_weights_params(self, weights: Weight_Types) -> NDArray[uint32]:
109+
def gen_weights_params(self, weights: WEIGHTS) -> NDArray[uint32]:
110110
"""
111111
Get the parameters of the weight generator on the machine.
112112
@@ -116,7 +116,7 @@ def gen_weights_params(self, weights: Weight_Types) -> NDArray[uint32]:
116116
"""
117117
return param_generator_params(weights)
118118

119-
def gen_weight_params_size_in_bytes(self, weights: Weight_Types) -> int:
119+
def gen_weight_params_size_in_bytes(self, weights: WEIGHTS) -> int:
120120
"""
121121
The size of the weight parameters in bytes.
122122
@@ -126,7 +126,7 @@ def gen_weight_params_size_in_bytes(self, weights: Weight_Types) -> int:
126126
"""
127127
return param_generator_params_size_in_bytes(weights)
128128

129-
def gen_delays_id(self, delays: Delay_Types) -> int:
129+
def gen_delays_id(self, delays: DELAYS) -> int:
130130
"""
131131
Get the id of the delay generator on the machine.
132132
@@ -136,7 +136,7 @@ def gen_delays_id(self, delays: Delay_Types) -> int:
136136
"""
137137
return param_generator_id(delays)
138138

139-
def gen_delay_params(self, delays: Delay_Types) -> NDArray[uint32]:
139+
def gen_delay_params(self, delays: DELAYS) -> NDArray[uint32]:
140140
"""
141141
Get the parameters of the delay generator on the machine.
142142
@@ -146,7 +146,7 @@ def gen_delay_params(self, delays: Delay_Types) -> NDArray[uint32]:
146146
"""
147147
return param_generator_params(delays)
148148

149-
def gen_delay_params_size_in_bytes(self, delays: Delay_Types) -> int:
149+
def gen_delay_params_size_in_bytes(self, delays: DELAYS) -> int:
150150
"""
151151
The size of the delay parameters in bytes.
152152

spynnaker/pyNN/models/neural_projections/connectors/all_but_me_connector.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
from spinn_front_end_common.utilities.constants import BYTES_PER_WORD
2626
from spinn_front_end_common.interface.ds import DataType
27-
from spynnaker.pyNN.types import Weight_Types
27+
from spynnaker.pyNN.types import WEIGHTS
2828

2929
from .abstract_connector import AbstractConnector
3030
from .abstract_generate_connector_on_machine import (
@@ -168,7 +168,7 @@ def get_weight_maximum(self, synapse_info: SynapseInformation) -> float:
168168
synapse_info)
169169

170170
@overrides(AbstractConnector.get_weight_mean)
171-
def get_weight_mean(self, weights: Weight_Types,
171+
def get_weight_mean(self, weights: WEIGHTS,
172172
synapse_info: SynapseInformation) -> float:
173173
if self.__weights is None:
174174
return AbstractConnector.get_weight_mean(
@@ -177,7 +177,7 @@ def get_weight_mean(self, weights: Weight_Types,
177177
return float(numpy.mean(numpy.abs(self.__weights)))
178178

179179
@overrides(AbstractConnector.get_weight_variance)
180-
def get_weight_variance(self, weights: Weight_Types,
180+
def get_weight_variance(self, weights: WEIGHTS,
181181
synapse_info: SynapseInformation) -> float:
182182
if self.__weights is None:
183183
return AbstractConnector.get_weight_variance(

spynnaker/pyNN/models/neural_projections/connectors/from_list_connector.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@
3333

3434
from spynnaker.pyNN.data import SpynnakerDataView
3535
from spynnaker.pyNN.exceptions import InvalidParameterType
36-
from spynnaker.pyNN.types import Delay_Types, Weight_Delay_Types, Weight_Types
37-
36+
from spynnaker.pyNN.types import DELAYS, WEIGHTS_DELAYS, WEIGHTS
3837
from .abstract_connector import AbstractConnector
3938
from .abstract_generate_connector_on_host import (
4039
AbstractGenerateConnectorOnHost)
@@ -53,7 +52,7 @@
5352
_FIRST_PARAM = 2
5453

5554

56-
def _is_sequential(value: Weight_Delay_Types
55+
def _is_sequential(value: WEIGHTS_DELAYS
5756
) -> TypeGuard[NDArray[numpy.float64]]:
5857
return isinstance(value, numpy.ndarray)
5958

@@ -154,7 +153,7 @@ def get_delay_minimum(self, synapse_info: SynapseInformation) -> float:
154153
return numpy.min(self.__delays)
155154

156155
@overrides(AbstractConnector.get_delay_variance)
157-
def get_delay_variance(self, delays: Delay_Types,
156+
def get_delay_variance(self, delays: DELAYS,
158157
synapse_info: SynapseInformation) -> float:
159158
if self.__delays is None:
160159
if _is_sequential(synapse_info.delays):
@@ -297,7 +296,7 @@ def get_n_connections_to_post_vertex_maximum(
297296
self.__targets.astype(int64, copy=False))))
298297

299298
@overrides(AbstractConnector.get_weight_mean)
300-
def get_weight_mean(self, weights: Weight_Types,
299+
def get_weight_mean(self, weights: WEIGHTS,
301300
synapse_info: SynapseInformation) -> float:
302301
if self.__weights is None:
303302
if _is_sequential(synapse_info.weights):
@@ -318,7 +317,7 @@ def get_weight_maximum(self, synapse_info: SynapseInformation) -> float:
318317
return float(numpy.amax(numpy.abs(self.__weights)))
319318

320319
@overrides(AbstractConnector.get_weight_variance)
321-
def get_weight_variance(self, weights: Weight_Types,
320+
def get_weight_variance(self, weights: WEIGHTS,
322321
synapse_info: SynapseInformation) -> float:
323322
if self.__weights is None:
324323
if _is_sequential(synapse_info.weights):

0 commit comments

Comments
 (0)