Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overrides check #1425

Merged
merged 40 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
429f528
typing
Christian-B Dec 5, 2023
8338467
overrides typing
Christian-B Dec 8, 2023
e664609
merged in master
Christian-B Dec 18, 2023
a3b2f2c
typing of override functions
Christian-B Dec 18, 2023
da35cfb
typing of override functions
Christian-B Dec 19, 2023
3cb8b78
flake8
Christian-B Dec 19, 2023
5ab17ef
spelling fixes
Christian-B Dec 19, 2023
37e3567
# pylint: disable=redefined-builtin
Christian-B Dec 19, 2023
60a2ed7
rtype
Christian-B Dec 19, 2023
79b89c2
type mocks
Christian-B Dec 19, 2023
7f8aafc
validate with a ProjectionApplicationEdge
Christian-B Dec 19, 2023
04a39e0
remove a typing that did not work
Christian-B Dec 19, 2023
fe030cc
Split If to help the typer
Christian-B Dec 20, 2023
b2bb18b
if self.__delays is not None:
Christian-B Dec 20, 2023
c216b0d
better TypeGuard
Christian-B Dec 20, 2023
a1124e7
Type fix
Christian-B Dec 20, 2023
8295cff
fix write_parameters types
Christian-B Dec 20, 2023
4e37725
typing fix
Christian-B Dec 20, 2023
f7c1f16
fix incorrect param passing
Christian-B Dec 20, 2023
774e187
is_same_as has two parents
Christian-B Dec 20, 2023
8322fb7
is_same_as must be same type and pass both parent checks
Christian-B Dec 20, 2023
81cbc60
type and log fixes
Christian-B Dec 20, 2023
b7e03c2
fix overrides
Christian-B Dec 20, 2023
373b3e0
fix super call
Christian-B Dec 20, 2023
4b40505
initial delay only a float
Christian-B Dec 21, 2023
9226c9b
flake8
Christian-B Dec 21, 2023
30a2f5b
adapt if max delay can be None
Christian-B Dec 21, 2023
46e3d58
typing
Christian-B Dec 21, 2023
d3bbc16
fix call
Christian-B Dec 21, 2023
30a8507
override app_vertex to guarantee it exosts and is correct type
Christian-B Dec 21, 2023
7142c30
flake8
Christian-B Dec 21, 2023
20ad0f8
type asserts
Christian-B Dec 21, 2023
3a0cde5
type same of super
Christian-B Dec 21, 2023
0ba4952
handle none
Christian-B Dec 21, 2023
a3e836d
type assert
Christian-B Dec 21, 2023
edb4844
fix typing
Christian-B Dec 21, 2023
fc37104
typing fixes
Christian-B Dec 21, 2023
b3dc799
Merge branch 'master' into overrides_check
Christian-B Jan 5, 2024
5b91cbd
merge
Christian-B Jan 8, 2024
e4c3206
merged in master
Christian-B Jan 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .pylint_dict.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ analog
componentised
config
heatmap
multiplicator
generatable
multapse
multiplicator
Expand Down Expand Up @@ -90,10 +91,26 @@ ProgressBar
RandomDistribution
SourceSegmentedSDRAMMachinePartition
SpinnmanIOException
PopulationApplicationVertex
AbstractSynapseType
SynapseInformation
SynapseRegionReferences
SynapseRegions
VariableSDRAM
MultiRegionSDRAM
AbstractMulticastControllableDevice
CommonRegions
NeuronRegions
MDSlice
DataSpecificationGenerator
CoreSubset
CoreSubsets
SpinnmanIOException
AbstractCurrentSource
GeneratorData
EIEIOType
EIEIOPrefix
RandomDistribtuion

# Others' Python types (including PYNN terms)
AnalogSignal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
from spinn_front_end_common.interface.ds import DataType
from spinn_front_end_common.utilities.connections.live_event_connection \
import (
LiveEventConnection, _Callback, _InitCallback)
LiveEventConnection, _Callback, _InitCallback, _RcvCallback,
_RcvTimeCallback)
from spinn_front_end_common.utilities.exceptions import ConfigurationException
from spinn_front_end_common.utilities.constants import NOTIFY_PORT

Expand Down Expand Up @@ -124,13 +125,15 @@ def add_init_callback(self, label: str, init_callback: _InitCallback):

@overrides(LiveEventConnection.add_receive_callback)
def add_receive_callback(
self, label, live_event_callback, translate_key=False):
self, label: str, live_event_callback: _RcvTimeCallback,
translate_key: bool = True):
raise ConfigurationException(
"SpynnakerPoissonControlPopulation can't receive data")

