diff --git a/.github/workflows/python_actions.yml b/.github/workflows/python_actions.yml index 031bd003b..a0093e871 100644 --- a/.github/workflows/python_actions.yml +++ b/.github/workflows/python_actions.yml @@ -26,5 +26,6 @@ jobs: coverage-package: pacman flake8-packages: pacman unittests pacman_test_objects pylint-packages: pacman pacman_test_objects - mypy-packages: pacman unittests pacman_test_objects + mypy-full_packages: pacman pacman_test_objects + mypy-packages: unittests secrets: inherit diff --git a/mypy.bash b/mypy.bash index d85d639c2..1d17cc22e 100755 --- a/mypy.bash +++ b/mypy.bash @@ -23,4 +23,4 @@ utils="../SpiNNUtils/spinn_utilities" machine="../SpiNNMachine/spinn_machine" man="../SpiNNMan/spinnman" -mypy --python-version 3.8 $utils $machine $man pacman +mypy --python-version 3.8 $utils $machine $man pacman pacman_test_objects unittests diff --git a/pacman_test_objects/placer_test_support.py b/mypyd.bash old mode 100644 new mode 100755 similarity index 51% rename from pacman_test_objects/placer_test_support.py rename to mypyd.bash index 11e3da9a4..7fb44b1d9 --- a/pacman_test_objects/placer_test_support.py +++ b/mypyd.bash @@ -1,4 +1,6 @@ -# Copyright (c) 2017 The University of Manchester +#!/bin/bash + +# Copyright (c) 2024 The University of Manchester # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -12,16 +14,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -from pacman.model.graphs.common import Slice -from pacman.model.graphs.machine import SimpleMachineVertex -from pacman.model.resources import ConstantSDRAM +# This bash assumes that other repositories are installed in paralled + +# requires the latest mypy +# pip install --upgrade mypy +utils="../SpiNNUtils/spinn_utilities" +machine="../SpiNNMachine/spinn_machine" +man="../SpiNNMan/spinnman" -def get_resourced_machine_vertex(lo_atom, hi_atom, label=None): - """ - A test vertex with sdram set - """ - sdram_requirement = 4000 + 50 * (hi_atom - lo_atom) - sdram = ConstantSDRAM(sdram_requirement) - return SimpleMachineVertex( - sdram, label=label, vertex_slice=Slice(lo_atom, hi_atom)) +mypy --python-version 3.8 --disallow-untyped-defs $utils $machine $man pacman pacman_test_objects diff --git a/pacman/data/pacman_data_view.py b/pacman/data/pacman_data_view.py index fa2a5138f..4ca68d6e9 100644 --- a/pacman/data/pacman_data_view.py +++ b/pacman/data/pacman_data_view.py @@ -139,7 +139,7 @@ class PacmanDataView(MachineDataView): # graph methods @classmethod - def add_vertex(cls, vertex: ApplicationVertex): + def add_vertex(cls, vertex: ApplicationVertex) -> None: """ Adds an Application vertex to the user graph. @@ -164,7 +164,8 @@ def add_vertex(cls, vertex: ApplicationVertex): @classmethod def add_edge( - cls, edge: ApplicationEdge, outgoing_edge_partition_name: str): + cls, edge: ApplicationEdge, + outgoing_edge_partition_name: str) -> None: """ Adds an Application edge to the user graph. @@ -588,7 +589,7 @@ def get_ethernet_monitor_sdram(cls) -> AbstractSDRAM: # n_boards/chips required @classmethod - def has_n_boards_required(cls): + def has_n_boards_required(cls) -> bool: """ Reports if a user has sets the number of boards requested during setup. @@ -599,7 +600,7 @@ def has_n_boards_required(cls): return cls.__pacman_data._n_boards_required is not None @classmethod - def get_n_boards_required(cls): + def get_n_boards_required(cls) -> int: """ Gets the number of boards requested by the user during setup if known. @@ -614,7 +615,7 @@ def get_n_boards_required(cls): return cls.__pacman_data._n_boards_required @classmethod - def get_n_chips_needed(cls): + def get_n_chips_needed(cls) -> int: """ Gets the number of chips needed, if set. @@ -637,7 +638,7 @@ def get_n_chips_needed(cls): raise cls._exception("n_chips_requiredr") @classmethod - def has_n_chips_needed(cls): + def has_n_chips_needed(cls) -> bool: """ Detects if the number of chips needed has been set. @@ -651,7 +652,7 @@ def has_n_chips_needed(cls): return cls.__pacman_data._n_chips_in_graph is not None @classmethod - def get_chips_boards_required_str(cls): + def get_chips_boards_required_str(cls) -> str: """ Gets a String to say what was required :return: diff --git a/pacman/data/pacman_data_writer.py b/pacman/data/pacman_data_writer.py index 1c8ccde24..ed07d5550 100644 --- a/pacman/data/pacman_data_writer.py +++ b/pacman/data/pacman_data_writer.py @@ -65,7 +65,7 @@ def _soft_reset(self) -> None: MachineDataWriter._soft_reset(self) self.__pacman_data._soft_reset() - def set_placements(self, placements: Placements): + def set_placements(self, placements: Placements) -> None: """ Set the placements. @@ -76,7 +76,7 @@ def set_placements(self, placements: Placements): raise TypeError("placements should be a Placements") self.__pacman_data._placements = placements - def set_routing_infos(self, routing_infos: RoutingInfo): + def set_routing_infos(self, routing_infos: RoutingInfo) -> None: """ Set the routing_infos. @@ -87,7 +87,7 @@ def set_routing_infos(self, routing_infos: RoutingInfo): raise TypeError("routing_infos should be a RoutingInfo") self.__pacman_data._routing_infos = routing_infos - def set_tags(self, tags: Tags): + def set_tags(self, tags: Tags) -> None: """ Set the tags. @@ -98,7 +98,7 @@ def set_tags(self, tags: Tags): raise TypeError("tags should be a Tags") self.__pacman_data._tags = tags - def set_uncompressed(self, router_tables: MulticastRoutingTables): + def set_uncompressed(self, router_tables: MulticastRoutingTables) -> None: """ Sets the uncompressed `router_tables` value. @@ -111,7 +111,8 @@ def set_uncompressed(self, router_tables: MulticastRoutingTables): "router_tables should be a MulticastRoutingTables") self.__pacman_data._uncompressed = router_tables - def set_precompressed(self, router_tables: MulticastRoutingTables): + def set_precompressed( + self, router_tables: MulticastRoutingTables) -> None: """ Sets the precompressed `router_tables` value. @@ -124,7 +125,7 @@ def set_precompressed(self, router_tables: MulticastRoutingTables): "router_tables should be a MulticastRoutingTables") self.__pacman_data._precompressed = router_tables - def set_plan_n_timesteps(self, plan_n_timesteps: Optional[int]): + def set_plan_n_timesteps(self, plan_n_timesteps: Optional[int]) -> None: """ Sets the `plan_n_timestep`. Use `None` for run forever. @@ -144,7 +145,7 @@ def set_plan_n_timesteps(self, plan_n_timesteps: Optional[int]): def set_routing_table_by_partition( self, routing_table_by_partition: - MulticastRoutingTableByPartition): + MulticastRoutingTableByPartition) -> None: """ Sets the `_routing_table_by_partition`. @@ -161,7 +162,7 @@ def set_routing_table_by_partition( routing_table_by_partition @classmethod - def add_vertex(cls, vertex: ApplicationVertex): + def add_vertex(cls, vertex: ApplicationVertex) -> None: if cls.__pacman_data._graph is None: raise cls._exception("graph") if not cls.get_requires_mapping(): @@ -171,7 +172,7 @@ def add_vertex(cls, vertex: ApplicationVertex): @classmethod def add_edge(cls, edge: ApplicationEdge, - outgoing_edge_partition_name: str): + outgoing_edge_partition_name: str) -> None: if cls.__pacman_data._graph is None: raise cls._exception("graph") if not cls.get_requires_mapping(): @@ -180,7 +181,7 @@ def add_edge(cls, edge: ApplicationEdge, cls.__pacman_data._graph.add_edge(edge, outgoing_edge_partition_name) def add_sample_monitor_vertex( - self, vertex: MachineVertex, all_chips: bool): + self, vertex: MachineVertex, all_chips: bool) -> None: """ Accepts a simple of the monitor cores to be added. @@ -203,7 +204,8 @@ def add_sample_monitor_vertex( if all_chips: self.__pacman_data._all_monitor_vertices.append(vertex) - def set_n_required(self, n_boards_required, n_chips_required): + def set_n_required(self, n_boards_required: Optional[int], + n_chips_required: Optional[int]) -> None: """ Sets (if not `None`) the number of boards/chips requested by the user. @@ -241,11 +243,9 @@ def set_n_required(self, n_boards_required, n_chips_required): self.__pacman_data._n_boards_required = n_boards_required self.__pacman_data._n_chips_required = n_chips_required - def set_n_chips_in_graph(self, n_chips_in_graph): + def set_n_chips_in_graph(self, n_chips_in_graph: int) -> None: """ Sets the number of chips needed by the graph. - - :param int n_chips_in_graph: """ if not isinstance(n_chips_in_graph, int): raise TypeError("n_chips_in_graph must be an int (or None)") diff --git a/pacman/model/graphs/abstract_edge_partition.py b/pacman/model/graphs/abstract_edge_partition.py index c564842fe..f08f41a94 100644 --- a/pacman/model/graphs/abstract_edge_partition.py +++ b/pacman/model/graphs/abstract_edge_partition.py @@ -52,7 +52,7 @@ def __init__(self, identifier: str, self._allowed_edge_types = allowed_edge_types self._edges: OrderedSet[E] = OrderedSet() - def add_edge(self, edge: E): + def add_edge(self, edge: E) -> None: """ Add an edge to the edge partition. @@ -101,14 +101,14 @@ def n_edges(self) -> int: """ return len(self._edges) - def __repr__(self): + def __repr__(self) -> str: return (f"{self.__class__.__name__}(identifier={self.identifier}" f", n_edges={self.n_edges})") - def __str__(self): + def __str__(self) -> str: return self.__repr__() - def __contains__(self, edge): + def __contains__(self, edge: AbstractEdge) -> bool: """ Check if the edge is contained within this partition. diff --git a/pacman/model/graphs/abstract_multiple_partition.py b/pacman/model/graphs/abstract_multiple_partition.py index 8208a759d..9af7137f3 100644 --- a/pacman/model/graphs/abstract_multiple_partition.py +++ b/pacman/model/graphs/abstract_multiple_partition.py @@ -53,7 +53,7 @@ def __init__( "There were clones in your list of acceptable pre vertices") @overrides(AbstractEdgePartition.add_edge) - def add_edge(self, edge: E): + def add_edge(self, edge: E) -> None: # safety checks if edge.pre_vertex not in self._pre_vertices: raise PacmanValueError( diff --git a/pacman/model/graphs/abstract_single_source_partition.py b/pacman/model/graphs/abstract_single_source_partition.py index bcef6a4fc..7bbb1090a 100644 --- a/pacman/model/graphs/abstract_single_source_partition.py +++ b/pacman/model/graphs/abstract_single_source_partition.py @@ -44,7 +44,7 @@ def __init__( self._pre_vertex = pre_vertex @overrides(AbstractEdgePartition.add_edge) - def add_edge(self, edge: E): + def add_edge(self, edge: E) -> None: super().add_edge(edge) if edge.pre_vertex != self._pre_vertex: raise PacmanConfigurationException( diff --git a/pacman/model/graphs/abstract_vertex.py b/pacman/model/graphs/abstract_vertex.py index c588eb8bd..1689b4a97 100644 --- a/pacman/model/graphs/abstract_vertex.py +++ b/pacman/model/graphs/abstract_vertex.py @@ -48,7 +48,7 @@ def label(self) -> Optional[str]: """ return self._label - def set_label(self, label: str): + def set_label(self, label: str) -> None: """ Changes the label for a vertex *not yet added* to a graph. @@ -90,7 +90,8 @@ def get_fixed_location(self) -> Optional[ChipAndCore]: """ return self._fixed_location - def set_fixed_location(self, x: int, y: int, p: Optional[int] = None): + def set_fixed_location( + self, x: int, y: int, p: Optional[int] = None) -> None: """ Set the location where the vertex must be placed. diff --git a/pacman/model/graphs/application/abstract/abstract_one_app_one_machine_vertex.py b/pacman/model/graphs/application/abstract/abstract_one_app_one_machine_vertex.py index 0e1392985..e163f40e9 100644 --- a/pacman/model/graphs/application/abstract/abstract_one_app_one_machine_vertex.py +++ b/pacman/model/graphs/application/abstract/abstract_one_app_one_machine_vertex.py @@ -40,7 +40,7 @@ def __init__(self, machine_vertex: V, label: Optional[str], super().remember_machine_vertex(machine_vertex) @overrides(ApplicationVertex.remember_machine_vertex) - def remember_machine_vertex(self, machine_vertex: V): + def remember_machine_vertex(self, machine_vertex: V) -> None: assert (machine_vertex == self._machine_vertex) @property diff --git a/pacman/model/graphs/application/application_edge_partition.py b/pacman/model/graphs/application/application_edge_partition.py index 87c410baf..f382100ae 100644 --- a/pacman/model/graphs/application/application_edge_partition.py +++ b/pacman/model/graphs/application/application_edge_partition.py @@ -41,6 +41,6 @@ def __init__(self, identifier: str, pre_vertex: ApplicationVertex): allowed_edge_types=ApplicationEdge) @overrides(AbstractSingleSourcePartition.add_edge) - def add_edge(self, edge: ApplicationEdge): + def add_edge(self, edge: ApplicationEdge) -> None: super().add_edge(edge) edge.post_vertex.add_incoming_edge(edge, self) diff --git a/pacman/model/graphs/application/application_graph.py b/pacman/model/graphs/application/application_graph.py index 3b7c3983a..51a950788 100644 --- a/pacman/model/graphs/application/application_graph.py +++ b/pacman/model/graphs/application/application_graph.py @@ -47,7 +47,7 @@ def __init__(self) -> None: self._unlabelled_vertex_count = 0 self._vertex_by_label: Dict[str, ApplicationVertex] = dict() - def add_vertex(self, vertex: ApplicationVertex): + def add_vertex(self, vertex: ApplicationVertex) -> None: """ Add a vertex to the graph. @@ -131,7 +131,7 @@ def add_edge( partition.add_edge(edge) return partition - def _check_edge(self, edge: ApplicationEdge): + def _check_edge(self, edge: ApplicationEdge) -> None: """ Add an edge to the graph. @@ -172,7 +172,7 @@ def edges(self) -> Sequence[ApplicationEdge]: for edge in partition.edges] def _add_outgoing_edge_partition( - self, edge_partition: ApplicationEdgePartition): + self, edge_partition: ApplicationEdgePartition) -> None: """ Add an edge partition to the graph. diff --git a/pacman/model/graphs/application/application_vertex.py b/pacman/model/graphs/application/application_vertex.py index ba33ea5cc..a2645664b 100644 --- a/pacman/model/graphs/application/application_vertex.py +++ b/pacman/model/graphs/application/application_vertex.py @@ -87,10 +87,10 @@ def __init__( self._max_atoms_per_dimension_per_core: Optional[Tuple[int, ...]] self._set_max_atoms_per_dimension_per_core(max_atoms_per_core) - def __str__(self): - return self.label + def __str__(self) -> str: + return str(self.label) - def __repr__(self): + def __repr__(self) -> str: if self.get_fixed_location(): return (f"ApplicationVertex({self.label}," f" at{self.get_fixed_location()})") @@ -117,7 +117,7 @@ def splitter(self) -> AbstractSplitterCommon[Self]: return s @splitter.setter - def splitter(self, new_value: AbstractSplitterCommon[Self]): + def splitter(self, new_value: AbstractSplitterCommon[Self]) -> None: """ Sets the splitter object. Does not allow repeated settings. @@ -134,7 +134,7 @@ def splitter(self, new_value: AbstractSplitterCommon[Self]): self._splitter = new_value self._splitter.set_governed_app_vertex(self) - def remember_machine_vertex(self, machine_vertex: MV): + def remember_machine_vertex(self, machine_vertex: MV) -> None: """ Adds the machine vertex to the iterable returned by machine_vertices @@ -202,7 +202,8 @@ def machine_vertices(self) -> Collection[MV]: """ return self._machine_vertices - def __check_atoms_per_core(self): + def __check_atoms_per_core(self) -> None: + assert self._max_atoms_per_dimension_per_core is not None if (len(self._max_atoms_per_dimension_per_core) != len(self.atoms_shape)): raise ValueError( @@ -248,7 +249,7 @@ def get_max_atoms_per_dimension_per_core(self) -> Tuple[int, ...]: return self._max_atoms_per_dimension_per_core def _set_max_atoms_per_dimension_per_core( - self, new_value: Optional[Union[int, Tuple[int, ...]]]): + self, new_value: Optional[Union[int, Tuple[int, ...]]]) -> None: """ Set the maximum number of atoms per dimension per core. @@ -273,7 +274,7 @@ def _set_max_atoms_per_dimension_per_core( self._max_atoms_per_dimension_per_core = max_atoms_tuple def set_max_atoms_per_dimension_per_core( - self, new_value: Optional[Union[int, Tuple[int, ...]]]): + self, new_value: Optional[Union[int, Tuple[int, ...]]]) -> None: """ Set the maximum number of atoms per dimension per core. @@ -336,8 +337,8 @@ def get_fixed_key_and_mask( # pylint: disable=unused-argument return None - def add_incoming_edge( - self, edge: ApplicationEdge, partition: ApplicationEdgePartition): + def add_incoming_edge(self, edge: ApplicationEdge, + partition: ApplicationEdgePartition) -> None: """ Add an edge incoming to this vertex. This is ignored by default, but could be used to track incoming edges, and/or report faults. @@ -349,7 +350,8 @@ def add_incoming_edge( ~pacman.model.graphs.application.ApplicationEdgePartition """ - def get_key_ordered_indices(self, indices=None): + def get_key_ordered_indices( + self, indices: Optional[numpy.ndarray] = None) -> numpy.ndarray: """ Get indices of the vertex in the order that atoms appear when the vertex is split into cores as determined by max_atoms_per_core. When @@ -373,7 +375,7 @@ def get_key_ordered_indices(self, indices=None): atoms_per_core = self.get_max_atoms_per_dimension_per_core() remainders = numpy.array(indices) cum_per_core = 1 - cum_cores_per_dim = 1 + cum_cores_per_dim = 1.0 core_index = numpy.zeros(len(indices)) atom_index = numpy.zeros(len(indices)) for n in range(n_dims): @@ -403,7 +405,8 @@ def get_key_ordered_indices(self, indices=None): return ((core_index * self.get_max_atoms_per_core()) + atom_index).astype(numpy.uint32) - def get_raster_ordered_indices(self, indices): + def get_raster_ordered_indices( + self, indices: numpy.ndarray) -> numpy.ndarray: """ Convert indices from key order to raster order. @@ -441,7 +444,7 @@ def get_raster_ordered_indices(self, indices): return global_index.astype(numpy.uint32) - def has_fixed_location(self): + def has_fixed_location(self) -> bool: """ Check if this vertex or any machine vertex has a fixed location. diff --git a/pacman/model/graphs/common/chip_and_core.py b/pacman/model/graphs/common/chip_and_core.py index fb8de3e5e..39e0bc4d2 100644 --- a/pacman/model/graphs/common/chip_and_core.py +++ b/pacman/model/graphs/common/chip_and_core.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -from typing import Optional +from typing import Any, Optional class ChipAndCore(object): @@ -72,12 +72,12 @@ def __repr__(self) -> str: else: return f"X:{self._x},Y:{self._y},P:{self._p}" - def __eq__(self, other) -> bool: + def __eq__(self, other: Any) -> bool: if not isinstance(other, ChipAndCore): return False return (self._x, self._y, self._p) == (other.x, other.y, other.p) - def __ne__(self, other) -> bool: + def __ne__(self, other: Any) -> bool: return not self.__eq__(other) def __hash__(self) -> int: diff --git a/pacman/model/graphs/common/mdslice.py b/pacman/model/graphs/common/mdslice.py index e60c6d3d9..b5c53350b 100644 --- a/pacman/model/graphs/common/mdslice.py +++ b/pacman/model/graphs/common/mdslice.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. from __future__ import annotations -from typing import Tuple, Union +from typing import Any, Tuple, Union import numpy from numpy.typing import NDArray from spinn_utilities.overrides import overrides @@ -119,7 +119,7 @@ def __str__(self) -> str: value += f"({a_slice.start}:{a_slice.stop})" return f"{self.lo_atom}{self._atoms_shape}{value}" - def __eq__(self, other) -> bool: + def __eq__(self, other: Any) -> bool: if not isinstance(other, MDSlice): return False if not super().__eq__(other): diff --git a/pacman/model/graphs/common/slice.py b/pacman/model/graphs/common/slice.py index 70bad8acb..34e4e5896 100644 --- a/pacman/model/graphs/common/slice.py +++ b/pacman/model/graphs/common/slice.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. from __future__ import annotations -from typing import Tuple, Union +from typing import Any, Tuple, Union import numpy from numpy.typing import NDArray from pacman.exceptions import PacmanValueError, PacmanTypeError @@ -170,10 +170,10 @@ def get_raster_ids(self) -> NDArray[numpy.integer]: """ return numpy.array(range(self._lo_atom, self._lo_atom + self._n_atoms)) - def __str__(self): + def __str__(self) -> str: return (f"({self.lo_atom}:{self.hi_atom})") - def __eq__(self, other): + def __eq__(self, other: Any) -> bool: if not isinstance(other, Slice): return False if self._lo_atom != other.lo_atom: @@ -185,7 +185,7 @@ def __eq__(self, other): return False return self._n_atoms == other.n_atoms - def __hash__(self): + def __hash__(self) -> int: # Slices will generally only be hashed in sets for the same Vertex return self._lo_atom diff --git a/pacman/model/graphs/machine/abstract_sdram_partition.py b/pacman/model/graphs/machine/abstract_sdram_partition.py index fc346a861..9ac21c94f 100644 --- a/pacman/model/graphs/machine/abstract_sdram_partition.py +++ b/pacman/model/graphs/machine/abstract_sdram_partition.py @@ -39,7 +39,7 @@ def sdram_base_address(self) -> int: raise NotImplementedError @sdram_base_address.setter - def sdram_base_address(self, new_value: int): + def sdram_base_address(self, new_value: int) -> None: raise NotImplementedError @abstractmethod diff --git a/pacman/model/graphs/machine/constant_sdram_machine_partition.py b/pacman/model/graphs/machine/constant_sdram_machine_partition.py index 553b99437..7c0b0718c 100644 --- a/pacman/model/graphs/machine/constant_sdram_machine_partition.py +++ b/pacman/model/graphs/machine/constant_sdram_machine_partition.py @@ -52,7 +52,7 @@ def __init__(self, identifier: str, pre_vertex: V): self._sdram_base_address: Optional[int] = None @overrides(AbstractSingleSourcePartition.add_edge) - def add_edge(self, edge: E): + def add_edge(self, edge: E) -> None: if self._sdram_size is None: self._sdram_size = edge.sdram_size elif self._sdram_size != edge.sdram_size: @@ -82,7 +82,7 @@ def sdram_base_address(self) -> int: return self._sdram_base_address @sdram_base_address.setter - def sdram_base_address(self, new_value: int): + def sdram_base_address(self, new_value: int) -> None: if len(self.edges) == 0: raise PartitionMissingEdgesException(self.__missing_edge_msg()) self._sdram_base_address = new_value diff --git a/pacman/model/graphs/machine/destination_segmented_sdram_machine_partition.py b/pacman/model/graphs/machine/destination_segmented_sdram_machine_partition.py index b17ec00bb..7a8345709 100644 --- a/pacman/model/graphs/machine/destination_segmented_sdram_machine_partition.py +++ b/pacman/model/graphs/machine/destination_segmented_sdram_machine_partition.py @@ -51,7 +51,7 @@ def sdram_base_address(self) -> int: return self._sdram_base_address @sdram_base_address.setter - def sdram_base_address(self, new_value: int): + def sdram_base_address(self, new_value: int) -> None: if len(self.edges) == 0: raise PartitionMissingEdgesException( f"Partition {self} has no edges") @@ -61,7 +61,7 @@ def sdram_base_address(self, new_value: int): new_value += edge.sdram_size @overrides(AbstractSingleSourcePartition.add_edge) - def add_edge(self, edge: SDRAMMachineEdge): + def add_edge(self, edge: SDRAMMachineEdge) -> None: if self._sdram_base_address is not None: raise PacmanConfigurationException( "Illegal attempt to add an edge after sdram_base_address set") diff --git a/pacman/model/graphs/machine/machine_edge.py b/pacman/model/graphs/machine/machine_edge.py index 44aa83b02..d6901520a 100644 --- a/pacman/model/graphs/machine/machine_edge.py +++ b/pacman/model/graphs/machine/machine_edge.py @@ -74,7 +74,7 @@ def post_vertex(self) -> MachineVertex: """ return self._post_vertex - def __repr__(self): + def __repr__(self) -> str: return ( f"MachineEdge(pre_vertex={self._pre_vertex}, " f"post_vertex={self._post_vertex}, label={self.label})") diff --git a/pacman/model/graphs/machine/machine_sdram_edge.py b/pacman/model/graphs/machine/machine_sdram_edge.py index bde536315..0468e9338 100644 --- a/pacman/model/graphs/machine/machine_sdram_edge.py +++ b/pacman/model/graphs/machine/machine_sdram_edge.py @@ -59,7 +59,7 @@ def sdram_base_address(self) -> Optional[int]: return self._sdram_base_address @sdram_base_address.setter - def sdram_base_address(self, new_value: int): + def sdram_base_address(self, new_value: int) -> None: """ Sets the start address without verification @@ -67,10 +67,10 @@ def sdram_base_address(self, new_value: int): """ self._sdram_base_address = new_value - def __repr__(self): + def __repr__(self) -> str: return (f"SDRAMMachineEdge(pre_vertex={self.pre_vertex}," f" post_vertex={self.post_vertex}, label={self.label}," f" sdram_size={self.sdram_size})") - def __str__(self): + def __str__(self) -> str: return self.__repr__() diff --git a/pacman/model/graphs/machine/machine_vertex.py b/pacman/model/graphs/machine/machine_vertex.py index 18a1aff41..1bed32413 100644 --- a/pacman/model/graphs/machine/machine_vertex.py +++ b/pacman/model/graphs/machine/machine_vertex.py @@ -109,18 +109,18 @@ def index(self) -> int: return self._index if self._index is not None else 0 @index.setter - def index(self, value: int): + def index(self, value: int) -> None: """ The index into the collection of machine vertices for an application vertex. """ self._index = value - def __str__(self): + def __str__(self) -> str: _l = self.label return self.__repr__() if _l is None else _l - def __repr__(self): + def __repr__(self) -> str: if self.get_fixed_location(): return (f"MachineVertex({self.label}, " f"at{self.get_fixed_location()})") diff --git a/pacman/model/graphs/machine/multicast_edge_partition.py b/pacman/model/graphs/machine/multicast_edge_partition.py index 4ea5e7d80..98909344c 100644 --- a/pacman/model/graphs/machine/multicast_edge_partition.py +++ b/pacman/model/graphs/machine/multicast_edge_partition.py @@ -36,6 +36,6 @@ def __init__(self, pre_vertex: MachineVertex, identifier: str): pre_vertex=pre_vertex, identifier=identifier, allowed_edge_types=MachineEdge) - def __repr__(self): + def __repr__(self) -> str: return (f"MulticastEdgePartition(pre_vertex={self.pre_vertex}," f" identifier={self.identifier})") diff --git a/pacman/model/graphs/machine/simple_machine_vertex.py b/pacman/model/graphs/machine/simple_machine_vertex.py index 04c2efc74..828bdcf2a 100644 --- a/pacman/model/graphs/machine/simple_machine_vertex.py +++ b/pacman/model/graphs/machine/simple_machine_vertex.py @@ -16,6 +16,8 @@ from spinn_utilities.overrides import overrides +from pacman.model.graphs.common import Slice +from pacman.model.graphs.application import ApplicationVertex from pacman.model.resources import AbstractSDRAM from pacman.model.resources import IPtagResource from pacman.model.resources import ReverseIPtagResource @@ -33,11 +35,12 @@ class SimpleMachineVertex(MachineVertex): """ __slots__ = ("_iptags", "_reverse_iptags", "_sdram") - def __init__(self, sdram, label=None, - app_vertex=None, vertex_slice=None, - iptags: Optional[Iterable[IPtagResource]] = None, - reverse_iptags: Optional[Iterable[ReverseIPtagResource]] - = None): + def __init__( + self, sdram: Optional[AbstractSDRAM], label: Optional[str] = None, + app_vertex: Optional[ApplicationVertex] = None, + vertex_slice: Optional[Slice] = None, + iptags: Optional[Iterable[IPtagResource]] = None, + reverse_iptags: Optional[Iterable[ReverseIPtagResource]] = None): super().__init__( label=label, app_vertex=app_vertex, vertex_slice=vertex_slice) self._sdram = sdram @@ -51,6 +54,7 @@ def __init__(self, sdram, label=None, @property @overrides(MachineVertex.sdram_required) def sdram_required(self) -> AbstractSDRAM: + assert self._sdram is not None return self._sdram @property diff --git a/pacman/model/graphs/machine/source_segmented_sdram_machine_partition.py b/pacman/model/graphs/machine/source_segmented_sdram_machine_partition.py index d80a7dfe0..caaee6ca2 100644 --- a/pacman/model/graphs/machine/source_segmented_sdram_machine_partition.py +++ b/pacman/model/graphs/machine/source_segmented_sdram_machine_partition.py @@ -58,7 +58,7 @@ def sdram_base_address(self) -> int: return self._sdram_base_address @sdram_base_address.setter - def sdram_base_address(self, new_value: int): + def sdram_base_address(self, new_value: int) -> None: if len(self.pre_vertices) != len(self.edges): raise PartitionMissingEdgesException( f"There are {len(self.pre_vertices)} pre vertices " @@ -73,7 +73,7 @@ def sdram_base_address(self, new_value: int): new_value += edge.sdram_size @overrides(AbstractMultiplePartition.add_edge) - def add_edge(self, edge: SDRAMMachineEdge): + def add_edge(self, edge: SDRAMMachineEdge) -> None: # check if len(self._destinations): if edge.post_vertex not in self._destinations: diff --git a/pacman/model/partitioner_splitters/abstract_splitter_common.py b/pacman/model/partitioner_splitters/abstract_splitter_common.py index e6ec84f44..1374c09ee 100644 --- a/pacman/model/partitioner_splitters/abstract_splitter_common.py +++ b/pacman/model/partitioner_splitters/abstract_splitter_common.py @@ -39,14 +39,17 @@ class AbstractSplitterCommon(Generic[V], metaclass=AbstractBase): def __init__(self) -> None: self.__governed_app_vertex: Optional[V] = None - def __str__(self): + def __str__(self) -> str: try: + if self.__governed_app_vertex is None: + return ( + f"{type(self).__name__} without an app vertex") return ( f"{type(self).__name__} on {self.__governed_app_vertex.label}") except AttributeError: return f"{type(self).__name__} has no governed_app_vertex" - def __repr__(self): + def __repr__(self) -> str: return self.__str__() @property @@ -63,7 +66,7 @@ def governed_app_vertex(self) -> V: "This splitter has no governing app vertex set") return self.__governed_app_vertex - def set_governed_app_vertex(self, app_vertex: V): + def set_governed_app_vertex(self, app_vertex: V) -> None: """ Sets a application vertex to be governed by this splitter object. Once set it can't be reset. @@ -83,7 +86,7 @@ def set_governed_app_vertex(self, app_vertex: V): app_vertex.splitter = self @abstractmethod - def create_machine_vertices(self, chip_counter: ChipCounter): + def create_machine_vertices(self, chip_counter: ChipCounter) -> None: """ Method for specific splitter objects to override. diff --git a/pacman/model/partitioner_splitters/splitter_external_device.py b/pacman/model/partitioner_splitters/splitter_external_device.py index 72f029eaa..9bcd287a6 100644 --- a/pacman/model/partitioner_splitters/splitter_external_device.py +++ b/pacman/model/partitioner_splitters/splitter_external_device.py @@ -58,7 +58,7 @@ def __init__(self) -> None: self.__outgoing_slice: Optional[Slice] = None @overrides(AbstractSplitterCommon.set_governed_app_vertex) - def set_governed_app_vertex(self, app_vertex: _Allowed): + def set_governed_app_vertex(self, app_vertex: _Allowed) -> None: super().set_governed_app_vertex(app_vertex) self.__incoming_vertices = list() @@ -122,7 +122,7 @@ def set_governed_app_vertex(self, app_vertex: _Allowed): f"Unknown vertex type to splitter: {app_vertex}") @overrides(AbstractSplitterCommon.create_machine_vertices) - def create_machine_vertices(self, chip_counter: ChipCounter): + def create_machine_vertices(self, chip_counter: ChipCounter) -> None: app_vertex = self.governed_app_vertex for vertex in self.__incoming_vertices: # machine_graph.add_vertex(vertex) diff --git a/pacman/model/partitioner_splitters/splitter_fixed_legacy.py b/pacman/model/partitioner_splitters/splitter_fixed_legacy.py index da2d0cc83..929767f46 100644 --- a/pacman/model/partitioner_splitters/splitter_fixed_legacy.py +++ b/pacman/model/partitioner_splitters/splitter_fixed_legacy.py @@ -48,7 +48,7 @@ def __init__(self) -> None: self.__slices: Optional[List[Slice]] = None @overrides(AbstractSplitterCommon.set_governed_app_vertex) - def set_governed_app_vertex(self, app_vertex: V): + def set_governed_app_vertex(self, app_vertex: V) -> None: if not isinstance(app_vertex, LegacyPartitionerAPI): raise PacmanConfigurationException( f"{self} is not a LegacyPartitionerAPI") @@ -83,7 +83,7 @@ def __fixed_slices(self) -> List[Slice]: return self.__slices @overrides(AbstractSplitterCommon.create_machine_vertices) - def create_machine_vertices(self, chip_counter: ChipCounter): + def create_machine_vertices(self, chip_counter: ChipCounter) -> None: app_vertex = self.governed_app_vertex # The mypy needs to know the vertex implements LegacyPartitionerAPI # We know is does because we checked when setting diff --git a/pacman/model/partitioner_splitters/splitter_one_app_one_machine.py b/pacman/model/partitioner_splitters/splitter_one_app_one_machine.py index 7daec388e..8e89987bc 100644 --- a/pacman/model/partitioner_splitters/splitter_one_app_one_machine.py +++ b/pacman/model/partitioner_splitters/splitter_one_app_one_machine.py @@ -37,7 +37,7 @@ class SplitterOneAppOneMachine(AbstractSplitterCommon[AV], Generic[AV, MV]): __slots__ = () @overrides(AbstractSplitterCommon.set_governed_app_vertex) - def set_governed_app_vertex(self, app_vertex: AV): + def set_governed_app_vertex(self, app_vertex: AV) -> None: if not isinstance(app_vertex, AbstractOneAppOneMachineVertex): raise PacmanConfigurationException( f"The vertex {app_vertex.label} cannot be supported by the " @@ -46,7 +46,7 @@ def set_governed_app_vertex(self, app_vertex: AV): super().set_governed_app_vertex(app_vertex) @overrides(AbstractSplitterCommon.create_machine_vertices) - def create_machine_vertices(self, chip_counter: ChipCounter): + def create_machine_vertices(self, chip_counter: ChipCounter) -> None: chip_counter.add_core( self.governed_app_vertex.machine_vertex.sdram_required) diff --git a/pacman/model/partitioner_splitters/splitter_one_to_one_legacy.py b/pacman/model/partitioner_splitters/splitter_one_to_one_legacy.py index be7499ef5..21fe3748a 100644 --- a/pacman/model/partitioner_splitters/splitter_one_to_one_legacy.py +++ b/pacman/model/partitioner_splitters/splitter_one_to_one_legacy.py @@ -48,7 +48,7 @@ def __init__(self) -> None: self._sdram: Optional[AbstractSDRAM] = None @overrides(AbstractSplitterCommon.set_governed_app_vertex) - def set_governed_app_vertex(self, app_vertex: ApplicationVertex): + def set_governed_app_vertex(self, app_vertex: ApplicationVertex) -> None: if not isinstance(app_vertex, LegacyPartitionerAPI): raise PacmanConfigurationException( f"{self} is not a LegacyPartitionerAPI") @@ -63,7 +63,7 @@ def set_governed_app_vertex(self, app_vertex: ApplicationVertex): self.governed_app_vertex.remember_machine_vertex(self._machine_vertex) @overrides(AbstractSplitterCommon.create_machine_vertices) - def create_machine_vertices(self, chip_counter: ChipCounter): + def create_machine_vertices(self, chip_counter: ChipCounter) -> None: assert self._sdram is not None chip_counter.add_core(self._sdram) diff --git a/pacman/model/placements/placements.py b/pacman/model/placements/placements.py index 6ec12418f..25fa3c6e2 100644 --- a/pacman/model/placements/placements.py +++ b/pacman/model/placements/placements.py @@ -61,7 +61,7 @@ def n_placements(self) -> int: """ return len(self._machine_vertices) - def add_placements(self, placements: Iterable[Placement]): + def add_placements(self, placements: Iterable[Placement]) -> None: """ Add some placements. @@ -70,7 +70,7 @@ def add_placements(self, placements: Iterable[Placement]): for placement in placements: self.add_placement(placement) - def add_placement(self, placement: Placement): + def add_placement(self, placement: Placement) -> None: """ Add a placement. diff --git a/pacman/model/resources/abstract_sdram.py b/pacman/model/resources/abstract_sdram.py index 06db3ad3c..07b896bd8 100644 --- a/pacman/model/resources/abstract_sdram.py +++ b/pacman/model/resources/abstract_sdram.py @@ -68,7 +68,7 @@ def __eq__(self, other: Any) -> bool: @abstractmethod def report(self, timesteps: Optional[int], indent: str = "", - preamble: str = "", target: Optional[TextIO] = None): + preamble: str = "", target: Optional[TextIO] = None) -> None: """ Writes a description of this SDRAM to the target. @@ -91,5 +91,5 @@ def short_str(self) -> str: """ raise NotImplementedError - def __str__(self): + def __str__(self) -> str: return f"SDRAM:{self.short_str}" diff --git a/pacman/model/resources/constant_sdram.py b/pacman/model/resources/constant_sdram.py index b05006f6f..2c122e2d4 100644 --- a/pacman/model/resources/constant_sdram.py +++ b/pacman/model/resources/constant_sdram.py @@ -64,7 +64,7 @@ def __add__(self, other: AbstractSDRAM) -> AbstractSDRAM: @overrides(AbstractSDRAM.report) def report(self, timesteps: Optional[int], indent: str = "", - preamble: str = "", target: Optional[TextIO] = None): + preamble: str = "", target: Optional[TextIO] = None) -> None: print(indent, preamble, f"Constant {self._sdram} bytes", file=target) @property diff --git a/pacman/model/resources/iptag_resource.py b/pacman/model/resources/iptag_resource.py index 4e6ea3206..f698a8a94 100644 --- a/pacman/model/resources/iptag_resource.py +++ b/pacman/model/resources/iptag_resource.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -from typing import Optional +from typing import Any, Optional class IPtagResource(object): @@ -102,23 +102,13 @@ def tag(self) -> Optional[int]: """ return self._tag - def get_value(self): - """ - :return: The description of the IP tag. - :rtype: list(str, int, bool, int, str) - """ - return [ - self._ip_address, self._port, self._strip_sdp, self._tag, - self._traffic_identifier - ] - - def __repr__(self): + def __repr__(self) -> str: return ( f"IPTagResource(ip_address={self._ip_address}, port={self._port}, " f"strip_sdp={self._strip_sdp}, tag={self._tag}, " f"traffic_identifier={self._traffic_identifier})") - def __eq__(self, other): + def __eq__(self, other: Any) -> bool: """ For unit tests *only* so __hash__ and __eq__ pairing not done! """ @@ -128,10 +118,10 @@ def __eq__(self, other): self._tag == other._tag and self._traffic_identifier == other._traffic_identifier) - def __hash__(self): + def __hash__(self) -> int: return hash(( self._ip_address, self._port, self._strip_sdp, self._tag, self._traffic_identifier)) - def __ne__(self, other): + def __ne__(self, other: Any) -> bool: return not self.__eq__(other) diff --git a/pacman/model/resources/multi_region_sdram.py b/pacman/model/resources/multi_region_sdram.py index 89a022412..1724b9436 100644 --- a/pacman/model/resources/multi_region_sdram.py +++ b/pacman/model/resources/multi_region_sdram.py @@ -57,7 +57,7 @@ def __init__(self) -> None: self._total: AbstractSDRAM = ConstantSDRAM(0) @property - def regions(self): + def regions(self) -> dict[_RegionKey, AbstractSDRAM]: """ The map from region identifiers to the amount of SDRAM required. @@ -66,16 +66,13 @@ def regions(self): return self.__regions def add_cost(self, region: _RegionKey, fixed_sdram: _Value, - per_timestep_sdram: _Value = 0): + per_timestep_sdram: _Value = 0) -> None: """ Adds the cost for the specified region. :param region: Key to identify the region - :type region: int or str or enum :param fixed_sdram: The fixed cost for this region. - :type fixed_sdram: int or numpy.integer :param per_timestep_sdram: The variable cost for this region is any - :type per_timestep_sdram: int or numpy.integer """ if per_timestep_sdram: self.nest(region, VariableSDRAM( @@ -83,7 +80,7 @@ def add_cost(self, region: _RegionKey, fixed_sdram: _Value, else: self.nest(region, ConstantSDRAM(_ceil(fixed_sdram))) - def nest(self, region: _RegionKey, other: AbstractSDRAM): + def nest(self, region: _RegionKey, other: AbstractSDRAM) -> None: """ Combines the other SDRAM cost, in a nested fashion. @@ -111,7 +108,7 @@ def nest(self, region: _RegionKey, other: AbstractSDRAM): else: self.__regions[region] = other - def merge(self, other: MultiRegionSDRAM): + def merge(self, other: MultiRegionSDRAM) -> None: """ Combines the other SDRAM costs keeping the region mappings. @@ -130,7 +127,7 @@ def merge(self, other: MultiRegionSDRAM): @overrides(AbstractSDRAM.report) def report(self, timesteps: Optional[int], indent: str = "", - preamble: str = "", target: Optional[TextIO] = None): + preamble: str = "", target: Optional[TextIO] = None) -> None: self._total.report(timesteps, indent, preamble, target) for region in self.__regions: self.__regions[region].report( diff --git a/pacman/model/resources/reverse_iptag_resource.py b/pacman/model/resources/reverse_iptag_resource.py index 0c4e2cba0..f67313026 100644 --- a/pacman/model/resources/reverse_iptag_resource.py +++ b/pacman/model/resources/reverse_iptag_resource.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -from typing import Optional +from typing import Any, Optional class ReverseIPtagResource(object): @@ -74,26 +74,19 @@ def tag(self) -> Optional[int]: """ return self._tag - def get_value(self): - """ - :return: The description of the reverse IP tag. - :rtype: list(int, int, int) - """ - return [self._port, self._sdp_port, self._tag] - - def __repr__(self): + def __repr__(self) -> str: return (f"ReverseIPTagResource(port={self._port}, " f"sdp_port={self._sdp_port}, tag={self._tag})") - def __eq__(self, other): + def __eq__(self, other: Any) -> bool: if not isinstance(other, ReverseIPtagResource): return False return (self._port == other._port and self._sdp_port == other._sdp_port and self._tag == other._tag) - def __hash__(self): + def __hash__(self) -> int: return hash((self._port, self._sdp_port, self._tag)) - def __ne__(self, other): + def __ne__(self, other: Any) -> bool: return not self.__eq__(other) diff --git a/pacman/model/resources/shared_sdram.py b/pacman/model/resources/shared_sdram.py index fb5d56ea6..bbf522ea8 100644 --- a/pacman/model/resources/shared_sdram.py +++ b/pacman/model/resources/shared_sdram.py @@ -115,7 +115,7 @@ def __add__(self, other: AbstractSDRAM) -> AbstractSDRAM: @overrides(AbstractSDRAM.report) def report(self, timesteps: Optional[int], indent: str = "", - preamble: str = "", target: Optional[TextIO] = None): + preamble: str = "", target: Optional[TextIO] = None) -> None: self._per_core.report(timesteps, indent, preamble, target) for key, sdram in self._shared.items(): sdram.report(timesteps, indent+" ", key+":", target) diff --git a/pacman/model/resources/variable_sdram.py b/pacman/model/resources/variable_sdram.py index ed874e3da..a4e676076 100644 --- a/pacman/model/resources/variable_sdram.py +++ b/pacman/model/resources/variable_sdram.py @@ -101,7 +101,7 @@ def __add__(self, other: AbstractSDRAM) -> AbstractSDRAM: @overrides(AbstractSDRAM.report) def report(self, timesteps: Optional[int], indent: str = "", - preamble: str = "", target: Optional[TextIO] = None): + preamble: str = "", target: Optional[TextIO] = None) -> None: print(indent, preamble, f"Fixed {self._fixed_sdram} bytes " f"Per_timestep {self._per_timestep_sdram} bytes " diff --git a/pacman/model/routing_info/routing_info.py b/pacman/model/routing_info/routing_info.py index 22b4179df..a81819061 100644 --- a/pacman/model/routing_info/routing_info.py +++ b/pacman/model/routing_info/routing_info.py @@ -34,7 +34,7 @@ def __init__(self) -> None: self._info: Dict[AbstractVertex, Dict[str, VertexRoutingInfo]] = defaultdict(dict) - def add_routing_info(self, info: VertexRoutingInfo): + def add_routing_info(self, info: VertexRoutingInfo) -> None: """ Add a routing information item. @@ -157,7 +157,7 @@ def has_info_from( def check_info_from( self, vertex: AbstractVertex, - allowed_partition_ids: Set[str]): + allowed_partition_ids: Set[str]) -> None: """ Check that the partition ids for a vertex are in the allowed set. diff --git a/pacman/model/routing_info/vertex_routing_info.py b/pacman/model/routing_info/vertex_routing_info.py index cfd25171f..d5c580dae 100644 --- a/pacman/model/routing_info/vertex_routing_info.py +++ b/pacman/model/routing_info/vertex_routing_info.py @@ -69,7 +69,7 @@ def get_keys(self, n_keys: Optional[int] = None) -> numpy.ndarray: return key_array @property - def key_and_mask(self): + def key_and_mask(self) -> BaseKeyAndMask: """ The only key and mask. diff --git a/pacman/model/routing_table_by_partition/multicast_routing_table_by_partition.py b/pacman/model/routing_table_by_partition/multicast_routing_table_by_partition.py index c49e6044e..f95e4784d 100644 --- a/pacman/model/routing_table_by_partition/multicast_routing_table_by_partition.py +++ b/pacman/model/routing_table_by_partition/multicast_routing_table_by_partition.py @@ -42,7 +42,7 @@ def __init__(self) -> None: def add_path_entry( self, entry: RoutingEntry, router_x: int, router_y: int, - source_vertex: AbstractVertex, partition_id: str): + source_vertex: AbstractVertex, partition_id: str) -> None: """ Adds a multicast routing path entry. diff --git a/pacman/model/routing_tables/abstract_multicast_routing_table.py b/pacman/model/routing_tables/abstract_multicast_routing_table.py index 4708a0f53..6227c63ca 100644 --- a/pacman/model/routing_tables/abstract_multicast_routing_table.py +++ b/pacman/model/routing_tables/abstract_multicast_routing_table.py @@ -67,7 +67,7 @@ def multicast_routing_entries(self) -> Collection[MulticastRoutingEntry]: @abstractmethod def add_multicast_routing_entry( - self, multicast_routing_entry: MulticastRoutingEntry): + self, multicast_routing_entry: MulticastRoutingEntry) -> None: """ Adds a routing entry to this table. diff --git a/pacman/model/routing_tables/compressed_multicast_routing_table.py b/pacman/model/routing_tables/compressed_multicast_routing_table.py index 8660478c7..61a5f8d84 100644 --- a/pacman/model/routing_tables/compressed_multicast_routing_table.py +++ b/pacman/model/routing_tables/compressed_multicast_routing_table.py @@ -60,7 +60,7 @@ def __init__( @overrides(AbstractMulticastRoutingTable.add_multicast_routing_entry) def add_multicast_routing_entry( - self, multicast_routing_entry: MulticastRoutingEntry): + self, multicast_routing_entry: MulticastRoutingEntry) -> None: self._multicast_routing_entries.append(multicast_routing_entry) # update default routed counter if required diff --git a/pacman/model/routing_tables/multicast_routing_tables.py b/pacman/model/routing_tables/multicast_routing_tables.py index 38bdb1453..2645d8f95 100644 --- a/pacman/model/routing_tables/multicast_routing_tables.py +++ b/pacman/model/routing_tables/multicast_routing_tables.py @@ -56,7 +56,8 @@ def __init__(self, for routing_table in routing_tables: self.add_routing_table(routing_table) - def add_routing_table(self, routing_table: AbstractMulticastRoutingTable): + def add_routing_table( + self, routing_table: AbstractMulticastRoutingTable) -> None: """ Add a routing table. diff --git a/pacman/model/routing_tables/uncompressed_multicast_routing_table.py b/pacman/model/routing_tables/uncompressed_multicast_routing_table.py index 219dffd53..84113d46b 100644 --- a/pacman/model/routing_tables/uncompressed_multicast_routing_table.py +++ b/pacman/model/routing_tables/uncompressed_multicast_routing_table.py @@ -70,7 +70,7 @@ def __init__( @overrides(AbstractMulticastRoutingTable.add_multicast_routing_entry) def add_multicast_routing_entry( - self, multicast_routing_entry: MulticastRoutingEntry): + self, multicast_routing_entry: MulticastRoutingEntry) -> None: routing_entry_key = multicast_routing_entry.key mask = multicast_routing_entry.mask diff --git a/pacman/model/tags/tags.py b/pacman/model/tags/tags.py index 577fdb3f8..012da646e 100644 --- a/pacman/model/tags/tags.py +++ b/pacman/model/tags/tags.py @@ -57,7 +57,7 @@ def __init__(self) -> None: # Set of ports already assigned on a board self._ports_assigned: Set[Tuple[str, int]] = set() - def add_ip_tag(self, ip_tag: IPTag, vertex: MachineVertex): + def add_ip_tag(self, ip_tag: IPTag, vertex: MachineVertex) -> None: """ Add an IP tag. @@ -102,7 +102,7 @@ def add_ip_tag(self, ip_tag: IPTag, vertex: MachineVertex): existing_tag.port = ip_tag.port def add_reverse_ip_tag( - self, reverse_ip_tag: ReverseIPTag, vertex: MachineVertex): + self, reverse_ip_tag: ReverseIPTag, vertex: MachineVertex) -> None: """ Add a reverse IP tag. diff --git a/pacman/operations/fixed_route_router/fixed_route_router.py b/pacman/operations/fixed_route_router/fixed_route_router.py index c21a9c96d..015f5d828 100644 --- a/pacman/operations/fixed_route_router/fixed_route_router.py +++ b/pacman/operations/fixed_route_router/fixed_route_router.py @@ -77,7 +77,7 @@ def build_fixed_routes(self) -> Dict[Tuple[int, int], RoutingEntry]: self._route_board(ethernet_chip) return self._fixed_route_tables - def _route_board(self, ethernet_chip: Chip): + def _route_board(self, ethernet_chip: Chip) -> None: """ Handles this board through the quick routing process, based on a predefined routing table. @@ -126,7 +126,7 @@ def _route_board(self, ethernet_chip: Chip): def __add_fixed_route_entry(self, key: Tuple[int, int], link_ids: List[int], - processor_ids: List[int]): + processor_ids: List[int]) -> None: """ :param tuple(int,int) key: :param list(int) link_ids: diff --git a/pacman/operations/multi_cast_router_check_functionality/valid_routes_checker.py b/pacman/operations/multi_cast_router_check_functionality/valid_routes_checker.py index 9c59fc8fe..a9930cda7 100644 --- a/pacman/operations/multi_cast_router_check_functionality/valid_routes_checker.py +++ b/pacman/operations/multi_cast_router_check_functionality/valid_routes_checker.py @@ -58,7 +58,7 @@ class _Failure(NamedTuple): source_mask: int -def validate_routes(routing_tables: MulticastRoutingTables): +def validate_routes(routing_tables: MulticastRoutingTables) -> None: """ Go through the app partitions and check that the routing entries within the routing tables support reach the correction destinations @@ -130,7 +130,7 @@ def validate_routes(routing_tables: MulticastRoutingTables): def _search_route( source_placement: Placement, dest_placements: Iterable[PlacementTuple], key_and_mask: BaseKeyAndMask, routing_tables: MulticastRoutingTables, - n_atoms: int): + n_atoms: int) -> None: """ Locate if the routing tables work for the source to desks as defined. @@ -215,7 +215,7 @@ def _start_trace_via_routing_tables( source_placement: Placement, key_and_mask: BaseKeyAndMask, reached_placements: Set[PlacementTuple], routing_tables: MulticastRoutingTables, n_atoms: int, - failed_to_cover_all_keys_routers: List[_Failure]): + failed_to_cover_all_keys_routers: List[_Failure]) -> None: """ Start the trace, by using the source placement's router and tracing from the route. @@ -274,7 +274,7 @@ def _recursive_trace_to_destinations( chip_x: int, chip_y: int, key_and_mask: BaseKeyAndMask, visited_routers: Set[Chip], reached_placements: Set[PlacementTuple], routing_tables: MulticastRoutingTables, n_atoms: int, - failed_to_cover_all_keys_routers: List[_Failure]): + failed_to_cover_all_keys_routers: List[_Failure]) -> None: """ Recursively search though routing tables until no more entries are registered with this key. @@ -294,8 +294,6 @@ def _recursive_trace_to_destinations( :param set(PlacementTuple) reached_placements: the placements reached during the trace :param MulticastRoutingTables routing_tables: - :param bool is_continuous: - whether the keys and atoms mapping is continuous :param int n_atoms: the number of atoms going through this path :param list(_Failure) failed_to_cover_all_keys_routers: list of failed routers for all keys @@ -346,7 +344,7 @@ def _recursive_trace_to_destinations( _is_dest(processor_values, current_router, reached_placements) -def _check_visited_routers(chip: Chip, visited_routers: Set[Chip]): +def _check_visited_routers(chip: Chip, visited_routers: Set[Chip]) -> None: """ Check if the trace has visited this router already. @@ -364,7 +362,7 @@ def _check_visited_routers(chip: Chip, visited_routers: Set[Chip]): def _is_dest(processor_ids: Iterable[int], current_router: AbstractMulticastRoutingTable, - reached_placements: Set[PlacementTuple]): + reached_placements: Set[PlacementTuple]) -> None: """ Collect processors to be removed. diff --git a/pacman/operations/placer_algorithms/application_placer.py b/pacman/operations/placer_algorithms/application_placer.py index cbad547a3..5bf269b82 100644 --- a/pacman/operations/placer_algorithms/application_placer.py +++ b/pacman/operations/placer_algorithms/application_placer.py @@ -14,7 +14,7 @@ from __future__ import annotations import logging import os -from typing import Dict, List, Optional, Tuple, Sequence, Set +from typing import Dict, Iterator, List, Optional, Tuple, Sequence, Set from spinn_utilities.config_holder import get_config_bool from spinn_utilities.log import FormatAdapter @@ -176,7 +176,7 @@ def do_placements(self, system_placements: Placements) -> Placements: return self.__placements - def _place_vertex(self, app_vertex: ApplicationVertex): + def _place_vertex(self, app_vertex: ApplicationVertex) -> None: """ Place the next application vertex @@ -367,7 +367,7 @@ def _place_error(self, system_placements: Placements, f" {exception}." f" Report written to {report_file}.") - def _place_fixed_vertex(self, app_vertex: ApplicationVertex): + def _place_fixed_vertex(self, app_vertex: ApplicationVertex) -> None: """ Place all vertices for this Application Vertex @@ -383,7 +383,7 @@ def _place_fixed_vertex(self, app_vertex: ApplicationVertex): vertices_to_place = self._filter_vertices(vertices) self._do_fixed_location(vertices_to_place) - def _do_fixed_location(self, vertices: list[MachineVertex]): + def _do_fixed_location(self, vertices: list[MachineVertex]) -> None: """ Do fixed placing for one group. @@ -435,11 +435,10 @@ def _do_fixed_location(self, vertices: list[MachineVertex]): raise PacmanConfigurationException( f"No more cores available on {x}, {y}: {on_chip}") - def _chip_order(self): + def _chip_order(self) -> Iterator[Chip]: """ Iterate the Chips in a guaranteed order - :rtype: iterable(Chip) """ for x in range(self.__machine.width): for y in range(self.__machine.height): @@ -514,12 +513,12 @@ def _space_on_chip( return True - def _check_could_fit(self, n_cores: int, sdram: AbstractSDRAM): + def _check_could_fit(self, n_cores: int, sdram: AbstractSDRAM) -> None: """ Checks that the cores/SDRAM would fit on a empty perfect Chip :param int n_cores: number of cores needs - :param int plan_sdram: minimum amount of SDRAM needed + :param sdram: minimum amount of SDRAM needed :raises PacmanTooBigToPlace: If the requirements are too big for any chip """ @@ -617,7 +616,8 @@ def _pop_start_chip(self) -> Chip: f"and {len(self.__starts_tried)} tried" f"{PacmanDataView.get_chips_boards_required_str()}") - def _get_next_neighbour(self, n_cores: int, sdram: AbstractSDRAM): + def _get_next_neighbour( + self, n_cores: int, sdram: AbstractSDRAM) -> Optional[Chip]: """ Gets the next neighbour Chip @@ -668,7 +668,7 @@ def _get_next_chip_with_space( else: return self._get_next_neighbour(n_cores, sdram) - def _add_neighbours(self, chip: Chip): + def _add_neighbours(self, chip: Chip) -> None: """ Adds the neighbours for this Chip to be used as the next chips. diff --git a/pacman/operations/placer_algorithms/draw_placements.py b/pacman/operations/placer_algorithms/draw_placements.py index f27681a06..754bfc568 100644 --- a/pacman/operations/placer_algorithms/draw_placements.py +++ b/pacman/operations/placer_algorithms/draw_placements.py @@ -41,7 +41,7 @@ def _next_colour() -> Colour: def draw_placements( placements: Placements, system_placements: Placements, - filename: str = "placements_error.png"): + filename: str = "placements_error.png") -> None: """ Draw the placements as a PNG in the specified file. diff --git a/pacman/operations/router_algorithms/application_router.py b/pacman/operations/router_algorithms/application_router.py index 5805bf240..7cacff92f 100644 --- a/pacman/operations/router_algorithms/application_router.py +++ b/pacman/operations/router_algorithms/application_router.py @@ -14,7 +14,7 @@ from collections import deque, defaultdict from typing import ( - Deque, Dict, Iterable, List, Optional, Set, Tuple, Union) + Deque, Dict, Iterable, Iterator, List, Optional, Set, Tuple, Union) from typing_extensions import TypeAlias from spinn_utilities.progress_bar import ProgressBar from spinn_utilities.typing.coords import XY @@ -48,7 +48,7 @@ def __init__(self) -> None: _AnyVertex, Tuple[List[int], List[int]]] = defaultdict( lambda: (list(), list())) - def ensure_source(self, source_vertex: _AnyVertex): + def ensure_source(self, source_vertex: _AnyVertex) -> None: """ Ensure that a source exists, even if it targets nothing. @@ -60,7 +60,7 @@ def ensure_source(self, source_vertex: _AnyVertex): def add_sources_for_target( self, core: _OptInt, link: _OptInt, - source_vertices: Iterable[_AnyVertex], partition_id: str): + source_vertices: Iterable[_AnyVertex], partition_id: str) -> None: """ Add a set of vertices that target a given core or link. @@ -85,7 +85,7 @@ def add_sources_for_target( def add_machine_sources_for_target( self, core: _OptInt, link: _OptInt, - source_vertices: Iterable[_AnyVertex], partition_id: str): + source_vertices: Iterable[_AnyVertex], partition_id: str) -> None: """ Add a set of machine vertices that target a given core or link. @@ -121,7 +121,7 @@ def __is_m_vertex( for vtx in vertex.splitter.get_out_going_vertices(partition_id)) def __replace_app_vertex( - self, vertex: ApplicationVertex, partition_id: str): + self, vertex: ApplicationVertex, partition_id: str) -> None: """ :param ApplicationVertex vertex: :param str partition_id: @@ -134,7 +134,7 @@ def __replace_app_vertex( def __add_m_vertices( self, vertex: ApplicationVertex, partition_id: str, - core: _OptInt, link: _OptInt): + core: _OptInt, link: _OptInt) -> None: """ :param ApplicationVertex vertex: :param str partition_id: @@ -144,11 +144,12 @@ def __add_m_vertices( for vtx in vertex.splitter.get_out_going_vertices(partition_id): self.__add_source(vtx, core, link) - def __add_source(self, source: _AnyVertex, core: _OptInt, link: _OptInt): + def __add_source( + self, source: _AnyVertex, core: _OptInt, link: _OptInt) -> None: """ - :param AbstractVertex source: - :param int core: - :param int link: + :param source: + :param core: + :param link: """ tgt = self.__targets_by_source[source] if core is not None: @@ -261,7 +262,9 @@ def route_application_graph() -> MulticastRoutingTableByPartition: return routing_tables -def _get_filtered_internal_partitions(vertex, identifier): +def _get_filtered_internal_partitions( + vertex: ApplicationVertex, + identifier: str) -> Iterator[MulticastEdgePartition]: for partition in vertex.splitter.get_internal_multicast_partitions(): if partition.identifier == identifier: yield partition @@ -274,7 +277,7 @@ def _route_source_to_target( source_edge_xys: Set[XY], target: ApplicationVertex, targets: Dict[XY, _Targets], partition: AbstractEdgePartition, - routes: Dict[XY, RoutingTree]): + routes: Dict[XY, RoutingTree]) -> None: """ Route from a source to a single application vertex target that is not the same as the source. @@ -350,7 +353,7 @@ def _route_single_source_to_target( machine: Machine, source_edge_xys: Set[XY], source_edge_xy: XY, source_mappings: Dict[XY, List[_MappedSrc]], target_edge_xy: XY, target_xys: Set[XY], real_target_xys: Set[XY], - routes: Dict[XY, RoutingTree]): + routes: Dict[XY, RoutingTree]) -> None: """ Route from a single source connection point to all targets from the target edge chip. @@ -387,23 +390,21 @@ def _route_single_source_to_target( def _route_multiple_source_to_target( machine: Machine, source_edge_xys: Set[XY], target_edge_xy: XY, target_xys: Set[XY], real_target_xys: Set[XY], - routes: Dict[XY, RoutingTree], overlaps: Set[XY]): + routes: Dict[XY, RoutingTree], overlaps: Set[XY]) -> None: """ Route from multiple source connection points to all target chips. - :param Machine machine: The machine to route on - :param set(tuple(int,int)) source_edge_xys: + :param machine: The machine to route on + :param source_edge_xys: Set of chips that routes are currently going outward from the source (updated here) - :param tuple(int,int) target_edge_xy: + :param target_edge_xy: The x and y coordinate of the actual target edge chip to route to - :param list(tuple(int,int)) target_xys: The chips in the target - :param set(tuple(int,int)) real_target_xys: + :param target_xys: The chips in the target + :param real_target_xys: The chips in the target that something in the source actually targets - :param dict(tuple(int,int), RoutingTree) routes: - The routes already made and to add to (updated here) - :param set(tuple(int,int)) overlaps: - Chips which overlap between source and target + :param routes: The routes already made and to add to (updated here) + :param overlaps: Chips which overlap between source and target """ # Deal with the overlaps first by finding the set of all things that can # be reached in the target from each of them, without hitting any other @@ -436,7 +437,7 @@ def _route_multiple_source_to_target( def _route_source_to_source( source: ApplicationVertex, partition: AbstractEdgePartition, - targets: Dict[XY, _Targets], self_xys: Set[XY]): + targets: Dict[XY, _Targets], self_xys: Set[XY]) -> None: """ Routes the source to itself. @@ -458,7 +459,7 @@ def _route_source_to_source( def _route_internal( internal_partitions: Iterable[MulticastEdgePartition], - targets: Dict[XY, _Targets], self_xys: Set[XY]): + targets: Dict[XY, _Targets], self_xys: Set[XY]) -> None: """ Route internal_partitions multicast edges. @@ -484,7 +485,7 @@ def _make_source_to_target_routes( source_mappings: Dict[XY, List[_MappedSrc]], targets: Dict[XY, _Targets], routing_tables: MulticastRoutingTableByPartition, - routes: Dict[XY, RoutingTree]): + routes: Dict[XY, RoutingTree]) -> None: """ Convert the routes from source to targets into routing table entries. @@ -522,24 +523,20 @@ def _make_source_to_source_routes( source_mappings: Dict[XY, List[_MappedSrc]], machine: Machine, partition: AbstractEdgePartition, routing_tables: MulticastRoutingTableByPartition, - targets: Dict[XY, _Targets]): + targets: Dict[XY, _Targets]) -> None: """ Convert the routes from the source vertices themselves when the source is self-connected. - :param list(tuple(int,int)) all_source_xys: All source chips - :param set(tuple(int,int)) source_edge_xys: + :param all_source_xys: All source chips + :param source_edge_xys: Set of chips that routes are going outward from the source :param self_xys: The actual chips that are targeted in the source :param source_mappings: The sources mapped to their routes - :type source_mappings: dict(tuple(int, int), - list(tuple(MachineVertex, int, None) or - tuple(MachineVertex, None, int))) :param Machine machine: The machine to route on - :param AbstractEdgePartition partition: The partition to route - :param MulticastRoutingTableByPartition routing_tables: The tables to write - :param dict(tuple(int,int),_Targets) targets: - The target end-points of the routes + :param partition: The partition to route + :param routing_tables: The tables to write + :param targets: The target end-points of the routes """ for xy in source_mappings: source_routes: Dict[XY, RoutingTree] = dict() @@ -558,21 +555,18 @@ def _make_source_to_source_edge_routes( all_source_xys: Set[XY], source_edge_xys: Iterable[XY], source_mappings: Dict[XY, List[_MappedSrc]], machine: Machine, partition: AbstractEdgePartition, - routing_tables: MulticastRoutingTableByPartition): + routing_tables: MulticastRoutingTableByPartition) -> None: """ Convert the routes from the source vertices to the edge vertices when the source is not self-connected. - :param list(tuple(int,int)) all_source_xys: All source chips - :param set(tuple(int,int)) source_edge_xys: + :param all_source_xys: All source chips + :param source_edge_xys: Set of chips that routes are going outward from the source :param source_mappings: The sources mapped to their routes - :type source_mappings: dict(tuple(int, int), - list(tuple(MachineVertex, int, None) or - tuple(MachineVertex, None, int))) - :param Machine machine: The machine to route on - :param AbstractEdgePartition partition: The partition to route - :param MulticastRoutingTableByPartition routing_tables: The tables to write + :param machine: The machine to route on + :param partition: The partition to route + :param routing_tables: The tables to write """ for xy in source_mappings: source_routes: Dict[XY, RoutingTree] = dict() @@ -648,11 +642,12 @@ def _get_outgoing_mapping( def _route_to_xys( first_xy: XY, all_xys: Set[XY], machine: Machine, - routes: Dict[XY, RoutingTree], targets: Iterable[XY], label: str): + routes: Dict[XY, RoutingTree], targets: Iterable[XY], + label: str) -> None: """ - :param tuple(int, int) first_xy: - :param list(tuple(int, int)) all_xys: - :param ~spinn_machine.Machine machine: + :param first_xy: + :param all_xys: + :param machine: :param routes: :param targets: :param str label: @@ -868,7 +863,7 @@ def _path_without_loops(start_xy: XY, nodes: List[_Node]) -> List[_Node]: return nodes -def _is_ok(xy: XY, node: _Node, machine: Machine): +def _is_ok(xy: XY, node: _Node, machine: Machine) -> bool: """ :param tuple(int, int) xy: :param tuple(int,tuple(int, int)) node: @@ -924,7 +919,7 @@ def _convert_a_route( first_incoming_processor: _OptInt, first_incoming_link: _OptInt, first_route: RoutingTree, targets: Dict[XY, _Targets], use_source_for_targets: bool = False, - ensure_all_source: bool = False): + ensure_all_source: bool = False) -> None: """ Convert the algorithm specific partition_route back to SpiNNaker and adds it to the routing_tables. @@ -1020,7 +1015,7 @@ def _add_routing_entry( first_route: RoutingTree, routing_tables: MulticastRoutingTableByPartition, entry: RoutingEntry, - x: int, y: int, source: _AnyVertex, partition_id: str): + x: int, y: int, source: _AnyVertex, partition_id: str) -> None: try: routing_tables.add_path_entry(entry, x, y, source, partition_id) except Exception as e: @@ -1029,7 +1024,7 @@ def _add_routing_entry( raise e -def _print_path(first_route: RoutingTree): +def _print_path(first_route: RoutingTree) -> None: to_process: List[Tuple[str, _OptInt, RoutingTree]] = [ ("", None, first_route)] last_is_leaf = False diff --git a/pacman/operations/router_compressors/pair_compressor.py b/pacman/operations/router_compressors/pair_compressor.py index a9c463a94..c2dfda503 100644 --- a/pacman/operations/router_compressors/pair_compressor.py +++ b/pacman/operations/router_compressors/pair_compressor.py @@ -24,7 +24,7 @@ def pair_compressor( ordered: bool = True, accept_overflow: bool = False, - verify: bool = False, c_sort=False): + verify: bool = False, c_sort: bool = False) -> MulticastRoutingTables: """ :param bool accept_overflow: A flag which should only be used in testing to stop raising an @@ -42,7 +42,7 @@ def pair_compressor( return compressed -def verify_lengths(compressed: MulticastRoutingTables): +def verify_lengths(compressed: MulticastRoutingTables) -> None: """ :param MulticastRoutingTables compressed: :raises PacmanElementAllocationException: @@ -203,7 +203,7 @@ def _compare_entries( return self._compare_routes(route_a_entry.spinnaker_route, route_b_entry.spinnaker_route) - def _compare_routes(self, route_a: int, route_b: int): + def _compare_routes(self, route_a: int, route_b: int) -> int: """ Compares two routes for sorting based on the frequency of each route. @@ -229,7 +229,8 @@ def _compare_routes(self, route_a: int, route_b: int): return -1 raise PacmanElementAllocationException("Sorting error") - def _three_way_partition_table(self, low: int, high: int): + def _three_way_partition_table( + self, low: int, high: int) -> Tuple[int, int]: """ Partitions the entries between low and high into three parts @@ -260,7 +261,7 @@ def _three_way_partition_table(self, low: int, high: int): check += 1 return low, check - def _quicksort_table(self, low: int, high: int): + def _quicksort_table(self, low: int, high: int) -> None: """ Sorts the entries in place based on frequency of their route @@ -272,7 +273,7 @@ def _quicksort_table(self, low: int, high: int): self._quicksort_table(low, left - 1) self._quicksort_table(right, high) - def _swap_routes(self, index_a: int, index_b: int): + def _swap_routes(self, index_a: int, index_b: int) -> None: """ Helper function to swap *both* the routes and routes frequency tables @@ -312,7 +313,7 @@ def _three_way_partition_routes( check += 1 return low, check - def _quicksort_routes(self, low: int, high: int): + def _quicksort_routes(self, low: int, high: int) -> None: """ Sorts the routes in place based on frequency. @@ -359,7 +360,7 @@ def _find_merge(self, left: int, index: int) -> bool: spinnaker_route=self._all_entries[left].spinnaker_route)) return True - def _compress_by_route(self, left: int, right: int): + def _compress_by_route(self, left: int, right: int) -> None: """ Compresses the entries between left and right. @@ -389,7 +390,7 @@ def _compress_by_route(self, left: int, right: int): # self._all_entries[left] = None self._write_index += 1 - def _update_frequency(self, entry: MulticastRoutingEntry): + def _update_frequency(self, entry: MulticastRoutingEntry) -> None: """ :param ~spinn_machine.MulticastRoutingEntry entry: """ diff --git a/pacman/operations/router_compressors/ranged_compressor.py b/pacman/operations/router_compressors/ranged_compressor.py index 0171f290c..db3df699f 100644 --- a/pacman/operations/router_compressors/ranged_compressor.py +++ b/pacman/operations/router_compressors/ranged_compressor.py @@ -157,7 +157,7 @@ def _get_endpoint(self, index: int) -> int: # return the key plus the mask flipping ones and zeros return (entry.key | ~entry.mask) & 0xFFFFFFFF - def _merge_range(self, first: int, last: int): + def _merge_range(self, first: int, last: int) -> None: while True: # With a range of 1 just use the existing if first == last: diff --git a/pacman/operations/router_compressors/routing_compression_checker.py b/pacman/operations/router_compressors/routing_compression_checker.py index cf3afd530..dbe92a740 100644 --- a/pacman/operations/router_compressors/routing_compression_checker.py +++ b/pacman/operations/router_compressors/routing_compression_checker.py @@ -113,7 +113,7 @@ def compare_route( o_route: MulticastRoutingEntry, compressed_dict: Dict[str, MulticastRoutingEntry], o_code: Optional[str] = None, start: int = 0, - f: Optional[TextIO] = None): + f: Optional[TextIO] = None) -> None: """ :param ~spinn_machine.MulticastRoutingEntry o_route: the original route :param dict(str, ~spinn_machine.MulticastRoutingEntry) compressed_dict: @@ -159,7 +159,7 @@ def compare_route( def compare_tables( original: AbstractMulticastRoutingTable, - compressed: AbstractMulticastRoutingTable): + compressed: AbstractMulticastRoutingTable) -> None: """ Compares the two tables without generating any output. diff --git a/pacman/operations/routing_table_generators/basic_routing_table_generator.py b/pacman/operations/routing_table_generators/basic_routing_table_generator.py index cf135da1c..8fa0bcda9 100644 --- a/pacman/operations/routing_table_generators/basic_routing_table_generator.py +++ b/pacman/operations/routing_table_generators/basic_routing_table_generator.py @@ -48,7 +48,7 @@ def basic_routing_table_generator() -> MulticastRoutingTables: def __create_routing_table( x: int, y: int, partitions_in_table: Dict[ Tuple[AbstractVertex, str], RoutingEntry], - routing_infos: RoutingInfo): + routing_infos: RoutingInfo) -> UnCompressedMulticastRoutingTable: """ :param int x: :param int y: @@ -57,7 +57,6 @@ def __create_routing_table( dict(((ApplicationVertex or MachineVertex), str), RoutingEntry) :param RoutingInfo routing_infos: - :rtype: MulticastRoutingTable """ table = UnCompressedMulticastRoutingTable(x, y) sources_by_key_mask: Dict[BaseKeyAndMask, diff --git a/pacman/operations/routing_table_generators/merged_routing_table_generator.py b/pacman/operations/routing_table_generators/merged_routing_table_generator.py index 4b2362b52..4fb1a992a 100644 --- a/pacman/operations/routing_table_generators/merged_routing_table_generator.py +++ b/pacman/operations/routing_table_generators/merged_routing_table_generator.py @@ -25,6 +25,58 @@ from pacman.model.graphs.machine.machine_vertex import MachineVertex from pacman.model.routing_info.base_key_and_mask import BaseKeyAndMask +#: :meta private: +E = TypeVar("E") + + +class _IteratorWithNext(Generic[E]): + """ + An iterator wrapper which allows peek + """ + + def __init__(self, iterable: Iterable[E]): + """ + :param iterable: iterable to be wrapped + """ + self.__iterator = iter(iterable) + try: + self.__next: Optional[E] = next(self.__iterator) + self.__has_next = True + except StopIteration: + self.__next = None + self.__has_next = False + + def peek(self) -> Optional[E]: + """ + The Element if any that would be returned by a pop call + """ + return self.__next + + @property + def has_next(self) -> bool: + """ + True if there is another element for Peek or Pop to return + """ + return self.__has_next + + def pop(self) -> E: + """ + The next element available. + + :raises: StopIteration if there is not more element available + """ + if not self.__has_next: + raise StopIteration + nxt = self.__next + assert nxt is not None + try: + self.__next = next(self.__iterator) + self.__has_next = True + except StopIteration: + self.__next = None + self.__has_next = False + return nxt + def merged_routing_table_generator() -> MulticastRoutingTables: """ @@ -109,6 +161,7 @@ def __create_routing_table( while __match(iterator, vertex, part_id, r_info, entry, routing_info, app_r_info): (vertex, part_id), entry = iterator.pop() + assert isinstance(vertex, MachineVertex) r_info = routing_info.get_info_from( vertex, part_id) if r_info is not None: @@ -123,13 +176,19 @@ def __create_routing_table( def __match( - iterator, vertex, part_id, r_info, entry, routing_info, - app_r_info) -> bool: + iterator: _IteratorWithNext[ + Tuple[Tuple[AbstractVertex, str], RoutingEntry]], + vertex: MachineVertex, + part_id: str, r_info: MachineVertexRoutingInfo, entry: RoutingEntry, + routing_info: RoutingInfo, + app_r_info: AppVertexRoutingInfo) -> bool: if not iterator.has_next: return False if r_info.mask != app_r_info.machine_mask: return False - (next_vertex, next_part_id), next_entry = iterator.peek() + peeked = iterator.peek() + assert peeked is not None + (next_vertex, next_part_id), next_entry = peeked if isinstance(next_vertex, ApplicationVertex): return False if part_id != next_part_id: @@ -138,9 +197,11 @@ def __match( return False next_r_info = routing_info.get_info_from( next_vertex, next_part_id) + assert isinstance(next_r_info, MachineVertexRoutingInfo) if next_r_info.index != r_info.index + 1: return False app_src = vertex.app_vertex + assert isinstance(next_vertex, MachineVertex) next_app_src = next_vertex.app_vertex return (next_app_src == app_src and entry.spinnaker_route == next_entry.spinnaker_route) @@ -171,56 +232,3 @@ def __merged_keys_and_masks( yield MulticastRoutingEntry(r_info.key, r_info.mask, entry) else: yield from app_r_info.merge_machine_entries(entries) - - -#: :meta private: -E = TypeVar("E") - - -class _IteratorWithNext(Generic[E]): - """ - An iterator wrapper which allows peek - """ - - def __init__(self, iterable: Iterable[E]): - """ - :param iterable: iterable to be wrapped - """ - self.__iterator = iter(iterable) - try: - self.__next: Optional[E] = next(self.__iterator) - self.__has_next = True - except StopIteration: - self.__next = None - self.__has_next = False - - def peek(self) -> Optional[E]: - """ - The Element if any that would be returned by a pop call - """ - return self.__next - - @property - def has_next(self) -> bool: - """ - True if there is another element for Peek or Pop to return - """ - return self.__has_next - - def pop(self) -> E: - """ - The next element available. - - :raises: StopIteration if there is not more element available - """ - if not self.__has_next: - raise StopIteration - nxt = self.__next - assert nxt is not None - try: - self.__next = next(self.__iterator) - self.__has_next = True - except StopIteration: - self.__next = None - self.__has_next = False - return nxt diff --git a/pacman/utilities/algorithm_utilities/routing_tree.py b/pacman/utilities/algorithm_utilities/routing_tree.py index b6e32ad15..3a47a099c 100644 --- a/pacman/utilities/algorithm_utilities/routing_tree.py +++ b/pacman/utilities/algorithm_utilities/routing_tree.py @@ -109,7 +109,8 @@ def children(self) -> Iterable[ yield from self._children def append_child( - self, child: Tuple[int, Union[RoutingTree, MachineVertex]]): + self, child: Tuple[int, Union[RoutingTree, MachineVertex]] + ) -> None: """ :param child: :type child: tuple(int, RoutingTree or MachineVertex) @@ -117,7 +118,8 @@ def append_child( self._children.append(child) def remove_child( - self, child: Tuple[int, Union[RoutingTree, MachineVertex]]): + self, child: Tuple[int, Union[RoutingTree, MachineVertex]] + ) -> None: """ :param child: :type child: tuple(int, RoutingTree or MachineVertex) diff --git a/pacman/utilities/utility_objs/chip_counter.py b/pacman/utilities/utility_objs/chip_counter.py index 73f87371a..1b85978d9 100644 --- a/pacman/utilities/utility_objs/chip_counter.py +++ b/pacman/utilities/utility_objs/chip_counter.py @@ -40,7 +40,7 @@ class ChipCounter(object): # The number of chips used, including the current one "__n_chips") - def __init__(self): + def __init__(self) -> None: version = PacmanDataView.get_machine_version() self.__n_cores_per_chip = ( version.max_cores_per_chip - version.n_scamp_cores - @@ -53,7 +53,7 @@ def __init__(self): self.__sdram_free = 0 self.__n_chips = 0 - def add_core(self, resources: AbstractSDRAM): + def add_core(self, resources: AbstractSDRAM) -> None: """ Adds a core (or if needed a Chip) to the count diff --git a/pacman_test_objects/__init__.py b/pacman_test_objects/__init__.py index 7ab64f0d6..8b25a257b 100644 --- a/pacman_test_objects/__init__.py +++ b/pacman_test_objects/__init__.py @@ -13,12 +13,10 @@ # limitations under the License. from .non_legacy_app_vertex import NonLegacyApplicationVertex -from .placer_test_support import get_resourced_machine_vertex from .simple_test_edge import SimpleTestEdge from .simple_test_vertex import SimpleTestVertex __all__ = [ - "get_resourced_machine_vertex", "NonLegacyApplicationVertex", "SimpleTestEdge", "SimpleTestVertex"] diff --git a/pacman_test_objects/non_legacy_app_vertex.py b/pacman_test_objects/non_legacy_app_vertex.py index 48ae71730..2d71bfe9b 100644 --- a/pacman_test_objects/non_legacy_app_vertex.py +++ b/pacman_test_objects/non_legacy_app_vertex.py @@ -18,9 +18,9 @@ class NonLegacyApplicationVertex(ApplicationVertex): """ Test vertex """ - def __init__(self, label="test"): + def __init__(self, label: str = "test"): super().__init__(label=label) @property - def n_atoms(self): + def n_atoms(self) -> int: return 256 diff --git a/pacman_test_objects/simple_test_edge.py b/pacman_test_objects/simple_test_edge.py index a6f82920c..269ee64a6 100644 --- a/pacman_test_objects/simple_test_edge.py +++ b/pacman_test_objects/simple_test_edge.py @@ -12,7 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -from pacman.model.graphs.application import ApplicationEdge +from typing import Optional +from pacman.model.graphs.application import ( + ApplicationEdge, ApplicationVertex) class SimpleTestEdge(ApplicationEdge): @@ -20,5 +22,6 @@ class SimpleTestEdge(ApplicationEdge): test class for creating edges """ - def __init__(self, pre_vertex, post_vertex, label=None): + def __init__(self, pre_vertex: ApplicationVertex, + post_vertex: ApplicationVertex, label: Optional[str] = None): super().__init__(pre_vertex, post_vertex, label=label) diff --git a/pacman_test_objects/simple_test_vertex.py b/pacman_test_objects/simple_test_vertex.py index e096d19b6..70d161c99 100644 --- a/pacman_test_objects/simple_test_vertex.py +++ b/pacman_test_objects/simple_test_vertex.py @@ -15,12 +15,17 @@ """ test vertex used in many unit tests """ from typing import Optional + +from typing_extensions import Self + from spinn_utilities.overrides import overrides + from pacman.model.partitioner_interfaces.legacy_partitioner_api import ( LegacyPartitionerAPI) from pacman.model.graphs.application import ApplicationVertex from pacman.model.graphs.common import Slice from pacman.model.graphs.machine import SimpleMachineVertex +from pacman.model.partitioner_splitters import AbstractSplitterCommon from pacman.model.resources import AbstractSDRAM, ConstantSDRAM @@ -30,8 +35,10 @@ class SimpleTestVertex(ApplicationVertex, LegacyPartitionerAPI): """ _model_based_max_atoms_per_core = None - def __init__(self, n_atoms, label="testVertex", max_atoms_per_core=256, - fixed_sdram_value=None, splitter=None): + def __init__(self, n_atoms: int, label: str = "testVertex", + max_atoms_per_core: int = 256, + fixed_sdram_value: Optional[int] = None, + splitter: Optional[AbstractSplitterCommon[Self]] = None): super().__init__( label=label, max_atoms_per_core=max_atoms_per_core, splitter=splitter) @@ -43,7 +50,7 @@ def __init__(self, n_atoms, label="testVertex", max_atoms_per_core=256, def get_sdram_used_by_atoms(self, vertex_slice: Slice) -> ConstantSDRAM: return ConstantSDRAM(self.get_sdram_usage_for_atoms(vertex_slice)) - def get_sdram_usage_for_atoms(self, vertex_slice): + def get_sdram_usage_for_atoms(self, vertex_slice: Slice) -> int: """ :param vertex_slice: the atoms being considered :return: the amount of sdram (in bytes this model will use) diff --git a/unittests/model_tests/resources_tests/test_resources_model.py b/unittests/model_tests/resources_tests/test_resources_model.py index 22f511969..196436c0c 100644 --- a/unittests/model_tests/resources_tests/test_resources_model.py +++ b/unittests/model_tests/resources_tests/test_resources_model.py @@ -126,7 +126,6 @@ def test_tags_resources(self): self.assertEqual(iptr.strip_sdp, 3) self.assertEqual(iptr.tag, 4) self.assertEqual(iptr.traffic_identifier, 5) - self.assertEqual(iptr.get_value(), ['1.2.3.4', 2, 3, 4, 5]) self.assertEqual(str(iptr), "IPTagResource(ip_address=1.2.3.4, port=2, " "strip_sdp=3, tag=4, traffic_identifier=5)") @@ -136,7 +135,6 @@ def test_tags_resources(self): self.assertEqual(riptr.port, 1) self.assertEqual(riptr.sdp_port, 2) self.assertEqual(riptr.tag, 3) - self.assertEqual(riptr.get_value(), [1, 2, 3]) self.assertEqual(str(riptr), "ReverseIPTagResource(port=1, sdp_port=2, tag=3)") riptr2 = ReverseIPtagResource(1, 2, 3)