Skip to content

Commit

Permalink
Merge pull request #537 from SpiNNakerManchester/overrides_check
Browse files Browse the repository at this point in the history
Overrides check
  • Loading branch information
Christian-B authored Jan 15, 2024
2 parents 261d001 + 69f6987 commit 1bfe611
Show file tree
Hide file tree
Showing 17 changed files with 74 additions and 48 deletions.
4 changes: 2 additions & 2 deletions pacman/model/graphs/application/application_2d_fpga_vertex.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import List, Optional
from typing import List, Optional, Tuple
from spinn_utilities.overrides import overrides
from .application_fpga_vertex import ApplicationFPGAVertex
from pacman.model.graphs.application.abstract import Abstract2DDeviceVertex
Expand Down Expand Up @@ -90,7 +90,7 @@ def sub_height(self) -> int:

@property
@overrides(ApplicationFPGAVertex.atoms_shape)
def atoms_shape(self):
def atoms_shape(self) -> Tuple[int, ...]:
return (self.__width, self.__height)

@overrides(ApplicationFPGAVertex.get_incoming_slice_for_link)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Optional
from typing import Optional, Tuple
from spinn_utilities.overrides import overrides
from .application_spinnaker_link_vertex import ApplicationSpiNNakerLinkVertex
from pacman.model.graphs.application.abstract import Abstract2DDeviceVertex
Expand Down Expand Up @@ -88,7 +88,7 @@ def sub_height(self) -> int:

@property
@overrides(ApplicationSpiNNakerLinkVertex.atoms_shape)
def atoms_shape(self):
def atoms_shape(self) -> Tuple[int, ...]:
return (self.__width, self.__height)

@overrides(ApplicationSpiNNakerLinkVertex.get_incoming_slice)
Expand Down
8 changes: 5 additions & 3 deletions pacman/model/graphs/common/mdslice.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ def from_string(cls, as_str: str) -> Union[MDSlice, Slice]:
atoms_shape)

@overrides(Slice.get_relative_indices)
def get_relative_indices(self, app_vertex_indices):
def get_relative_indices(self, app_vertex_indices: NDArray[numpy.integer]
) -> NDArray[numpy.integer]:
n_dims = len(self._atoms_shape)
remainders = app_vertex_indices
cum_last_core = 1
Expand All @@ -185,11 +186,12 @@ def get_relative_indices(self, app_vertex_indices):
return rel_index.astype(numpy.uint32)

@overrides(Slice.get_raster_indices)
def get_raster_indices(self, relative_indices):
def get_raster_indices(self, relative_indices: NDArray[numpy.integer]
) -> NDArray[numpy.integer]:
n_dims = len(self._atoms_shape)
remainders = relative_indices
cum_last_size = 1
global_index = numpy.zeros(len(relative_indices))
global_index = numpy.zeros(len(relative_indices), dtype=int)
for n in range(n_dims):
# Work out the local index in this dimension
local_index_d = remainders % self._shape[n]
Expand Down
6 changes: 4 additions & 2 deletions pacman/model/graphs/common/slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ def from_string(cls, as_str: str) -> Slice:
hi_atom = int(parts[1])
return Slice(lo_atom, hi_atom)

def get_relative_indices(self, app_vertex_indices):
def get_relative_indices(self, app_vertex_indices: NDArray[numpy.integer]
) -> NDArray[numpy.integer]:
"""
Convert from raster indices to slice-level indices.
Expand All @@ -218,7 +219,8 @@ def get_relative_indices(self, app_vertex_indices):
"""
return app_vertex_indices - self._lo_atom