@overrides(LiveEventConnection.add_receive_no_time_callback)
def add_receive_no_time_callback(
self, label, live_event_callback, translate_key=True):
self, label: str, live_event_callback: _RcvCallback,
translate_key: bool = True):
raise ConfigurationException(
"SpynnakerPoissonControlPopulation can't receive data")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Optional
from spinn_utilities.overrides import overrides
from spinn_front_end_common.utilities.exceptions import ConfigurationException
from spynnaker.pyNN.models.neuron import AbstractPyNNNeuronModelStandard
from spynnaker.pyNN.extra_algorithms.splitter_components import (
SplitterAbstractPopulationVertex)
from spynnaker.pyNN.models.neuron import (
AbstractPopulationVertex, AbstractPyNNNeuronModelStandard)
from spynnaker.pyNN.models.defaults import (
default_initial_values, default_parameters)
from spynnaker.pyNN.models.neuron.input_types import InputTypeCurrent
from spynnaker.pyNN.models.neuron.implementations import NeuronImplStandard
from spynnaker.pyNN.models.neuron.neuron_models import (
NeuronModelLeakyIntegrateAndFire)
from spynnaker.pyNN.models.neuron.synapse_types import SynapseTypeExponential
Expand Down Expand Up @@ -96,18 +101,24 @@ def __init__(

@overrides(AbstractPyNNNeuronModelStandard.create_vertex)
def create_vertex(
self, n_neurons, label, *, spikes_per_second,
ring_buffer_sigma, incoming_spike_buffer_size,
n_steps_per_timestep, drop_late_spikes, splitter, seed,
n_colour_bits):
self, n_neurons: int, label: str, *,
spikes_per_second: Optional[float] = None,
ring_buffer_sigma: Optional[float] = None,
incoming_spike_buffer_size: Optional[int] = None,
drop_late_spikes: Optional[bool] = None,
splitter: Optional[SplitterAbstractPopulationVertex] = None,
seed: Optional[int] = None, n_colour_bits: Optional[int] = None,
n_steps_per_timestep: int = 1) -> AbstractPopulationVertex:
if n_neurons != len(self._devices):
raise ConfigurationException(
"Number of neurons does not match number of "
f"devices in {label}")
self._model.n_steps_per_timestep = n_steps_per_timestep
model = self._model
assert isinstance(model, NeuronImplStandard)
model.n_steps_per_timestep = n_steps_per_timestep
max_atoms = self.get_model_max_atoms_per_dimension_per_core()
return ExternalDeviceLifControlVertex(
self._devices, self._create_edges, max_atoms, self._model, self,
self._devices, self._create_edges, max_atoms, model, self,
self._translator, spikes_per_second, label, ring_buffer_sigma,
incoming_spike_buffer_size, drop_late_spikes, splitter, seed,
n_colour_bits)
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
from .abstract_multicast_controllable_device import (
AbstractMulticastControllableDevice)
if TYPE_CHECKING:
from pacman.model.graphs.machine.machine_vertex import MachineVertex
from pacman.model.routing_info.routing_info import RoutingInfo
from spynnaker.pyNN.models.neuron.implementations import AbstractNeuronImpl
from spynnaker.pyNN.models.neuron import AbstractPyNNNeuronModel
from .abstract_ethernet_translator import AbstractEthernetTranslator
Expand Down Expand Up @@ -53,15 +55,15 @@ class ExternalDeviceLifControlVertex(

def __init__(
self, devices: Sequence[AbstractMulticastControllableDevice],
create_edges: bool, max_atoms_per_core: int,
create_edges: bool, max_atoms_per_core: Tuple[int, ...],
neuron_impl: AbstractNeuronImpl,
pynn_model: AbstractPyNNNeuronModel,
translator: Optional[AbstractEthernetTranslator] = None,
spikes_per_second: Optional[float] = None,
label: Optional[str] = None,
ring_buffer_sigma: Optional[float] = None,
incoming_spike_buffer_size: Optional[int] = None,
drop_late_spikes: bool = False,
drop_late_spikes: Optional[bool] = None,
splitter: Optional[SplitterAbstractPopulationVertex] = None,
seed: Optional[int] = None, n_colour_bits: Optional[int] = None):
"""
Expand All @@ -71,7 +73,7 @@ def __init__(
:param bool create_edges:
True if edges to the devices should be added by this dev (set
to False if using the dev over Ethernet using a translator)
:param int max_atoms_per_core:
:param tuple(int, ...) max_atoms_per_core:
:param AbstractNeuronImpl neuron_impl:
:param AbstractPyNNNeuronModel pynn_model:
:param translator:
Expand All @@ -87,6 +89,8 @@ def __init__(
:param int n_colour_bits: The number of colour bits to use
"""
# pylint: disable=too-many-arguments
if drop_late_spikes is None:
drop_late_spikes = False
super().__init__(
len(devices), f"ext_dev{devices}" if label is None else label,
max_atoms_per_core,
Expand Down Expand Up @@ -146,14 +150,15 @@ def get_outgoing_partition_ids(self) -> List[str]:

@overrides(HasCustomAtomKeyMap.get_atom_key_map)
def get_atom_key_map(
self, pre_vertex, partition_id: str, routing_info) -> List[
Tuple[int, int]]:
self, pre_vertex: MachineVertex, partition_id: str,
routing_info: RoutingInfo) -> Iterable[Tuple[int, int]]:
index = self.__indices[partition_id]
device = self.__devices[partition_id]
return [(index, device.device_control_key)]

@overrides(AbstractPopulationVertex.get_fixed_key_and_mask)
def get_fixed_key_and_mask(self, partition_id: str):
def get_fixed_key_and_mask(
self, partition_id: str) -> Optional[BaseKeyAndMask]:
return BaseKeyAndMask(
self.__devices[partition_id].device_control_key,
self._DEFAULT_COMMAND_MASK)
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def __init__(
self.__fixed_mask = self._get_mask(mode)

@overrides(ApplicationSpiNNakerLinkVertex.get_fixed_key_and_mask)
def get_fixed_key_and_mask(self, partition_id) -> BaseKeyAndMask:
def get_fixed_key_and_mask(self, partition_id: str) -> BaseKeyAndMask:
return BaseKeyAndMask(self.__fixed_key, self.__fixed_mask)

def _get_mask(self, mode: str) -> int:
Expand Down
7 changes: 5 additions & 2 deletions spynnaker/pyNN/external_devices_models/icub_retina_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from spinn_utilities.log import FormatAdapter
from pacman.model.graphs.application import Application2DSpiNNakerLinkVertex
from pacman.model.graphs.common import Slice
from pacman.model.graphs.machine import MachineVertex
from pacman.model.routing_info.base_key_and_mask import BaseKeyAndMask
from pacman.utilities.constants import BITS_IN_KEY
from pacman.utilities.utility_calls import is_power_of_2
Expand Down Expand Up @@ -102,13 +103,15 @@ def get_incoming_slice(self, index: int) -> Slice:
return vertex_slice

@overrides(Application2DSpiNNakerLinkVertex.get_machine_fixed_key_and_mask)
def get_machine_fixed_key_and_mask(self, machine_vertex, partition_id):
def get_machine_fixed_key_and_mask(
self, machine_vertex: MachineVertex,
partition_id: str) -> BaseKeyAndMask:
vertex_slice = machine_vertex.vertex_slice
index = self.__index_by_slice[vertex_slice]
return self._get_key_and_mask(self.__base_key, index)

@overrides(Application2DSpiNNakerLinkVertex.get_fixed_key_and_mask)
def get_fixed_key_and_mask(self, partition_id) -> BaseKeyAndMask:
def get_fixed_key_and_mask(self, partition_id: str) -> BaseKeyAndMask:
n_key_bits = BITS_IN_KEY - self._key_shift
key_mask = ((1 << n_key_bits) - 1) << self._key_shift
return BaseKeyAndMask(self.__base_key << self._key_shift, key_mask)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Sequence
from spinn_utilities.overrides import overrides
from spinnman.model.enums import ExecutableType
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.abstract_models import (
AbstractHasAssociatedBinary)
from spinn_front_end_common.abstract_models import (
AbstractGeneratesDataSpecification)
from spinn_front_end_common.interface.ds import DataSpecificationGenerator
from spinn_front_end_common.interface.provenance import (
ProvidesProvenanceDataFromMachineImpl, ProvenanceWriter)
from spinn_front_end_common.interface.simulation import simulation_utilities
Expand Down Expand Up @@ -91,33 +94,34 @@ def __init__(

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

@overrides(AbstractHasAssociatedBinary.get_binary_file_name)
def get_binary_file_name(self):
def get_binary_file_name(self) -> str:
return "robot_motor_control.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(ProvidesProvenanceDataFromMachineImpl._provenance_region_id)
def _provenance_region_id(self):
def _provenance_region_id(self) -> int:
return self._PROVENANCE_REGION

@property
@overrides(ProvidesProvenanceDataFromMachineImpl._n_additional_data_items)
def _n_additional_data_items(self):
def _n_additional_data_items(self) -> int:
return self._PROVENANCE_ELEMENTS

@overrides(
ProvidesProvenanceDataFromMachineImpl.parse_extra_provenance_items)
def parse_extra_provenance_items(
self, label, x, y, p, provenance_data):
self, label: str, x: int, y: int, p: int,
provenance_data: Sequence[int]):
n_buffer_overflows, = provenance_data

with ProvenanceWriter() as db:
Expand All @@ -133,7 +137,8 @@ def parse_extra_provenance_items(
"or decrease the number of neurons per core.")

@overrides(AbstractGeneratesDataSpecification.generate_data_specification)
def generate_data_specification(self, spec, placement):
def generate_data_specification(
self, spec: DataSpecificationGenerator, placement: Placement):
# reserve regions
self.reserve_memory_regions(spec)

Expand All @@ -142,8 +147,10 @@ def generate_data_specification(self, spec, placement):

# handle simulation data
spec.switch_write_focus(self._SYSTEM_REGION)
vertex = placement.vertex
assert isinstance(vertex, AbstractHasAssociatedBinary)
spec.write_array(simulation_utilities.get_simulation_header_array(
placement.vertex.get_binary_file_name()))
vertex.get_binary_file_name()))

