Skip to content

Commit

Permalink
Merge pull request #268 from SpiNNakerManchester/overrides_check
Browse files Browse the repository at this point in the history
type overrides
  • Loading branch information
Christian-B authored Jan 15, 2024
2 parents dc6f4b6 + b8359df commit e15a836
Show file tree
Hide file tree
Showing 19 changed files with 221 additions and 108 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/python_actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install pip, etc
uses: ./support/actions/python-tools
- name: Install mypy
run: pip install mypy

- name: Install Spinnaker Dependencies
uses: ./support/actions/install-spinn-deps
with:
Expand Down Expand Up @@ -76,6 +79,9 @@ jobs:
exitcheck: 31 # Action fails on any message
language: en_GB

- name: Lint with mypy
run: mypy $BASE_PKG

validate:
runs-on: ubuntu-latest
strategy:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@
# limitations under the License.

from enum import IntEnum
from typing import Iterable, Optional
from spinn_utilities.overrides import overrides
from spinn_machine.tags import IPTag, ReverseIPTag
from pacman.model.graphs.machine import MachineVertex
from pacman.model.placements import Placement
from pacman.model.resources import VariableSDRAM
from spinn_front_end_common.data import FecDataView
from spinn_front_end_common.interface.ds import DataSpecificationGenerator
from spinn_front_end_common.utilities.constants import (
SYSTEM_BYTES_REQUIREMENT, BYTES_PER_WORD)
from spinn_front_end_common.utilities.exceptions import ConfigurationException
Expand Down Expand Up @@ -72,7 +76,9 @@ def add_neighbour(self, neighbour):
@overrides(
MachineDataSpecableVertex.generate_machine_data_specification)
def generate_machine_data_specification(
self, spec, placement, iptags, reverse_iptags):
self, spec: DataSpecificationGenerator, placement: Placement,
iptags: Optional[Iterable[IPTag]],
reverse_iptags: Optional[Iterable[ReverseIPTag]]):
if len(self._neighbours) != 8:
raise ValueError(
f"Only {len(self._neighbours)} neighbours, not 8")
Expand Down Expand Up @@ -149,7 +155,7 @@ def get_data(self):