def get_raster_indices(self, relative_indices):
def get_raster_indices(self, relative_indices: NDArray[numpy.integer]
) -> NDArray[numpy.integer]:
"""
Convert from slice-level indices to raster indices.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,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):
def add_edge(self, edge: E):
if self._sdram_size is None:
self._sdram_size = edge.sdram_size
elif self._sdram_size != edge.sdram_size:
Expand Down
2 changes: 1 addition & 1 deletion pacman/model/graphs/machine/machine_edge.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def __init__(self, pre_vertex: MachineVertex, post_vertex: MachineVertex,

@property
@overrides(AbstractEdge.label)
def label(self):
def label(self) -> Optional[str]:
return self._label

@property
Expand Down
20 changes: 13 additions & 7 deletions pacman/model/graphs/machine/simple_machine_vertex.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Iterable, Optional
from .machine_vertex import MachineVertex
from spinn_utilities.overrides import overrides
from pacman.model.resources import AbstractSDRAM
from pacman.model.resources import IPtagResource
from pacman.model.resources import ReverseIPtagResource


class SimpleMachineVertex(MachineVertex):
Expand All @@ -27,29 +31,31 @@ class SimpleMachineVertex(MachineVertex):
__slots__ = ("_iptags", "_reverse_iptags", "_sdram")

def __init__(self, sdram, label=None,
app_vertex=None, vertex_slice=None, iptags=None,
reverse_iptags=None):
app_vertex=None, vertex_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
self._iptags = []
self._iptags: Iterable[IPtagResource] = []
if iptags:
self._iptags = iptags
self._reverse_iptags = []
self._reverse_iptags: Iterable[ReverseIPtagResource] = []
if reverse_iptags:
self._reverse_iptags = reverse_iptags

@property
@overrides(MachineVertex.sdram_required)
def sdram_required(self):
def sdram_required(self) -> AbstractSDRAM:
return self._sdram

@property
@overrides(MachineVertex.iptags)
def iptags(self):
def iptags(self) -> Iterable[IPtagResource]:
return self._iptags

@property
@overrides(MachineVertex.reverse_iptags)
def reverse_iptags(self):
def reverse_iptags(self) -> Iterable[ReverseIPtagResource]:
return self._reverse_iptags
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def machine_vertices_for_recording(
raise NotImplementedError

@abstractmethod
def reset_called(self):
def reset_called(self) -> None:
"""
Reset the splitter to be as if it has not operated a splitting yet.
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,5 +163,5 @@ def machine_vertices_for_recording(
return []

@overrides(AbstractSplitterCommon.reset_called)
def reset_called(self):
def reset_called(self) -> None:
pass
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ def get_in_coming_vertices(self, partition_id: str) -> List[MV]:
return [self.governed_app_vertex.machine_vertex]

@overrides(AbstractSplitterCommon.machine_vertices_for_recording)
def machine_vertices_for_recording(self, variable_to_record) -> List[MV]:
def machine_vertices_for_recording(
self, variable_to_record: str) -> List[MV]:
return [self.governed_app_vertex.machine_vertex]

@overrides(AbstractSplitterCommon.reset_called)
def reset_called(self):
def reset_called(self) -> None:
pass
25 changes: 14 additions & 11 deletions pacman/model/partitioner_splitters/splitter_one_to_one_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

import logging
from typing import Optional
from typing import cast, List, Optional
from spinn_utilities.overrides import overrides
from spinn_utilities.log import FormatAdapter
from pacman.exceptions import PacmanConfigurationException
Expand All @@ -22,6 +22,7 @@
from pacman.model.graphs.machine import MachineVertex
from pacman.model.partitioner_interfaces import LegacyPartitionerAPI
from pacman.model.resources import AbstractSDRAM
from pacman.utilities.utility_objs import ChipCounter
from .abstract_splitter_common import AbstractSplitterCommon

logger = FormatAdapter(logging.getLogger(__name__))
Expand All @@ -41,49 +42,51 @@ def __init__(self) -> None:
self._sdram: Optional[AbstractSDRAM] = None

@overrides(AbstractSplitterCommon.set_governed_app_vertex)
def set_governed_app_vertex(self, app_vertex):
def set_governed_app_vertex(self, app_vertex: ApplicationVertex):
if not isinstance(app_vertex, LegacyPartitionerAPI):
raise PacmanConfigurationException(
f"{self} is not a LegacyPartitionerAPI")
super().set_governed_app_vertex(app_vertex)
self._vertex_slice = Slice(0, self.governed_app_vertex.n_atoms - 1)
self._sdram = self.governed_app_vertex.get_sdram_used_by_atoms(
lp = cast(LegacyPartitionerAPI, app_vertex)
self._sdram = lp.get_sdram_used_by_atoms(
self._vertex_slice)
self._machine_vertex = self.governed_app_vertex.create_machine_vertex(
self._machine_vertex = lp.create_machine_vertex(
vertex_slice=self._vertex_slice,
sdram=self._sdram, label=None)
self.governed_app_vertex.remember_machine_vertex(self._machine_vertex)

@overrides(AbstractSplitterCommon.create_machine_vertices)
def create_machine_vertices(self, chip_counter):
def create_machine_vertices(self, chip_counter: ChipCounter):
assert self._sdram is not None
chip_counter.add_core(self._sdram)

@overrides(AbstractSplitterCommon.get_out_going_slices)
def get_out_going_slices(self):
def get_out_going_slices(self) -> List[Slice]:
assert self._vertex_slice is not None
return [self._vertex_slice]

@overrides(AbstractSplitterCommon.get_in_coming_slices)
def get_in_coming_slices(self):
def get_in_coming_slices(self) -> List[Slice]:
assert self._vertex_slice is not None
return [self._vertex_slice]

@overrides(AbstractSplitterCommon.get_out_going_vertices)
def get_out_going_vertices(self, partition_id):
def get_out_going_vertices(self, partition_id: str) -> List[MachineVertex]:
assert self._machine_vertex is not None
return [self._machine_vertex]

@overrides(AbstractSplitterCommon.get_in_coming_vertices)
def get_in_coming_vertices(self, partition_id):
def get_in_coming_vertices(self, partition_id: str) -> List[MachineVertex]:
assert self._machine_vertex is not None
return [self._machine_vertex]

@overrides(AbstractSplitterCommon.machine_vertices_for_recording)
def machine_vertices_for_recording(self, variable_to_record):
def machine_vertices_for_recording(
self, variable_to_record: str) -> List[MachineVertex]:
assert self._machine_vertex is not None
return [self._machine_vertex]

@overrides(AbstractSplitterCommon.reset_called)
def reset_called(self):
def reset_called(self) -> None:
pass
8 changes: 5 additions & 3 deletions pacman/model/resources/constant_sdram.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Optional, TextIO
from spinn_utilities.overrides import overrides
from .abstract_sdram import AbstractSDRAM

Expand All @@ -35,7 +36,7 @@ def __init__(self, sdram: int):
self._sdram = int(sdram)

@overrides(AbstractSDRAM.get_total_sdram)
def get_total_sdram(self, n_timesteps) -> int: # @UnusedVariable
def get_total_sdram(self, n_timesteps: Optional[int]) -> int:
return self._sdram

@property
Expand Down Expand Up @@ -65,7 +66,7 @@ def __sub__(self, other):
return other.sub_from(self)

@overrides(AbstractSDRAM.sub_from)
def sub_from(self, other):
def sub_from(self, other: AbstractSDRAM) -> AbstractSDRAM:
if isinstance(other, ConstantSDRAM):
return ConstantSDRAM(
other.fixed - self._sdram)
Expand All @@ -74,5 +75,6 @@ def sub_from(self, other):
return other - self

@overrides(AbstractSDRAM.report)
def report(self, timesteps, indent="", preamble="", target=None):
def report(self, timesteps: Optional[int], indent: str = "",
preamble: str = "", target: Optional[TextIO] = None):
print(indent, preamble, f"Constant {self._sdram} bytes", file=target)
5 changes: 3 additions & 2 deletions pacman/model/resources/multi_region_sdram.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from enum import Enum
import math
import numpy
from typing import Dict, Union
from typing import Dict, Optional, TextIO, Union
from typing_extensions import TypeAlias
from spinn_utilities.overrides import overrides
from .abstract_sdram import AbstractSDRAM
Expand Down Expand Up @@ -132,7 +132,8 @@ def merge(self, other: MultiRegionSDRAM):
self.__regions[region] = other.regions[region]

@overrides(AbstractSDRAM.report)
def report(self, timesteps, indent="", preamble="", target=None):
def report(self, timesteps: Optional[int], indent: str = "",
preamble: str = "", target: Optional[TextIO] = None):
super().report(timesteps, indent, preamble, target)
for region in self.__regions:
self.__regions[region].report(
Expand Down
5 changes: 3 additions & 2 deletions pacman/model/resources/variable_sdram.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import math
import numpy
from typing import Optional, Union
from typing import Optional, TextIO, Union
from spinn_utilities.overrides import overrides
from pacman.exceptions import PacmanConfigurationException
from .abstract_sdram import AbstractSDRAM
Expand Down Expand Up @@ -87,7 +87,8 @@ def sub_from(self, other: AbstractSDRAM) -> 'VariableSDRAM':
other.per_timestep - self._per_timestep_sdram)

@overrides(AbstractSDRAM.report)
def report(self, timesteps, indent="", preamble="", target=None):
def report(self, timesteps: Optional[int], indent: str = "",
preamble: str = "", target: Optional[TextIO] = None):
print(indent, preamble,
f"Fixed {self._fixed_sdram} bytes "
f"Per_timestep {self._per_timestep_sdram} bytes "
Expand Down
12 changes: 8 additions & 4 deletions pacman_test_objects/simple_test_vertex.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@

""" test vertex used in many unit tests
"""
from typing import Optional
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.resources import ConstantSDRAM
from pacman.model.resources import AbstractSDRAM, ConstantSDRAM


class SimpleTestVertex(ApplicationVertex, LegacyPartitionerAPI):
Expand All @@ -38,7 +40,7 @@ def __init__(self, n_atoms, label="testVertex", max_atoms_per_core=256,
self._fixed_sdram_value = fixed_sdram_value

@overrides(LegacyPartitionerAPI.get_sdram_used_by_atoms)
def get_sdram_used_by_atoms(self, vertex_slice):
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):
Expand All @@ -51,10 +53,12 @@ def get_sdram_usage_for_atoms(self, vertex_slice):
return self._fixed_sdram_value

@overrides(LegacyPartitionerAPI.create_machine_vertex)
def create_machine_vertex(self, vertex_slice, sdram, label=None):
def create_machine_vertex(
self, vertex_slice: Slice, sdram: AbstractSDRAM,
label: Optional[str] = None) -> SimpleMachineVertex:
return SimpleMachineVertex(sdram, label, self, vertex_slice)

@property
@overrides(ApplicationVertex.n_atoms)
def n_atoms(self):
def n_atoms(self) -> int:
return self._n_atoms
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
class MockSupportsSDRAMEdges(SimpleMachineVertex, AbstractSupportsSDRAMEdges):

@overrides(AbstractSupportsSDRAMEdges.sdram_requirement)
def sdram_requirement(self, sdram_machine_edge):
def sdram_requirement(self, sdram_machine_edge: SDRAMMachineEdge) -> int:
# A mock so that the size can be different depending on prevertex
return 16 + self.sdram_required.fixed

Expand Down
Loading

0 comments on commit 1bfe611

Please sign in to comment.