# Get the key
routing_info = SpynnakerDataView.get_routing_infos()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Iterable
from spinn_utilities.overrides import overrides
from pacman.model.graphs.application import (
ApplicationSpiNNakerLinkVertex)
from pacman.model.graphs.application import ApplicationVertex
from pacman.model.graphs.application.abstract import (
AbstractOneAppOneMachineVertex)
from spinn_front_end_common.abstract_models import (
Expand Down Expand Up @@ -73,10 +75,11 @@ def __init__(
_MunichMotorDevice(spinnaker_link_id, board_address)]

@overrides(AbstractVertexWithEdgeToDependentVertices.dependent_vertices)
def dependent_vertices(self):
def dependent_vertices(self) -> Iterable[ApplicationVertex]:
return self.__dependent_vertices

@overrides(AbstractVertexWithEdgeToDependentVertices.
edge_partition_identifiers_for_dependent_vertex)
def edge_partition_identifiers_for_dependent_vertex(self, vertex):
def edge_partition_identifiers_for_dependent_vertex(
self, vertex: ApplicationVertex) -> Iterable[str]:
yield self.machine_vertex.MOTOR_PARTITION_ID
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 Iterable, List
from spinn_utilities.overrides import overrides
from pacman.model.routing_info import BaseKeyAndMask
from pacman.model.graphs.application import ApplicationSpiNNakerLinkVertex
Expand Down Expand Up @@ -114,12 +115,12 @@ def __init__(
label=label, board_address=board_address)

@overrides(ApplicationSpiNNakerLinkVertex.get_fixed_key_and_mask)
def get_fixed_key_and_mask(self, partition_id):
def get_fixed_key_and_mask(self, partition_id: str) -> BaseKeyAndMask:
return BaseKeyAndMask(self.__fixed_key, self.__fixed_mask)

@property
@overrides(AbstractSendMeMulticastCommandsVertex.start_resume_commands)
def start_resume_commands(self):
def start_resume_commands(self) -> Iterable[MultiCastCommand]:
# change the retina key it transmits with
# (based off if its right or left)
key_set_command = self._MANAGEMENT_BIT | (
Expand All @@ -144,7 +145,7 @@ def start_resume_commands(self):

@property
@overrides(AbstractSendMeMulticastCommandsVertex.pause_stop_commands)
def pause_stop_commands(self):
def pause_stop_commands(self) -> Iterable[MultiCastCommand]:
# disable retina
disable_command = self._MANAGEMENT_BIT | (
self._RIGHT_RETINA_DISABLE if self.__is_right
Expand All @@ -155,5 +156,5 @@ def pause_stop_commands(self):

@property
@overrides(AbstractSendMeMulticastCommandsVertex.timed_commands)
def timed_commands(self):
def timed_commands(self) -> List[MultiCastCommand]:
return []
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Iterable, List
from spinn_utilities.overrides import overrides
from spinn_front_end_common.abstract_models import (
AbstractSendMeMulticastCommandsVertex)
from spinn_front_end_common.utility_models import MultiCastCommand


class AbstractPushBotRetinaDevice(
Expand All @@ -35,7 +37,7 @@ def __init__(self, protocol, resolution):

@property
@overrides(AbstractSendMeMulticastCommandsVertex.start_resume_commands)
def start_resume_commands(self):
def start_resume_commands(self) -> Iterable[MultiCastCommand]:
# add mode command if not done already
if not self._protocol.sent_mode_command():
yield self._protocol.set_mode()
Expand All @@ -50,10 +52,10 @@ def start_resume_commands(self):

@property
@overrides(AbstractSendMeMulticastCommandsVertex.pause_stop_commands)
def pause_stop_commands(self):
def pause_stop_commands(self) -> Iterable[MultiCastCommand]:
yield self._protocol.disable_retina()

@property
@overrides(AbstractSendMeMulticastCommandsVertex.timed_commands)
def timed_commands(self):
def timed_commands(self) -> List[MultiCastCommand]:
return []
Loading