Skip to content

Commit

Permalink
Merge pull request #585 from SpiNNakerManchester/t_pacman
Browse files Browse the repository at this point in the history
Typing for PACMAN
  • Loading branch information
Christian-B authored Dec 23, 2024
2 parents ca929f3 + 006fac8 commit 12ba215
Show file tree
Hide file tree
Showing 63 changed files with 316 additions and 314 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/python_actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion mypy.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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
23 changes: 11 additions & 12 deletions pacman_test_objects/placer_test_support.py → mypyd.bash
100644 → 100755
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
15 changes: 8 additions & 7 deletions pacman/data/pacman_data_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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:
Expand Down
28 changes: 14 additions & 14 deletions pacman/data/pacman_data_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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`.
Expand All @@ -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():
Expand All @@ -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():
Expand All @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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)")
Expand Down
8 changes: 4 additions & 4 deletions pacman/model/graphs/abstract_edge_partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion pacman/model/graphs/abstract_multiple_partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion pacman/model/graphs/abstract_single_source_partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
5 changes: 3 additions & 2 deletions pacman/model/graphs/abstract_vertex.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
6 changes: 3 additions & 3 deletions pacman/model/graphs/application/application_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
Loading

0 comments on commit 12ba215

Please sign in to comment.