Skip to content

Commit

Permalink
overrides typing
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian-B committed Dec 8, 2023
1 parent 084f2c7 commit 867c9fa
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 37 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
6 changes: 4 additions & 2 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,7 +186,8 @@ 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
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.interger]
) -> 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) -> bool:
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
20 changes: 11 additions & 9 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 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,7 +42,7 @@ 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")
Expand All @@ -55,35 +56,36 @@ def set_governed_app_vertex(self, app_vertex):
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

0 comments on commit 867c9fa

Please sign in to comment.