@property
@overrides(MachineVertex.sdram_required)
def sdram_required(self):
def sdram_required(self) -> VariableSDRAM:
fixed_sdram = (SYSTEM_BYTES_REQUIREMENT + self.TRANSMISSION_DATA_SIZE +
self.STATE_DATA_SIZE +
self.NEIGHBOUR_INITIAL_STATES_SIZE +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@
# limitations under the License.

from enum import IntEnum
from typing import Iterable, List, Optional
from spinn_utilities.overrides import overrides
from spinn_machine.tags import IPTag, ReverseIPTag
from pacman.model.graphs.machine import MachineVertex
from pacman.model.placements import Placement
from pacman.model.resources import VariableSDRAM
from spinn_front_end_common.data import FecDataView
from spinn_front_end_common.interface.ds import DataSpecificationGenerator
from spinn_front_end_common.utilities.constants import (
SYSTEM_BYTES_REQUIREMENT, BYTES_PER_WORD)
from spinn_front_end_common.utilities.helpful_functions import (
Expand Down Expand Up @@ -80,7 +84,9 @@ def add_neighbour(self, neighbour):

@overrides(MachineDataSpecableVertex.generate_machine_data_specification)
def generate_machine_data_specification(
self, spec, placement, iptags, reverse_iptags):
self, spec: DataSpecificationGenerator, placement: Placement,
iptags: Optional[Iterable[IPTag]],
reverse_iptags: Optional[Iterable[ReverseIPTag]]):
# pylint: disable=arguments-differ
if len(self._neighbours) != 8:
raise ValueError(
Expand Down Expand Up @@ -147,7 +153,7 @@ def get_data(self):

@property
@overrides(MachineVertex.sdram_required)
def sdram_required(self):
def sdram_required(self) -> VariableSDRAM:
fixed_sdram = (
SYSTEM_BYTES_REQUIREMENT +
self.TRANSMISSION_DATA_SIZE +
Expand All @@ -166,10 +172,10 @@ def __repr__(self):
return self.label

@overrides(AbstractReceiveBuffersToHost.get_recorded_region_ids)
def get_recorded_region_ids(self):
def get_recorded_region_ids(self) -> List[int]:
return [Channels.STATE_LOG]

@overrides(AbstractReceiveBuffersToHost.get_recording_region_base_address)
def get_recording_region_base_address(self, placement):
def get_recording_region_base_address(self, placement: Placement) -> int:
return locate_memory_region_for_placement(
placement, DataRegions.RESULTS)
14 changes: 10 additions & 4 deletions gfe_examples/hello_world/hello_world_vertex.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@

from enum import IntEnum
import logging
from typing import Iterable, List, Optional
from spinn_utilities.log import FormatAdapter
from spinn_utilities.overrides import overrides
from spinn_machine.tags import IPTag, ReverseIPTag
from pacman.model.graphs.machine import MachineVertex
from pacman.model.placements import Placement
from pacman.model.resources import ConstantSDRAM
from spinn_front_end_common.interface.ds import DataSpecificationGenerator
from spinn_front_end_common.utilities.constants import SYSTEM_BYTES_REQUIREMENT
from spinn_front_end_common.utilities.helpful_functions import (
locate_memory_region_for_placement)
Expand Down Expand Up @@ -53,15 +57,17 @@ def __init__(self, n_hellos, label=None):

@property
@overrides(MachineVertex.sdram_required)
def sdram_required(self):
def sdram_required(self) -> ConstantSDRAM:
return ConstantSDRAM(
SYSTEM_BYTES_REQUIREMENT +
get_recording_header_size(len(Channels)) +
self._string_data_size)

@overrides(MachineDataSpecableVertex.generate_machine_data_specification)
def generate_machine_data_specification(
self, spec, placement, iptags, reverse_iptags):
self, spec: DataSpecificationGenerator, placement: Placement,
iptags: Optional[Iterable[IPTag]],
reverse_iptags: Optional[Iterable[ReverseIPTag]]):
# Generate the system data region for simulation .c requirements
self.generate_system_region(spec)

Expand All @@ -84,10 +90,10 @@ def read(self):
return str(bytearray(raw_data))

@overrides(AbstractReceiveBuffersToHost.get_recorded_region_ids)
def get_recorded_region_ids(self):
def get_recorded_region_ids(self) -> List[int]:
return [Channels.HELLO]

@overrides(AbstractReceiveBuffersToHost.get_recording_region_base_address)
def get_recording_region_base_address(self, placement):
def get_recording_region_base_address(self, placement: Placement) -> int:
return locate_memory_region_for_placement(
placement, DataRegions.STRING_DATA)
12 changes: 8 additions & 4 deletions gfe_examples/hello_world_untimed/hello_world_vertex.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@

from enum import IntEnum
import logging
from typing import List
from spinn_utilities.log import FormatAdapter
from spinn_utilities.overrides import overrides
from pacman.model.graphs.machine import MachineVertex
from pacman.model.placements import Placement
from pacman.model.resources import VariableSDRAM
from spinn_front_end_common.data import FecDataView
from spinn_front_end_common.utilities.constants import (
Expand All @@ -29,6 +31,7 @@
AbstractReceiveBuffersToHost)
from spinn_front_end_common.interface.buffer_management import (
recording_utilities)
from spinn_front_end_common.interface.ds import DataSpecificationGenerator
from spinnaker_graph_front_end.utilities import SimulatorVertex
from spinnaker_graph_front_end.utilities.data_utils import (
generate_steps_system_data_region)
Expand Down Expand Up @@ -76,7 +79,7 @@ def __init__(self, label):

@property
@overrides(MachineVertex.sdram_required)
def sdram_required(self):
def sdram_required(self) -> VariableSDRAM:
fixed = (
SYSTEM_BYTES_REQUIREMENT +
recording_utilities.get_recording_header_size(len(Channels)) +
Expand All @@ -85,7 +88,8 @@ def sdram_required(self):
return VariableSDRAM(fixed, variable)

@overrides(AbstractGeneratesDataSpecification.generate_data_specification)
def generate_data_specification(self, spec, placement):
def generate_data_specification(
self, spec: DataSpecificationGenerator, placement: Placement):
# pylint: disable=arguments-differ

# Generate the system data region for simulation .c requirements
Expand Down Expand Up @@ -124,10 +128,10 @@ def read(self):
return str(raw_data, self._ENCODING)

@overrides(AbstractReceiveBuffersToHost.get_recorded_region_ids)
def get_recorded_region_ids(self):
def get_recorded_region_ids(self) -> List[int]:
return [Channels.HELLO]

@overrides(AbstractReceiveBuffersToHost.get_recording_region_base_address)
def get_recording_region_base_address(self, placement):
def get_recording_region_base_address(self, placement: Placement) -> int:
return locate_memory_region_for_placement(
placement, DataRegions.STRING_DATA)
2 changes: 1 addition & 1 deletion gfe_examples/live_io/live_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def start_sending(label, c):


def end_sim(label, c):
# pylint: disable=unused-argument
# pylint: disable=unused-argument,global-statement
global running
running = False

Expand Down
10 changes: 8 additions & 2 deletions gfe_examples/live_io/live_io_vertex.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@

from enum import IntEnum
import logging
from typing import Iterable, Optional
from spinn_utilities.log import FormatAdapter
from spinn_utilities.overrides import overrides
from spinn_machine.tags import IPTag, ReverseIPTag
from pacman.model.graphs.common import Slice
from pacman.model.graphs.machine import MachineVertex
from pacman.model.placements import Placement
from pacman.model.resources import ConstantSDRAM
from spinn_front_end_common.interface.ds import DataSpecificationGenerator
from spinn_front_end_common.utilities.constants import (
SYSTEM_BYTES_REQUIREMENT, BYTES_PER_WORD)
from spinn_front_end_common.abstract_models.impl import (
Expand Down Expand Up @@ -46,7 +50,7 @@ def __init__(self, n_keys, send_partition="LiveOut", label=None):

@property
@overrides(MachineVertex.sdram_required)
def sdram_required(self):
def sdram_required(self) -> ConstantSDRAM:
return ConstantSDRAM(
SYSTEM_BYTES_REQUIREMENT + N_KEY_DATA_BYTES)

Expand All @@ -55,7 +59,9 @@ def get_n_keys_for_partition(self, partition_id):

@overrides(MachineDataSpecableVertex.generate_machine_data_specification)
def generate_machine_data_specification(
self, spec, placement, iptags, reverse_iptags):
self, spec: DataSpecificationGenerator, placement: Placement,
iptags: Optional[Iterable[IPTag]],
reverse_iptags: Optional[Iterable[ReverseIPTag]]):
# Generate the system data region for simulation .c requirements
self.generate_system_region(spec)

Expand Down
11 changes: 7 additions & 4 deletions gfe_examples/sync_test/sync_test_vertex.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
from spinn_utilities.overrides import overrides
from spinnman.model.enums import ExecutableType
from pacman.model.graphs.machine import MachineVertex
from pacman.model.placements import Placement
from pacman.model.resources import ConstantSDRAM
from spinn_front_end_common.data import FecDataView
from spinn_front_end_common.interface.ds import DataSpecificationGenerator
from spinn_front_end_common.utilities.constants import (
SYSTEM_BYTES_REQUIREMENT, BYTES_PER_WORD)
from spinn_front_end_common.abstract_models import (
Expand Down Expand Up @@ -54,21 +56,22 @@ def __init__(self, lead, app_vertex, label=None):
self._lead = lead

@overrides(AbstractHasAssociatedBinary.get_binary_file_name)
def get_binary_file_name(self):
def get_binary_file_name(self) -> str:
return "sync_test.aplx"

@overrides(AbstractHasAssociatedBinary.get_binary_start_type)
def get_binary_start_type(self):
def get_binary_start_type(self) -> ExecutableType:
return ExecutableType.USES_SIMULATION_INTERFACE

@property
@overrides(MachineVertex.sdram_required)
def sdram_required(self):
def sdram_required(self) -> ConstantSDRAM:
return ConstantSDRAM(SYSTEM_BYTES_REQUIREMENT + BYTES_PER_WORD * 2)

@overrides(
AbstractGeneratesDataSpecification.generate_data_specification)
def generate_data_specification(self, spec, placement):
def generate_data_specification(
self, spec: DataSpecificationGenerator, placement: Placement):
# Generate the system data region for simulation .c requirements
generate_system_data_region(spec, DataRegions.SYSTEM.value, self)

Expand Down
14 changes: 10 additions & 4 deletions gfe_examples/template/template_vertex.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@

from enum import IntEnum
import logging
from typing import Iterable, List, Optional
from spinn_utilities.log import FormatAdapter
from spinn_utilities.overrides import overrides
from spinn_machine.tags import IPTag, ReverseIPTag
from pacman.model.graphs.machine import MachineVertex
from pacman.model.placements import Placement
from pacman.model.resources import VariableSDRAM
from spinn_front_end_common.data import FecDataView
from spinn_front_end_common.interface.ds import DataSpecificationGenerator
from spinn_front_end_common.utilities.constants import (
SYSTEM_BYTES_REQUIREMENT, BYTES_PER_WORD)
from spinn_front_end_common.utilities.helpful_functions import (
Expand Down Expand Up @@ -68,7 +72,7 @@ def __init__(self, label):

@property
@overrides(MachineVertex.sdram_required)
def sdram_required(self):
def sdram_required(self) -> VariableSDRAM:
constant_sdram = (
SYSTEM_BYTES_REQUIREMENT + self.TRANSMISSION_REGION_N_BYTES +
recording_utilities.get_recording_header_size(
Expand All @@ -82,7 +86,9 @@ def sdram_required(self):

@overrides(MachineDataSpecableVertex.generate_machine_data_specification)
def generate_machine_data_specification(
self, spec, placement, iptags, reverse_iptags):
self, spec: DataSpecificationGenerator, placement: Placement,
iptags: Optional[Iterable[IPTag]],
reverse_iptags: Optional[Iterable[ReverseIPTag]]):
# Generate the system data region for simulation .c requirements
self.generate_system_region(spec, DataRegions.SYSTEM)

Expand Down Expand Up @@ -125,10 +131,10 @@ def read(self):
return raw_data

@overrides(AbstractReceiveBuffersToHost.get_recorded_region_ids)
def get_recorded_region_ids(self):
def get_recorded_region_ids(self) -> List[int]:
return [RecordingChannels.RECORDING]

@overrides(AbstractReceiveBuffersToHost.get_recording_region_base_address)
def get_recording_region_base_address(self, placement):
def get_recording_region_base_address(self, placement: Placement) -> int:
return locate_memory_region_for_placement(
placement, DataRegions.RECORDED_DATA)
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from enum import IntEnum

from typing import Iterable, Optional
from spinnman.model.enums import ExecutableType
from spinn_machine.tags import IPTag, ReverseIPTag
from pacman.model.graphs import AbstractSupportsSDRAMEdges
from pacman.model.graphs.machine import MachineVertex
from pacman.model.graphs.machine import MachineVertex, SDRAMMachineEdge
from pacman.model.placements import Placement
from pacman.model.resources import ConstantSDRAM
from spinn_front_end_common.abstract_models import AbstractHasAssociatedBinary
from spinn_front_end_common.abstract_models.impl import (
MachineDataSpecableVertex)
from spinn_front_end_common.interface.ds import DataSpecificationGenerator
from spinn_front_end_common.interface.simulation import simulation_utilities
from spinn_front_end_common.utilities.constants import (
SIMULATION_N_BYTES, BYTES_PER_WORD, SARK_PER_MALLOC_SDRAM_USAGE)
Expand Down Expand Up @@ -60,7 +63,7 @@ def add_outgoing_sdram_partition(self, partition):


@overrides(MachineVertex.sdram_required)
def sdram_required(self):
def sdram_required(self) -> ConstantSDRAM:
if (len(self.__incoming_sdram_partitions) +
len(self.__outgoing_sdram_partitions) == 0):
raise ValueError("Isolated SDRAM vertex!")
Expand All @@ -79,24 +82,26 @@ def sdram_required(self):
outgoing_sdram_requirements)

@overrides(AbstractSupportsSDRAMEdges.sdram_requirement)
def sdram_requirement(self, sdram_machine_edge):
def sdram_requirement(self, sdram_machine_edge: SDRAMMachineEdge) -> int:
if self.__sdram_cost is None:
raise NotImplementedError(
"This vertex has no cost so is not expected to appear "
"as the pre-vertex to an SDRAM edge!")
return self.__sdram_cost

@overrides(AbstractHasAssociatedBinary.get_binary_file_name)
def get_binary_file_name(self):
def get_binary_file_name(self) -> str:
return "sdram.aplx"

@overrides(AbstractHasAssociatedBinary.get_binary_start_type)
def get_binary_start_type(self):
def get_binary_start_type(self) -> ExecutableType:
return ExecutableType.USES_SIMULATION_INTERFACE

@overrides(MachineDataSpecableVertex.generate_machine_data_specification)
def generate_machine_data_specification(
self, spec, placement, iptags, reverse_iptags):
self, spec: DataSpecificationGenerator, placement: Placement,
iptags: Optional[Iterable[IPTag]],
reverse_iptags: Optional[Iterable[ReverseIPTag]]):
# reserve memory regions
spec.reserve_memory_region(
region=DataRegions.SYSTEM, size=SIMULATION_N_BYTES,
Expand Down
Loading

0 comments on commit e15a836

Please sign in to comment.