Skip to content

Commit 5ba974e

Browse files
authored
Merge pull request #1546 from SpiNNakerManchester/mypy
typing of tests
2 parents f23fda5 + a52bb80 commit 5ba974e

95 files changed

Lines changed: 1015 additions & 662 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/python_actions.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ jobs:
3232
coverage-package: spynnaker
3333
flake8-packages: spynnaker unittests spynnaker_integration_tests proxy_integration_tests
3434
pylint-packages: spynnaker
35-
mypy-packages: unittests spynnaker_integration_tests proxy_integration_tests
36-
mypy-full-packages: spynnaker
35+
mypy-packages: spynnaker_integration_tests proxy_integration_tests
36+
mypy-full-packages: spynnaker unittests
3737
cfg-file: spynnaker

mypy.bash

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ man="../SpiNNMan/spinnman"
2525
pacman="../PACMAN/pacman"
2626
spalloc="../spalloc/spalloc_client"
2727
fec="../SpiNNFrontEndCommon/spinn_front_end_common"
28+
test_base="../TestBase/spinnaker_testbase"
2829

29-
mypy --python-version 3.8 $utils $machine $man $pacman $spalloc $fec spynnaker
30+
mypy --python-version 3.8 $utils $machine $man $pacman $spalloc $fec $test_base spynnaker unittests

mypyd.bash

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ man="../SpiNNMan/spinnman"
2525
pacman="../PACMAN/pacman"
2626
spalloc="../spalloc/spalloc_client"
2727
fec="../SpiNNFrontEndCommon/spinn_front_end_common"
28+
test_base="../TestBase/spinnaker_testbase"
2829

29-
mypy --python-version 3.8 --disallow-untyped-defs $utils $machine $man $pacman $spalloc $fec spynnaker
30+
mypy --python-version 3.8 --disallow-untyped-defs $utils $machine $man $pacman $spalloc $fec $test_base spynnaker unittests

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ requires = ["setuptools"]
1717
build-backend = "setuptools.build_meta"
1818

1919
[[tool.mypy.overrides]]
20-
module = ["pyNN.*", "quantities", "neo", "scipy", "scipy.*", "lazyarray"]
20+
module = ["matplotlib", "matplotlib.*", "pyNN.*", "quantities", "neo", "scipy", "scipy.*", "lazyarray"]
2121
ignore_missing_imports = true

spynnaker/pyNN/data/spynnaker_data_writer.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,9 @@ def _set_min_delay(self, min_delay: Optional[Union[int, float]]) -> None:
131131
f'{self.get_simulation_time_step_ms()}')
132132

133133
self.__spy_data._min_delay = min_delay
134+
135+
def _get_id_counter(self) -> int:
136+
"""
137+
Testing method likely to change without notice!
138+
"""
139+
return self.__spy_data._id_counter

spynnaker/pyNN/external_devices_models/push_bot/parameters/push_bot_retina_viewer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from time import sleep
1717
from typing import Any, List
1818

19-
from matplotlib import pyplot # type: ignore[import]
19+
from matplotlib import pyplot
2020
import numpy
2121

2222
from spinn_utilities.log import FormatAdapter

spynnaker/pyNN/models/neuron/connection_holder.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
ConnectionsArray)
2525

2626
_ItemType: TypeAlias = numpy.floating
27-
_Items: TypeAlias = Union[Tuple[NDArray[_ItemType], ...], NDArray[_ItemType]]
27+
_Items: TypeAlias = Union[Tuple[NDArray[_ItemType], ...], NDArray[_ItemType],
28+
Tuple[List[numpy.floating], ...]]
2829

2930

3031
def _is_listable(value: Any) -> TypeGuard[Sequence[Any]]:
@@ -205,7 +206,7 @@ def _get_data_items(self) -> _Items:
205206
connections[order][self.__data_items_to_return[0]]
206207

