diff --git a/.github/workflows/python_actions.yml b/.github/workflows/python_actions.yml index 6b6dde6..d6e520d 100644 --- a/.github/workflows/python_actions.yml +++ b/.github/workflows/python_actions.yml @@ -36,6 +36,8 @@ jobs: path: support - 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 @@ -90,3 +92,5 @@ jobs: if: matrix.python-version == 3.12 uses: dieghernan/cff-validator@main + - name: Lint with mypy + run: mypy spinn_gym diff --git a/pyproject.toml b/pyproject.toml index 1c61443..9773fff 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,4 +15,8 @@ [build-system] requires = ["setuptools"] -build-backend = "setuptools.build_meta:" \ No newline at end of file +build-backend = "setuptools.build_meta:" + +[[tool.mypy.overrides]] +module = ["pyNN.*", "quantities", "neo", "scipy", "scipy.*", "lazyarray", "IPython", "matplotlib.*"] +ignore_missing_imports = true diff --git a/spinn_gym/games/breakout/breakout.py b/spinn_gym/games/breakout/breakout.py index 69098e6..f88454f 100644 --- a/spinn_gym/games/breakout/breakout.py +++ b/spinn_gym/games/breakout/breakout.py @@ -36,7 +36,7 @@ class Breakout(SpinnGymApplicationVertex): numpy.random.randint(10000), numpy.random.randint(10000)] - __slots__ = ["__source_vertex"] + __slots__ = ("__source_vertex") def __init__(self, x_factor=16, y_factor=16, width=160, height=128, colour_bits=2, label="Breakout", @@ -60,7 +60,7 @@ def __init__(self, x_factor=16, y_factor=16, width=160, height=128, @property @overrides(SpinnGymApplicationVertex.score_format) - def score_format(self): + def score_format(self) -> type: return numpy.int32 @property diff --git a/spinn_gym/games/breakout/breakout_machine_vertex.py b/spinn_gym/games/breakout/breakout_machine_vertex.py index 9521208..e1ba1a2 100644 --- a/spinn_gym/games/breakout/breakout_machine_vertex.py +++ b/spinn_gym/games/breakout/breakout_machine_vertex.py @@ -14,9 +14,12 @@ # along with this program. If not, see . from enum import Enum +from typing import cast, TYPE_CHECKING from spinn_utilities.overrides import overrides +from pacman.model.placements import Placement + # SpinnFrontEndCommon imports from spinn_front_end_common.utilities import helpful_functions from spinn_front_end_common.abstract_models.\ @@ -27,7 +30,8 @@ import AbstractHasAssociatedBinary from spinn_front_end_common.interface.buffer_management \ import recording_utilities -from spinn_front_end_common.interface.ds import DataType +from spinn_front_end_common.interface.ds import ( + DataSpecificationGenerator, DataType) from spinn_front_end_common.interface.simulation import simulation_utilities from spinn_front_end_common.utilities import constants as \ front_end_common_constants @@ -39,6 +43,9 @@ # spinn_gym imports from spinn_gym.games import SpinnGymMachineVertex +if TYPE_CHECKING: + from .breakout import Breakout + # ---------------------------------------------------------------------------- # BreakoutMachineVertex @@ -54,10 +61,10 @@ class BreakoutMachineVertex(SpinnGymMachineVertex): ('RECORDING', 2), ('PARAMS', 3)]) - __slots__ = ["_x_factor", "_y_factor", "_colour_bits", "_bricking"] + __slots__ = ("_x_factor", "_y_factor", "_colour_bits", "_bricking") def __init__( - self, label, app_vertex, n_neurons, + self, label, app_vertex: 'Breakout', n_neurons, simulation_duration_ms, random_seed, x_factor, y_factor, colour_bits, bricking): """ @@ -96,11 +103,18 @@ def __init__( self._colour_bits = colour_bits self._bricking = bricking + @property + @overrides(SpinnGymMachineVertex.app_vertex) + def app_vertex(self) -> 'Breakout': + # type checked by init + return cast('Breakout', self._app_vertex) + # ------------------------------------------------------------------------ # AbstractGeneratesDataSpecification overrides # ------------------------------------------------------------------------ @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 vertex = placement.vertex @@ -127,6 +141,7 @@ def generate_data_specification(self, spec, placement): spec.comment("\nWriting setup region:\n") spec.switch_write_focus( BreakoutMachineVertex._BREAKOUT_REGIONS.SYSTEM.value) + assert isinstance(vertex, AbstractHasAssociatedBinary) spec.write_array(simulation_utilities.get_simulation_header_array( vertex.get_binary_file_name())) @@ -135,8 +150,10 @@ def generate_data_specification(self, spec, placement): spec.switch_write_focus( BreakoutMachineVertex._BREAKOUT_REGIONS.BREAKOUT.value) routing_info = SpynnakerDataView.get_routing_infos() - spec.write_value(routing_info.get_first_key_from_pre_vertex( - vertex, constants.SPIKE_PARTITION_ID)) + data = routing_info.get_first_key_from_pre_vertex( + vertex, constants.SPIKE_PARTITION_ID) + assert data is not None + spec.write_value(data) if self.app_vertex.source_vertex is None: raise ValueError( "The breakout vertex doesn't have a source vertex!") @@ -168,10 +185,10 @@ def generate_data_specification(self, spec, placement): spec.end_specification() @overrides(SpinnGymMachineVertex.get_recording_region_base_address) - def get_recording_region_base_address(self, placement): + def get_recording_region_base_address(self, placement: Placement) -> int: return helpful_functions.locate_memory_region_for_placement( placement, self._BREAKOUT_REGIONS.RECORDING.value) @overrides(AbstractHasAssociatedBinary.get_binary_file_name) - def get_binary_file_name(self): + def get_binary_file_name(self) -> str: return "breakout.aplx" diff --git a/spinn_gym/games/double_inverted_pendulum/double_pendulum.py b/spinn_gym/games/double_inverted_pendulum/double_pendulum.py index 2b28e64..c438a6f 100644 --- a/spinn_gym/games/double_inverted_pendulum/double_pendulum.py +++ b/spinn_gym/games/double_inverted_pendulum/double_pendulum.py @@ -32,7 +32,7 @@ class DoublePendulum(SpinnGymApplicationVertex): ONE_WEEK_IN_MS = 1000 * 60 * 60 * 24 * 7 # 1 week RANDOM_SEED = [0, 1, 2, 3] - __slots__ = [] + __slots__ = () def __init__( self, encoding=0, time_increment=20, @@ -78,5 +78,5 @@ def __init__( @property @overrides(SpinnGymApplicationVertex.score_format) - def score_format(self): + def score_format(self) -> type: return numpy.float32 diff --git a/spinn_gym/games/double_inverted_pendulum/double_pendulum_machine_vertex.py b/spinn_gym/games/double_inverted_pendulum/double_pendulum_machine_vertex.py index 12bc043..8620fff 100644 --- a/spinn_gym/games/double_inverted_pendulum/double_pendulum_machine_vertex.py +++ b/spinn_gym/games/double_inverted_pendulum/double_pendulum_machine_vertex.py @@ -17,13 +17,16 @@ from spinn_utilities.overrides import overrides +from pacman.model.placements import Placement + # SpinnFrontEndCommon imports from spinn_front_end_common.utilities import helpful_functions from spinn_front_end_common.abstract_models.abstract_has_associated_binary \ import AbstractHasAssociatedBinary from spinn_front_end_common.interface.buffer_management \ import recording_utilities -from spinn_front_end_common.interface.ds import DataType +from spinn_front_end_common.interface.ds import ( + DataSpecificationGenerator, DataType) from spinn_front_end_common.interface.simulation import simulation_utilities from spinn_front_end_common.utilities import constants as \ front_end_common_constants @@ -43,11 +46,11 @@ class DoublePendulumMachineVertex(SpinnGymMachineVertex): PENDULUM_REGION_BYTES = 4 DATA_REGION_BYTES = 17 * 4 - __slots__ = [ + __slots__ = ( "_bin_overlap", "_central", "_encoding", "_force_increments", "_max_firing_rate", "_number_of_bins", "_pole_angle", "_pole2_angle", "_pole_length", "_pole2_length", "_reward_based", "_tau_force", - "_time_increment"] + "_time_increment") _DOUBLE_PENDULUM_REGIONS = Enum( value="_DOUBLE_PENDULUM_REGIONS", @@ -127,7 +130,8 @@ def __init__( # AbstractGeneratesDataSpecification overrides # ------------------------------------------------------------------------ @overrides(SpinnGymMachineVertex.generate_data_specification) - def generate_data_specification(self, spec, placement): + def generate_data_specification( + self, spec: DataSpecificationGenerator, placement: Placement): # pylint: disable=arguments-differ vertex = placement.vertex @@ -154,6 +158,7 @@ def generate_data_specification(self, spec, placement): spec.comment("\nWriting setup region:\n") spec.switch_write_focus( self._DOUBLE_PENDULUM_REGIONS.SYSTEM.value) + assert isinstance(vertex, AbstractHasAssociatedBinary) spec.write_array(simulation_utilities.get_simulation_header_array( vertex.get_binary_file_name())) @@ -162,8 +167,10 @@ def generate_data_specification(self, spec, placement): spec.switch_write_focus( self._DOUBLE_PENDULUM_REGIONS.PENDULUM.value) routing_info = SpynnakerDataView.get_routing_infos() - spec.write_value(routing_info.get_first_key_from_pre_vertex( - vertex, constants.SPIKE_PARTITION_ID)) + data = routing_info.get_first_key_from_pre_vertex( + vertex, constants.SPIKE_PARTITION_ID) + assert data is not None + spec.write_value(data) # Write recording region for score spec.comment("\nWriting double pendulum recording region:\n") @@ -198,10 +205,10 @@ def generate_data_specification(self, spec, placement): spec.end_specification() @overrides(SpinnGymMachineVertex.get_recording_region_base_address) - def get_recording_region_base_address(self, placement): + def get_recording_region_base_address(self, placement: Placement) -> int: return helpful_functions.locate_memory_region_for_placement( placement, self._DOUBLE_PENDULUM_REGIONS.RECORDING.value) @overrides(AbstractHasAssociatedBinary.get_binary_file_name) - def get_binary_file_name(self): + def get_binary_file_name(self) -> str: return "double_inverted_pendulum.aplx" diff --git a/spinn_gym/games/inverted_pendulum/inverted_pendulum.py b/spinn_gym/games/inverted_pendulum/inverted_pendulum.py index 9253d11..91b9ffa 100644 --- a/spinn_gym/games/inverted_pendulum/inverted_pendulum.py +++ b/spinn_gym/games/inverted_pendulum/inverted_pendulum.py @@ -33,7 +33,7 @@ class Pendulum(SpinnGymApplicationVertex): ONE_WEEK_IN_MS = 1000 * 60 * 60 * 24 * 7 # 1 week RANDOM_SEED = [0, 1, 2, 3] - __slots__ = [] + __slots__ = () def __init__(self, encoding=0, time_increment=20, pole_length=1.0, pole_angle=0.1, reward_based=1, @@ -80,5 +80,5 @@ def __init__(self, encoding=0, time_increment=20, @property @overrides(SpinnGymApplicationVertex.score_format) - def score_format(self): + def score_format(self) -> type: return numpy.float32 diff --git a/spinn_gym/games/inverted_pendulum/inverted_pendulum_machine_vertex.py b/spinn_gym/games/inverted_pendulum/inverted_pendulum_machine_vertex.py index 3501fe9..ee52931 100644 --- a/spinn_gym/games/inverted_pendulum/inverted_pendulum_machine_vertex.py +++ b/spinn_gym/games/inverted_pendulum/inverted_pendulum_machine_vertex.py @@ -17,6 +17,8 @@ from spinn_utilities.overrides import overrides +from pacman.model.placements import Placement + # SpinnFrontEndCommon imports from spinn_front_end_common.utilities import helpful_functions from spinn_front_end_common.abstract_models.abstract_has_associated_binary \ @@ -26,7 +28,8 @@ from spinn_front_end_common.abstract_models \ .abstract_generates_data_specification \ import AbstractGeneratesDataSpecification -from spinn_front_end_common.interface.ds import DataType +from spinn_front_end_common.interface.ds import ( + DataSpecificationGenerator, DataType) from spinn_front_end_common.interface.simulation import simulation_utilities from spinn_front_end_common.utilities import constants as \ front_end_common_constants @@ -53,10 +56,10 @@ class PendulumMachineVertex(SpinnGymMachineVertex): ('RECORDING', 2), ('DATA', 3)]) - __slots__ = ["_bin_overlap", "_central", "_encoding", "_force_increments", + __slots__ = ("_bin_overlap", "_central", "_encoding", "_force_increments", "_max_firing_rate", "_number_of_bins", "_pole_angle", "_pole_length", "_reward_based", "_tau_force", - "_time_increment"] + "_time_increment") def __init__(self, label, app_vertex, n_neurons, simulation_duration_ms, random_seed, @@ -125,7 +128,8 @@ def __init__(self, label, app_vertex, n_neurons, # AbstractGeneratesDataSpecification overrides # ------------------------------------------------------------------------ @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 vertex = placement.vertex @@ -152,6 +156,7 @@ def generate_data_specification(self, spec, placement): spec.comment("\nWriting setup region:\n") spec.switch_write_focus( self._PENDULUM_REGIONS.SYSTEM.value) + assert isinstance(vertex, AbstractHasAssociatedBinary) spec.write_array(simulation_utilities.get_simulation_header_array( vertex.get_binary_file_name())) @@ -160,8 +165,10 @@ def generate_data_specification(self, spec, placement): spec.switch_write_focus( self._PENDULUM_REGIONS.PENDULUM.value) routing_info = SpynnakerDataView.get_routing_infos() - spec.write_value(routing_info.get_first_key_from_pre_vertex( - vertex, constants.SPIKE_PARTITION_ID)) + data = routing_info.get_first_key_from_pre_vertex( + vertex, constants.SPIKE_PARTITION_ID) + assert data is not None + spec.write_value(data) # Write recording region for score spec.comment("\nWriting pendulum recording region:\n") @@ -193,10 +200,10 @@ def generate_data_specification(self, spec, placement): # End-of-Spec: spec.end_specification() - def get_recording_region_base_address(self, placement): + def get_recording_region_base_address(self, placement: Placement): return helpful_functions.locate_memory_region_for_placement( placement, self._PENDULUM_REGIONS.RECORDING.value) @overrides(AbstractHasAssociatedBinary.get_binary_file_name) - def get_binary_file_name(self): + def get_binary_file_name(self) -> str: return "inverted_pendulum.aplx" diff --git a/spinn_gym/games/logic/logic.py b/spinn_gym/games/logic/logic.py index d8575cd..0c4e4a1 100644 --- a/spinn_gym/games/logic/logic.py +++ b/spinn_gym/games/logic/logic.py @@ -41,7 +41,7 @@ class Logic(SpinnGymApplicationVertex): numpy.random.randint(10000), numpy.random.randint(10000)] - __slots__ = [] + __slots__ = () def __init__( self, truth_table, input_sequence, rate_on=20.0, rate_off=5.0, @@ -66,5 +66,5 @@ def __init__( @property @overrides(SpinnGymApplicationVertex.score_format) - def score_format(self): + def score_format(self) -> type: return numpy.int32 diff --git a/spinn_gym/games/logic/logic_machine_vertex.py b/spinn_gym/games/logic/logic_machine_vertex.py index 34d1775..7c2f667 100644 --- a/spinn_gym/games/logic/logic_machine_vertex.py +++ b/spinn_gym/games/logic/logic_machine_vertex.py @@ -18,6 +18,8 @@ from spinn_utilities.overrides import overrides +from pacman.model.placements import Placement + # SpinnFrontEndCommon imports from spinn_front_end_common.utilities import helpful_functions from spinn_front_end_common.abstract_models.abstract_has_associated_binary \ @@ -27,7 +29,8 @@ from spinn_front_end_common.abstract_models \ .abstract_generates_data_specification \ import AbstractGeneratesDataSpecification -from spinn_front_end_common.interface.ds import DataType +from spinn_front_end_common.interface.ds import ( + DataSpecificationGenerator, DataType) from spinn_front_end_common.interface.simulation import simulation_utilities from spinn_front_end_common.utilities import constants as \ front_end_common_constants @@ -54,8 +57,8 @@ class LogicMachineVertex(SpinnGymMachineVertex): ('RECORDING', 2), ('DATA', 3)]) - __slots__ = ["_input_sequence", "_no_inputs", "_rate_on", "_rate_off", - "_score_delay", "_stochastic", "_truth_table"] + __slots__ = ("_input_sequence", "_no_inputs", "_rate_on", "_rate_off", + "_score_delay", "_stochastic", "_truth_table") def __init__(self, label, app_vertex, n_neurons, simulation_duration_ms, random_seed, @@ -108,7 +111,8 @@ def __init__(self, label, app_vertex, n_neurons, # AbstractGeneratesDataSpecification overrides # ------------------------------------------------------------------------ @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 vertex = placement.vertex @@ -137,6 +141,7 @@ def generate_data_specification(self, spec, placement): spec.comment("\nWriting setup region:\n") spec.switch_write_focus( self._LOGIC_REGIONS.SYSTEM.value) + assert isinstance(vertex, AbstractHasAssociatedBinary) spec.write_array(simulation_utilities.get_simulation_header_array( vertex.get_binary_file_name())) @@ -145,8 +150,10 @@ def generate_data_specification(self, spec, placement): spec.switch_write_focus( self._LOGIC_REGIONS.LOGIC.value) routing_info = SpynnakerDataView.get_routing_infos() - spec.write_value(routing_info.get_first_key_from_pre_vertex( - vertex, constants.SPIKE_PARTITION_ID)) + first_key = routing_info.get_first_key_from_pre_vertex( + vertex, constants.SPIKE_PARTITION_ID) + assert first_key is not None + spec.write_value(first_key) # Write recording region for score spec.comment("\nWriting logic recording region:\n") @@ -182,5 +189,5 @@ def get_recording_region_base_address(self, placement): placement, self._LOGIC_REGIONS.RECORDING.value) @overrides(AbstractHasAssociatedBinary.get_binary_file_name) - def get_binary_file_name(self): + def get_binary_file_name(self) -> str: return "logic.aplx" diff --git a/spinn_gym/games/multi_arm_bandit/bandit.py b/spinn_gym/games/multi_arm_bandit/bandit.py index 07efc1b..47e155d 100644 --- a/spinn_gym/games/multi_arm_bandit/bandit.py +++ b/spinn_gym/games/multi_arm_bandit/bandit.py @@ -36,7 +36,7 @@ class Bandit(SpinnGymApplicationVertex): numpy.random.randint(10000)] ARMS = [0.1, 0.9] - __slots__ = [] + __slots__ = () def __init__(self, arms=None, reward_delay=200.0, reward_based=1, rate_on=20.0, rate_off=5.0, stochastic=1, @@ -59,5 +59,5 @@ def __init__(self, arms=None, reward_delay=200.0, reward_based=1, @property @overrides(SpinnGymApplicationVertex.score_format) - def score_format(self): + def score_format(self) -> type: return numpy.int32 diff --git a/spinn_gym/games/multi_arm_bandit/bandit_machine_vertex.py b/spinn_gym/games/multi_arm_bandit/bandit_machine_vertex.py index f116819..0fe4b71 100644 --- a/spinn_gym/games/multi_arm_bandit/bandit_machine_vertex.py +++ b/spinn_gym/games/multi_arm_bandit/bandit_machine_vertex.py @@ -18,6 +18,8 @@ from spinn_utilities.overrides import overrides +from pacman.model.placements import Placement + # SpinnFrontEndCommon imports from spinn_front_end_common.utilities import helpful_functions from spinn_front_end_common.abstract_models.abstract_has_associated_binary \ @@ -27,7 +29,8 @@ from spinn_front_end_common.abstract_models \ .abstract_generates_data_specification \ import AbstractGeneratesDataSpecification -from spinn_front_end_common.interface.ds import DataType +from spinn_front_end_common.interface.ds import ( + DataSpecificationGenerator, DataType) from spinn_front_end_common.interface.simulation import simulation_utilities from spinn_front_end_common.utilities import constants as \ front_end_common_constants @@ -54,8 +57,8 @@ class BanditMachineVertex(SpinnGymMachineVertex): ('RECORDING', 2), ('ARMS', 3)]) - __slots__ = ["_arms", "_constant_input", "_no_arms", "_rate_off", - "_rate_on", "_reward_based", "_reward_delay", "_stochastic"] + __slots__ = ("_arms", "_constant_input", "_no_arms", "_rate_off", + "_rate_on", "_reward_based", "_reward_delay", "_stochastic") def __init__(self, label, app_vertex, n_neurons, simulation_duration_ms, random_seed, arms, reward_delay, reward_based, rate_on, @@ -119,7 +122,8 @@ def __init__(self, label, app_vertex, n_neurons, simulation_duration_ms, # AbstractGeneratesDataSpecification overrides # ------------------------------------------------------------------------ @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 vertex = placement.vertex @@ -147,6 +151,7 @@ def generate_data_specification(self, spec, placement): spec.comment("\nWriting setup region:\n") spec.switch_write_focus( self._BANDIT_REGIONS.SYSTEM.value) + assert isinstance(vertex, AbstractHasAssociatedBinary) spec.write_array(simulation_utilities.get_simulation_header_array( vertex.get_binary_file_name())) @@ -155,8 +160,10 @@ def generate_data_specification(self, spec, placement): spec.switch_write_focus( self._BANDIT_REGIONS.BANDIT.value) routing_info = SpynnakerDataView.get_routing_infos() - spec.write_value(routing_info.get_first_key_from_pre_vertex( - vertex, constants.SPIKE_PARTITION_ID)) + first_key = routing_info.get_first_key_from_pre_vertex( + vertex, constants.SPIKE_PARTITION_ID) + assert first_key is not None + spec.write_value(first_key) # Write recording region for score spec.comment("\nWriting bandit recording region:\n") @@ -192,5 +199,5 @@ def get_recording_region_base_address(self, placement): placement, self._BANDIT_REGIONS.RECORDING.value) @overrides(AbstractHasAssociatedBinary.get_binary_file_name) - def get_binary_file_name(self): + def get_binary_file_name(self) -> str: return "bandit.aplx" diff --git a/spinn_gym/games/spinn_gym_application_vertex.py b/spinn_gym/games/spinn_gym_application_vertex.py index 1ffb58c..8e1d0de 100644 --- a/spinn_gym/games/spinn_gym_application_vertex.py +++ b/spinn_gym/games/spinn_gym_application_vertex.py @@ -15,7 +15,7 @@ import numpy -from spinn_utilities.abstract_base import abstractproperty +from spinn_utilities.abstract_base import abstractmethod from spinn_utilities.overrides import overrides # PACMAN imports @@ -31,7 +31,7 @@ class SpinnGymApplicationVertex( AbstractOneAppOneMachineVertex, PopulationApplicationVertex): - __slots__ = [] + __slots__ = () def __init__(self, machine_vertex, label, n_atoms): """ @@ -48,7 +48,7 @@ def __init__(self, machine_vertex, label, n_atoms): machine_vertex, label, n_atoms) @overrides(PopulationApplicationVertex.get_units) - def get_units(self, name): + def get_units(self, name: str) -> str: if name == "score": return "" return super(SpinnGymApplicationVertex, self).get_units(name) @@ -91,11 +91,13 @@ def describe(self): } return context - @abstractproperty - def score_format(self): + @property + @abstractmethod + def score_format(self) -> type: """ The numpy format for the scores data """ + raise NotImplementedError def __str__(self): return "{} with {} atoms".format(self._label, self.n_atoms) diff --git a/spinn_gym/games/spinn_gym_machine_vertex.py b/spinn_gym/games/spinn_gym_machine_vertex.py index 855c2cd..8513eea 100644 --- a/spinn_gym/games/spinn_gym_machine_vertex.py +++ b/spinn_gym/games/spinn_gym_machine_vertex.py @@ -14,6 +14,7 @@ # along with this program. If not, see . import math +from typing import List from spinn_utilities.overrides import overrides from spinnman.model.enums import ExecutableType @@ -38,13 +39,13 @@ class SpinnGymMachineVertex(MachineVertex, AbstractGeneratesDataSpecification, AbstractReceiveBuffersToHost, AbstractHasAssociatedBinary): - __slots__ = [ + __slots__ = ( # list of 4 numbers to be the random seeds for the c code "_random_seed", # size of recording region "_recording_size", # sdram needed for this vertex - "_sdram_required"] + "_sdram_required") def __init__(self, label, app_vertex, n_neurons, region_bytes, simulation_duration_ms, random_seed): @@ -88,13 +89,13 @@ def __init__(self, label, app_vertex, n_neurons, @property @overrides(MachineVertex.sdram_required) - def sdram_required(self): + def sdram_required(self) -> ConstantSDRAM: return self._sdram_required @overrides(AbstractReceiveBuffersToHost.get_recorded_region_ids) - def get_recorded_region_ids(self): + def get_recorded_region_ids(self) -> List[int]: return [0] @overrides(AbstractHasAssociatedBinary.get_binary_start_type) - def get_binary_start_type(self): + def get_binary_start_type(self) -> ExecutableType: return ExecutableType.USES_SIMULATION_INTERFACE diff --git a/spinn_gym/games/store_recall/store_recall.py b/spinn_gym/games/store_recall/store_recall.py index 710e9e3..d4a584a 100644 --- a/spinn_gym/games/store_recall/store_recall.py +++ b/spinn_gym/games/store_recall/store_recall.py @@ -36,7 +36,7 @@ class Recall(SpinnGymApplicationVertex): numpy.random.randint(10000), numpy.random.randint(10000)] - __slots__ = [] + __slots__ = () def __init__( self, rate_on=50.0, rate_off=0.0, pop_size=1, prob_command=1.0/6.0, @@ -57,5 +57,5 @@ def __init__( @property @overrides(SpinnGymApplicationVertex.score_format) - def score_format(self): + def score_format(self) -> type: return numpy.int32 diff --git a/spinn_gym/games/store_recall/store_recall_machine_vertex.py b/spinn_gym/games/store_recall/store_recall_machine_vertex.py index a1bcea1..c02c67c 100644 --- a/spinn_gym/games/store_recall/store_recall_machine_vertex.py +++ b/spinn_gym/games/store_recall/store_recall_machine_vertex.py @@ -17,6 +17,8 @@ from spinn_utilities.overrides import overrides +from pacman.model.placements import Placement + # SpinnFrontEndCommon imports from spinn_front_end_common.utilities import helpful_functions from spinn_front_end_common.abstract_models.abstract_has_associated_binary \ @@ -26,7 +28,8 @@ from spinn_front_end_common.abstract_models \ .abstract_generates_data_specification \ import AbstractGeneratesDataSpecification -from spinn_front_end_common.interface.ds import DataType +from spinn_front_end_common.interface.ds import ( + DataSpecificationGenerator, DataType) from spinn_front_end_common.interface.simulation import simulation_utilities from spinn_front_end_common.utilities import constants as \ front_end_common_constants @@ -53,9 +56,9 @@ class RecallMachineVertex(SpinnGymMachineVertex): ('RECORDING', 2), ('DATA', 3)]) - __slots__ = ["_prob_command", "_prob_in_change", "_pop_size", + __slots__ = ("_prob_command", "_prob_in_change", "_pop_size", "_rate_off", "_rate_on", "_reward", "_stochastic", - "_time_period"] + "_time_period") def __init__(self, label, app_vertex, n_neurons, simulation_duration_ms, random_seed, @@ -114,7 +117,8 @@ def __init__(self, label, app_vertex, n_neurons, # AbstractGeneratesDataSpecification overrides # ------------------------------------------------------------------------ @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 vertex = placement.vertex @@ -141,6 +145,7 @@ def generate_data_specification(self, spec, placement): spec.comment("\nWriting setup region:\n") spec.switch_write_focus( self._RECALL_REGIONS.SYSTEM.value) + assert isinstance(vertex, AbstractHasAssociatedBinary) spec.write_array(simulation_utilities.get_simulation_header_array( vertex.get_binary_file_name())) @@ -149,8 +154,10 @@ def generate_data_specification(self, spec, placement): spec.switch_write_focus( self._RECALL_REGIONS.RECALL.value) routing_info = SpynnakerDataView.get_routing_infos() - spec.write_value(routing_info.get_first_key_from_pre_vertex( - vertex, constants.SPIKE_PARTITION_ID)) + data = routing_info.get_first_key_from_pre_vertex( + vertex, constants.SPIKE_PARTITION_ID) + assert data is not None + spec.write_value(data) # Write recording region for score spec.comment("\nWriting recall recording region:\n") @@ -184,5 +191,5 @@ def get_recording_region_base_address(self, placement): placement, self._RECALL_REGIONS.RECORDING.value) @overrides(AbstractHasAssociatedBinary.get_binary_file_name) - def get_binary_file_name(self): + def get_binary_file_name(self) -> str: return "store_recall.aplx"