Skip to content

Commit e1e2501

Browse files
authored
Merge branch 'master' into less_overrides
2 parents 03553a0 + e444814 commit e1e2501

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")
@@ -119,10 +120,10 @@ def __init__(self, receive_labels: Optional[Iterable[str]],
119120
self.__spif_packet_size = events_per_packet * BYTES_PER_WORD
120121
self.__spif_packet_time_us = time_per_packet
121122
self.__key_to_atom_id_and_label: Dict[int, Tuple[int, int]] = dict()
122-
self.__live_event_callbacks: List[List[Tuple[_EventCB, bool]]] = list()
123-
self.__start_resume_callbacks: Dict[str, List[_StartStopCB]] = dict()
124-
self.__pause_stop_callbacks: Dict[str, List[_StartStopCB]] = dict()
125-
self.__init_callbacks: Dict[str, List[_InitCB]] = dict()
123+
self.__live_event_callbacks: List[List[Tuple[_EVENT, bool]]] = list()
124+
self.__start_resume_callbacks: Dict[str, List[_START_STOP]] = dict()
125+
self.__pause_stop_callbacks: Dict[str, List[_START_STOP]] = dict()
126+
self.__init_callbacks: Dict[str, List[_INIT]] = dict()
126127
if receive_labels is not None:
127128
for label in receive_labels:
128129
self.__live_event_callbacks.append(list())
@@ -145,7 +146,7 @@ def add_receive_label(self, label: str) -> None:
145146
self.__pause_stop_callbacks[label] = list()
146147
self.__init_callbacks[label] = list()
147148

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

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

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

203204
def add_pause_stop_callback(
204-
self, label: str, pause_stop_callback: _StartStopCB) -> None:
205+
self, label: str, pause_stop_callback: _START_STOP) -> None:
205206
"""
206207
Add a callback for the pause and stop state of the simulation.
207208
@@ -268,7 +269,7 @@ def __handle_possible_rerun_state(self) -> None:
268269
self.__receiver_connection = None
269270

270271
def __launch_thread(
271-
self, kind: str, label: str, callback: _StartStopCB) -> None:
272+
self, kind: str, label: str, callback: _START_STOP) -> None:
272273
thread = Thread(target=callback, args=(label, self), name=(
273274
f"{kind} callback thread for live_event_connection "
274275
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

@@ -120,7 +120,7 @@ def set_projection_information(
120120
self.__min_delay = SpynnakerDataView.get_simulation_time_step_ms()
121121

122122
def _get_delay_minimum(
123-
self, delays: Delay_Types, n_connections: int,
123+
self, delays: DELAYS, n_connections: int,
124124
synapse_info: SynapseInformation) -> float:
125125
"""
126126
Get the minimum delay given a float or RandomDistribution.
@@ -146,7 +146,7 @@ def _get_delay_minimum(
146146
raise self.delay_type_exception(delays)
147147

148148
def _get_delay_maximum(
149-
self, delays: Delay_Types, n_connections: int,
149+
self, delays: DELAYS, n_connections: int,
150150
synapse_info: SynapseInformation) -> float:
151151
"""
152152
Get the maximum delay given a float or RandomDistribution.
@@ -193,7 +193,7 @@ def get_delay_minimum(
193193
"""
194194
raise NotImplementedError
195195

196-
def get_delay_variance(self, delays: Delay_Types,
196+
def get_delay_variance(self, delays: DELAYS,
197197
synapse_info: SynapseInformation) -> float:
198198
"""
199199
Get the variance of the delays.
@@ -212,7 +212,7 @@ def get_delay_variance(self, delays: Delay_Types,
212212
raise self.delay_type_exception(delays)
213213

214214
def _get_n_connections_from_pre_vertex_with_delay_maximum(
215-
self, delays: Delay_Types, n_total_connections: int,
215+
self, delays: DELAYS, n_total_connections: int,
216216
n_connections: int, min_delay: float, max_delay: float,
217217
synapse_info: SynapseInformation) -> int:
218218
"""
@@ -292,7 +292,7 @@ def get_n_connections_to_post_vertex_maximum(
292292
"""
293293
raise NotImplementedError
294294

295-
def get_weight_mean(self, weights: Weight_Types,
295+
def get_weight_mean(self, weights: WEIGHTS,
296296
synapse_info: SynapseInformation) -> float:
297297
"""
298298
Get the mean of the weights.
@@ -311,7 +311,7 @@ def get_weight_mean(self, weights: Weight_Types,
311311
raise self.weight_type_exception(synapse_info)
312312

313313
def _get_weight_maximum(
314-
self, weights: Weight_Types, n_connections: int,
314+
self, weights: WEIGHTS, n_connections: int,
315315
synapse_info: SynapseInformation) -> float:
316316
"""
317317
Get the maximum of the weights.
@@ -354,7 +354,7 @@ def get_weight_maximum(self, synapse_info: SynapseInformation) -> float:
354354
"""
355355
raise NotImplementedError
356356

357-
def get_weight_variance(self, weights: Weight_Types,
357+
def get_weight_variance(self, weights: WEIGHTS,
358358
synapse_info: SynapseInformation) -> float:
359359
"""
360360
Get the variance of the weights.
@@ -420,7 +420,7 @@ def _generate_random_values(
420420
return copy_rd.next(n_connections)
421421

422422
def _no_space_exception(
423-
self, values: Weight_Delay_Types,
423+
self, values: WEIGHTS_DELAYS,
424424
synapse_info: SynapseInformation) -> SpynnakerException:
425425
"""
426426
Returns a SpynnakerException about there being no space defined
@@ -436,7 +436,7 @@ def _no_space_exception(
436436
f"{synapse_info.post_population}")
437437

438438
def weight_type_exception(
439-
self, weights: Weight_Types) -> SpynnakerException:
439+
self, weights: WEIGHTS) -> SpynnakerException:
440440
"""
441441
Returns an Exception explaining incorrect weight or delay type
442442
@@ -461,7 +461,7 @@ def weight_type_exception(
461461
else:
462462
return SpynnakerException(f"Unrecognised weight {weights}")
463463

464-
def delay_type_exception(self, delays: Delay_Types) -> SpynnakerException:
464+
def delay_type_exception(self, delays: DELAYS) -> SpynnakerException:
465465
"""
466466
Returns an Exception explaining incorrect delay type
467467
@@ -483,7 +483,7 @@ def delay_type_exception(self, delays: Delay_Types) -> SpynnakerException:
483483
return SpynnakerException(f"Unrecognised delay {delays}")
484484

485485
def _generate_values(
486-
self, values: Weight_Delay_Types, sources: numpy.ndarray,
486+
self, values: WEIGHTS_DELAYS, sources: numpy.ndarray,
487487
targets: numpy.ndarray, n_connections: int, post_slice: Slice,
488488
synapse_info: SynapseInformation,
489489
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)