207208
# Return in a format which can be understood by a FromListConnector
208-
items: List[Any] = []
209+
items: List[List[numpy.floating]] = []
209210
# NB: The types in here are all wrong, but that's
210211
for data_item in data_items:
211212
if _is_listable(data_item):
@@ -242,7 +243,8 @@ def _get_data_items(self) -> _Items:
242243
return self.__data_items
243244

244245
def __getitem__(self, s: int) -> Union[
245-
numpy.floating, NDArray[numpy.floating]]:
246+
numpy.floating, NDArray[numpy.floating],
247+
List[numpy.floating]]:
246248
data = self._get_data_items()
247249
return data[s]
248250

spynnaker/pyNN/models/neuron/population_vertex.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -472,15 +472,14 @@ def get_max_atoms_per_dimension_per_core(self) -> Tuple[int, ...]:
472472
@overrides(PopulationApplicationVertex.
473473
set_max_atoms_per_dimension_per_core)
474474
def set_max_atoms_per_dimension_per_core(
475-
self, new_value: Union[None, int, Tuple[int, ...]]) -> None:
476-
if new_value is not None:
477-
max_atoms = self.__synapse_dynamics.absolute_max_atoms_per_core
478-
if numpy.prod(new_value) > max_atoms:
479-
raise SpynnakerException(
480-
"In the current configuration, the maximum number of"
481-
" neurons for each dimension must be such that the total"
482-
" number of neurons per core is less than or equal to"
483-
f" {max_atoms}")
475+
self, new_value: Union[int, Tuple[int, ...]]) -> None:
476+
max_atoms = self.__synapse_dynamics.absolute_max_atoms_per_core
477+
if numpy.prod(new_value) > max_atoms:
478+
raise SpynnakerException(
479+
"In the current configuration, the maximum number of"
480+
" neurons for each dimension must be such that the total"
481+
" number of neurons per core is less than or equal to"
482+
f" {max_atoms}")
484483
super().set_max_atoms_per_dimension_per_core(new_value)
485484

486485
@overrides(SupportsStructure.set_structure)

spynnaker/pyNN/models/neuron/synapse_dynamics/synapse_dynamics_static.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from spynnaker.pyNN.exceptions import SynapticConfigurationException
2929
from spynnaker.pyNN.models.neuron.synapse_dynamics.types import (
3030
NUMPY_CONNECTORS_DTYPE)
31-
from spynnaker.pyNN.types import Weight_Delay_In_Types as _Weight
31+
from spynnaker.pyNN.types import Weight_Delay_In_Types as _InTypes
3232
from spynnaker.pyNN.utilities.utility_calls import get_n_bits
3333

3434
from .abstract_static_synapse_dynamics import AbstractStaticSynapseDynamics
@@ -58,8 +58,9 @@ class SynapseDynamicsStatic(
5858
"__pad_to_length"]
5959

6060
def __init__(
61-
self, weight: _Weight = StaticSynapse.default_parameters['weight'],
62-
delay: Optional[float] = None,
61+
self, weight: _InTypes = StaticSynapse.default_parameters[
62+
'weight'],
63+
delay: _InTypes = None,
6364
pad_to_length: Optional[int] = None):
6465

6566
"""

spynnaker/pyNN/models/neuron/synapse_io.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from typing import List, Optional, Tuple, Union, TYPE_CHECKING
1717

1818
import numpy
19-
from numpy import floating, integer, uint32
19+
from numpy import integer, uint32
2020
from numpy.typing import NDArray
2121

2222
from pacman.model.graphs.application import ApplicationVertex
@@ -33,6 +33,7 @@
3333
AbstractPlasticSynapseDynamics)
3434
from spynnaker.pyNN.models.neuron.synapse_dynamics.types import (
3535
NUMPY_CONNECTORS_DTYPE, ConnectionsArray)
36+
from spynnaker.pyNN.types import WeightScales
3637

3738
from .master_pop_table import MasterPopTableAsBinarySearch
3839

@@ -217,7 +218,7 @@ def _get_allowed_row_length(
217218
def get_synapses(
218219
connections: ConnectionsArray, synapse_info: SynapseInformation,
219220
n_delay_stages: int, n_synapse_types: int,
220-
weight_scales: NDArray[floating], app_edge: ProjectionApplicationEdge,
221+
weight_scales: WeightScales, app_edge: ProjectionApplicationEdge,
221222
max_row_info: MaxRowInfo, gen_undelayed: bool, gen_delayed: bool,
222223
max_atoms_per_core: int) -> Tuple[_RowData, _RowData]:
223224
"""
@@ -233,8 +234,7 @@ def get_synapses(
233234
The number of delay stages in total to be represented
234235
:param int n_synapse_types:
235236
The number of synapse types in total to be represented
236-
:param list(float) weight_scales:
237-
The scaling of the weights for each synapse type
237+
:param weight_scales: The scaling of the weights for each synapse type
238238
:param ~pacman.model.graphs.application.ApplicationEdge app_edge:
239239
The incoming machine edge that the synapses are on
240240
:param MaxRowInfo max_row_info:
@@ -391,7 +391,7 @@ def _get_row_data(
391391
def convert_to_connections(
392392
synapse_info: SynapseInformation, post_vertex_slice: Slice,
393393
n_pre_atoms: int, max_row_length: int, n_synapse_types: int,
394-
weight_scales: NDArray[floating], data: Union[bytes, NDArray, None],
394+
weight_scales: WeightScales, data: Union[bytes, NDArray, None],
395395
delayed: bool, post_vertex_max_delay_ticks: int,
396396
max_atoms_per_core: int) -> ConnectionsArray:
397397
"""
@@ -407,7 +407,7 @@ def convert_to_connections(
407407
The length of each row in the data
408408
:param int n_synapse_types:
409409
The number of synapse types in total
410-
:param list(float) weight_scales:
410+
:param weight_scales:
411411
The weight scaling of each synapse type
412412
:param bytearray data:
413413
The raw data containing the synapses
@@ -461,7 +461,7 @@ def convert_to_connections(
461461
def read_all_synapses(
462462
data: NDArray[uint32], delayed_data: NDArray[uint32],
463463
synapse_info: SynapseInformation, n_synapse_types: int,
464-
weight_scales: NDArray[floating], post_vertex_slice: Slice,
464+
weight_scales: WeightScales, post_vertex_slice: Slice,
465465
n_pre_atoms: int, post_vertex_max_delay_ticks: int,
466466
max_row_info: MaxRowInfo, max_atoms_per_core: int
467467
) -> ConnectionsArray:
@@ -477,7 +477,7 @@ def read_all_synapses(
477477
The synapse info that generated the synapses
478478
:param int n_synapse_types:
479479
The total number of synapse types available
480-
:param list(float) weight_scales:
480+
:param weight_scales:
481481
A weight scale for each synapse type
482482
:param int n_pre_atoms: The number of atoms in the pre-vertex
483483
:param ~pacman.model.graphs.common.Slice post_vertex_slice:
@@ -638,13 +638,13 @@ def _read_plastic_data(
638638

639639

640640
def _rescale_connections(
641-
connections: ConnectionsArray, weight_scales: NDArray[floating],
641+
connections: ConnectionsArray, weight_scales: WeightScales,
642642
synapse_info: SynapseInformation) -> ConnectionsArray:
643643
"""
644644
Scale the connection data into machine values.
645645
646646
:param ~numpy.ndarray connections: The connections to be rescaled
647-
:param list(float) weight_scales: The weight scale of each synapse type
647+
:param weight_scales: The weight scale of each synapse type
648648
:param SynapseInformation synapse_info:
649649
The synapse information of the connections
650650
"""

0 commit comments

Comments
 (0)