From 5c9561696aaae2987e53d397f941a63ab12ef4a3 Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Tue, 2 Jan 2024 09:40:56 +0000 Subject: [PATCH 1/9] overrides typing --- mcmc/mcmc_cholesky_vertex.py | 12 ++++++++---- mcmc/mcmc_coordinator_vertex.py | 16 ++++++++++------ mcmc/mcmc_model.py | 9 ++++++--- mcmc/mcmc_root_finder_vertex.py | 12 ++++++++---- mcmc/mcmc_vertex.py | 14 +++++++++----- mcmc_examples/arma/arma_fixed_point_model.py | 7 ++++--- mcmc_examples/arma/arma_float_model.py | 7 ++++--- mcmc_examples/arma/arma_model.py | 7 ++++--- .../lighthouse/lighthouse_fixed_point_model.py | 7 ++++--- .../lighthouse/lighthouse_float_model.py | 7 ++++--- mcmc_examples/lighthouse/lighthouse_model.py | 7 ++++--- 11 files changed, 65 insertions(+), 40 deletions(-) diff --git a/mcmc/mcmc_cholesky_vertex.py b/mcmc/mcmc_cholesky_vertex.py index 7e95fc7..7d4aae2 100644 --- a/mcmc/mcmc_cholesky_vertex.py +++ b/mcmc/mcmc_cholesky_vertex.py @@ -17,11 +17,14 @@ from pacman.model.resources import ConstantSDRAM from spinn_utilities.overrides import overrides +from pacman.model.placements import Placement + from spinn_front_end_common.abstract_models.abstract_has_associated_binary \ import AbstractHasAssociatedBinary from spinn_front_end_common.abstract_models\ .abstract_generates_data_specification \ import AbstractGeneratesDataSpecification +from spinn_front_end_common.interface.ds import DataSpecificationGenerator from spinn_front_end_common.utilities.utility_objs.executable_type \ import ExecutableType @@ -61,20 +64,21 @@ def __init__( @property @overrides(MachineVertex.sdram_required) - def sdram_required(self): + def sdram_required(self) -> ConstantSDRAM: return ConstantSDRAM(self._n_parameter_bytes) @overrides(AbstractHasAssociatedBinary.get_binary_file_name) - def get_binary_file_name(self): + def get_binary_file_name(self) -> str: return "mcmc_cholesky.aplx" @overrides(AbstractHasAssociatedBinary.get_binary_start_type) - def get_binary_start_type(self): + def get_binary_start_type(self) -> ExecutableType: return ExecutableType.SYNC @overrides( AbstractGeneratesDataSpecification.generate_data_specification) - def generate_data_specification(self, spec, placement): + def generate_data_specification( + self, spec: DataSpecificationGenerator, placement: Placement): # Reserve and write the parameters region spec.reserve_memory_region( diff --git a/mcmc/mcmc_coordinator_vertex.py b/mcmc/mcmc_coordinator_vertex.py index b285dc2..1b8b084 100644 --- a/mcmc/mcmc_coordinator_vertex.py +++ b/mcmc/mcmc_coordinator_vertex.py @@ -17,13 +17,16 @@ from pacman.model.resources import ConstantSDRAM from spinn_utilities.overrides import overrides +from pacman.model.placements import Placement + from spinn_front_end_common.abstract_models.abstract_has_associated_binary \ import AbstractHasAssociatedBinary from spinn_front_end_common.abstract_models\ .abstract_generates_data_specification \ import AbstractGeneratesDataSpecification from spinn_front_end_common.data import FecDataView -from spinn_front_end_common.interface.ds import DataType +from spinn_front_end_common.interface.ds import ( + DataSpecificationGenerator, DataType) from spinn_front_end_common.utilities.utility_objs.executable_type \ import ExecutableType from spinn_utilities.progress_bar import ProgressBar @@ -187,22 +190,23 @@ def acknowledge_partition_name(self): @property @overrides(MachineVertex.sdram_required) - def sdram_required(self): + def sdram_required(self) -> ConstantSDRAM: sdram = self._N_PARAMETER_BYTES + self._data_size sdram += len(self._mcmc_vertices) * self._KEY_ELEMENT_TYPE.size return ConstantSDRAM(sdram) @overrides(AbstractHasAssociatedBinary.get_binary_file_name) - def get_binary_file_name(self): + def get_binary_file_name(self) -> str: return "mcmc_coordinator.aplx" @overrides(AbstractHasAssociatedBinary.get_binary_start_type) - def get_binary_start_type(self): + def get_binary_start_type(self) -> ExecutableType: return ExecutableType.SYNC @overrides( AbstractGeneratesDataSpecification.generate_data_specification) - def generate_data_specification(self, spec, placement): + def generate_data_specification( + self, spec: DataSpecificationGenerator, placement: Placement): routing_info = FecDataView.get_routing_infos() # Reserve and write the parameters region @@ -265,7 +269,7 @@ def generate_data_specification(self, spec, placement): spec.end_specification() @overrides(MachineVertex.get_n_keys_for_partition) - def get_n_keys_for_partition(self, partition_id): + def get_n_keys_for_partition(self, partition_id: str) -> int: return self._n_sequences def read_samples(self, buffer_manager): diff --git a/mcmc/mcmc_model.py b/mcmc/mcmc_model.py index a8d2e0f..888c8a5 100644 --- a/mcmc/mcmc_model.py +++ b/mcmc/mcmc_model.py @@ -13,28 +13,31 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +from typing import List from spinn_utilities.abstract_base import AbstractBase from spinn_utilities.abstract_base import abstractmethod +from mcmc.mcmc_parameter import MCMCParameter +from mcmc.mcmc_state_variable import MCMCStateVariable class MCMCModel(object, metaclass=AbstractBase): @abstractmethod - def get_parameters(self): + def get_parameters(self) -> List[MCMCParameter]: """ Get the parameters of the model :rtype: list of :py:class:`mcmc.mcmc_parameter.MCMCParameter` """ @abstractmethod - def get_state_variables(self): + def get_state_variables(self) -> List[MCMCStateVariable]: """ Get the state variables of the model :rtype: list of :py:class:`mcmc.mcmc_state_variable.MCMCStateVariable` """ @abstractmethod - def get_binary_name(self): + def get_binary_name(self) -> str: """ Get the name of the binary compiled with this model :rtype: str diff --git a/mcmc/mcmc_root_finder_vertex.py b/mcmc/mcmc_root_finder_vertex.py index ba922a8..a2fde6f 100644 --- a/mcmc/mcmc_root_finder_vertex.py +++ b/mcmc/mcmc_root_finder_vertex.py @@ -17,11 +17,14 @@ from pacman.model.resources import ConstantSDRAM from spinn_utilities.overrides import overrides +from pacman.model.placements import Placement + from spinn_front_end_common.abstract_models.abstract_has_associated_binary \ import AbstractHasAssociatedBinary from spinn_front_end_common.abstract_models\ .abstract_generates_data_specification \ import AbstractGeneratesDataSpecification +from spinn_front_end_common.interface.ds import DataSpecificationGenerator from spinn_front_end_common.utilities.utility_objs.executable_type \ import ExecutableType @@ -60,20 +63,21 @@ def __init__( @property @overrides(MachineVertex.sdram_required) - def sdram_required(self): + def sdram_required(self) -> ConstantSDRAM: return ConstantSDRAM(self._n_parameter_bytes) @overrides(AbstractHasAssociatedBinary.get_binary_file_name) - def get_binary_file_name(self): + def get_binary_file_name(self) -> str: return "mcmc_root_finder.aplx" @overrides(AbstractHasAssociatedBinary.get_binary_start_type) - def get_binary_start_type(self): + def get_binary_start_type(self) -> ExecutableType: return ExecutableType.SYNC @overrides( AbstractGeneratesDataSpecification.generate_data_specification) - def generate_data_specification(self, spec, placement): + def generate_data_specification( + self, spec: DataSpecificationGenerator, placement: Placement): # Reserve and write the parameters region spec.reserve_memory_region( diff --git a/mcmc/mcmc_vertex.py b/mcmc/mcmc_vertex.py index e625a59..f5a0c9b 100644 --- a/mcmc/mcmc_vertex.py +++ b/mcmc/mcmc_vertex.py @@ -17,6 +17,8 @@ from pacman.model.resources import ConstantSDRAM from spinn_utilities.overrides import overrides +from pacman.model.placements import Placement + from spinn_front_end_common.abstract_models.abstract_has_associated_binary \ import AbstractHasAssociatedBinary from spinn_front_end_common.abstract_models\ @@ -25,7 +27,8 @@ from spinn_front_end_common.data import FecDataView from spinn_front_end_common.interface.buffer_management.buffer_models\ .abstract_receive_buffers_to_host import AbstractReceiveBuffersToHost -from spinn_front_end_common.interface.ds import DataType +from spinn_front_end_common.interface.ds import ( + DataSpecificationGenerator, DataType) from spinn_front_end_common.utilities import helpful_functions from spinn_front_end_common.interface.buffer_management \ import recording_utilities @@ -195,20 +198,21 @@ def cholesky_result_partition_name(self): @property @overrides(MachineVertex.sdram_required) - def sdram_required(self): + def sdram_required(self) -> ConstantSDRAM: return ConstantSDRAM(self._sdram_usage) @overrides(AbstractHasAssociatedBinary.get_binary_file_name) - def get_binary_file_name(self): + def get_binary_file_name(self) -> str: return self._model.get_binary_name() @overrides(AbstractHasAssociatedBinary.get_binary_start_type) - def get_binary_start_type(self): + def get_binary_start_type(self) -> ExecutableType: return ExecutableType.SYNC @overrides( AbstractGeneratesDataSpecification.generate_data_specification) - def generate_data_specification(self, spec, placement): + def generate_data_specification( + self, spec: DataSpecificationGenerator, placement: Placement): routing_info = FecDataView.get_routing_infos() # Reserve and write the recording regions diff --git a/mcmc_examples/arma/arma_fixed_point_model.py b/mcmc_examples/arma/arma_fixed_point_model.py index 29b182d..59d06a4 100644 --- a/mcmc_examples/arma/arma_fixed_point_model.py +++ b/mcmc_examples/arma/arma_fixed_point_model.py @@ -13,6 +13,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +from typing import List from spinn_utilities.overrides import overrides from spinn_front_end_common.interface.ds import DataType @@ -41,11 +42,11 @@ def __init__( self._q_jump_scale = q_jump_scale @overrides(MCMCModel.get_binary_name) - def get_binary_name(self): + def get_binary_name(self) -> str: return "arma.aplx" @overrides(MCMCModel.get_parameters) - def get_parameters(self): + def get_parameters(self) -> List[MCMCParameter]: return [ MCMCParameter(self._parameters, DataType.S1615), # array ? MCMCParameter(self._p_jump_scale, DataType.S1615), @@ -53,7 +54,7 @@ def get_parameters(self): ] @overrides(MCMCModel.get_state_variables) - def get_state_variables(self): + def get_state_variables(self) -> List[MCMCStateVariable]: return [ MCMCStateVariable("order_p", 10, DataType.S1615), # check type MCMCStateVariable("order_q", 10, DataType.S1615) diff --git a/mcmc_examples/arma/arma_float_model.py b/mcmc_examples/arma/arma_float_model.py index 63632a2..a0f358b 100644 --- a/mcmc_examples/arma/arma_float_model.py +++ b/mcmc_examples/arma/arma_float_model.py @@ -13,6 +13,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +from typing import List from spinn_utilities.overrides import overrides from mcmc.mcmc_model import MCMCModel @@ -40,11 +41,11 @@ def __init__( self._cholesky = cholesky @overrides(MCMCModel.get_binary_name) - def get_binary_name(self): + def get_binary_name(self) -> str: return "arma.aplx" @overrides(MCMCModel.get_parameters) - def get_parameters(self): + def get_parameters(self) -> List[MCMCParameter]: # Best here to convert the arrays into individual values return_params = [] for i in range(len(self._jump_scale)): @@ -54,7 +55,7 @@ def get_parameters(self): return return_params @overrides(MCMCModel.get_state_variables) - def get_state_variables(self): + def get_state_variables(self)-> List[MCMCStateVariable]: # Best here to convert the arrays into individual values return_state_vars = [] for i in range(len(self._parameters)): diff --git a/mcmc_examples/arma/arma_model.py b/mcmc_examples/arma/arma_model.py index cb530c0..1093ea4 100644 --- a/mcmc_examples/arma/arma_model.py +++ b/mcmc_examples/arma/arma_model.py @@ -13,6 +13,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +from typing import List from spinn_utilities.overrides import overrides from mcmc.mcmc_model import MCMCModel @@ -42,11 +43,11 @@ def __init__( self._q_jump_scale = q_jump_scale @overrides(MCMCModel.get_binary_name) - def get_binary_name(self): + def get_binary_name(self) -> str: return "arma.aplx" @overrides(MCMCModel.get_parameters) - def get_parameters(self): + def get_parameters(self) -> List[MCMCParameter]: # It's probably best here to convert the arrays into individual values? return_params = [] for i in range(len(self._p_jump_scale)): @@ -59,7 +60,7 @@ def get_parameters(self): return return_params @overrides(MCMCModel.get_state_variables) - def get_state_variables(self): + def get_state_variables(self)-> List[MCMCStateVariable]: # It's probably best here to convert the arrays into individual values? return_state_vars = [] for i in range(len(self._parameters)): diff --git a/mcmc_examples/lighthouse/lighthouse_fixed_point_model.py b/mcmc_examples/lighthouse/lighthouse_fixed_point_model.py index 89ee579..1deb7fb 100644 --- a/mcmc_examples/lighthouse/lighthouse_fixed_point_model.py +++ b/mcmc_examples/lighthouse/lighthouse_fixed_point_model.py @@ -13,6 +13,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +from typing import List from spinn_utilities.overrides import overrides from spinn_front_end_common.interface.ds import DataType @@ -51,11 +52,11 @@ def __init__( self._cholesky = cholesky @overrides(MCMCModel.get_binary_name) - def get_binary_name(self): + def get_binary_name(self) -> str: return "lighthouse.aplx" @overrides(MCMCModel.get_parameters) - def get_parameters(self): + def get_parameters(self) -> List[MCMCParameter]: return [ MCMCParameter(self._alpha_jump_scale, DataType.S1615), MCMCParameter(self._beta_jump_scale, DataType.S1615), @@ -66,7 +67,7 @@ def get_parameters(self): ] @overrides(MCMCModel.get_state_variables) - def get_state_variables(self): + def get_state_variables(self) -> List[MCMCStateVariable]: return [ MCMCStateVariable("alpha", 0.0, DataType.S1615), MCMCStateVariable("beta", 1.0, DataType.S1615) diff --git a/mcmc_examples/lighthouse/lighthouse_float_model.py b/mcmc_examples/lighthouse/lighthouse_float_model.py index 77c857a..1427b66 100644 --- a/mcmc_examples/lighthouse/lighthouse_float_model.py +++ b/mcmc_examples/lighthouse/lighthouse_float_model.py @@ -13,6 +13,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +from typing import List from spinn_utilities.overrides import overrides from mcmc.mcmc_model import MCMCModel @@ -51,11 +52,11 @@ def __init__( self._cholesky = cholesky @overrides(MCMCModel.get_binary_name) - def get_binary_name(self): + def get_binary_name(self) -> str: return "lighthouse.aplx" @overrides(MCMCModel.get_parameters) - def get_parameters(self): + def get_parameters(self) -> List[MCMCParameter]: return [ MCMCParameter(self._alpha_jump_scale, numpy.float32), MCMCParameter(self._beta_jump_scale, numpy.float32), @@ -66,7 +67,7 @@ def get_parameters(self): ] @overrides(MCMCModel.get_state_variables) - def get_state_variables(self): + def get_state_variables(self) -> List[MCMCStateVariable]: return [ MCMCStateVariable("alpha", 0.0, numpy.float32), MCMCStateVariable("beta", 1.0, numpy.float32) diff --git a/mcmc_examples/lighthouse/lighthouse_model.py b/mcmc_examples/lighthouse/lighthouse_model.py index 3129aea..78466fd 100644 --- a/mcmc_examples/lighthouse/lighthouse_model.py +++ b/mcmc_examples/lighthouse/lighthouse_model.py @@ -13,6 +13,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +from typing import List from spinn_utilities.overrides import overrides from mcmc.mcmc_model import MCMCModel @@ -51,11 +52,11 @@ def __init__( self._cholesky = cholesky @overrides(MCMCModel.get_binary_name) - def get_binary_name(self): + def get_binary_name(self) -> str: return "lighthouse.aplx" @overrides(MCMCModel.get_parameters) - def get_parameters(self): + def get_parameters(self) -> List[MCMCParameter]: return [ MCMCParameter(self._alpha_jump_scale, numpy.float64), MCMCParameter(self._beta_jump_scale, numpy.float64), @@ -66,7 +67,7 @@ def get_parameters(self): ] @overrides(MCMCModel.get_state_variables) - def get_state_variables(self): + def get_state_variables(self) -> List[MCMCStateVariable]: return [ MCMCStateVariable("alpha", 0.0, numpy.float64), MCMCStateVariable("beta", 1.0, numpy.float64) From 27cd769fa1e03a68552e060735ce94418184ecbd Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Tue, 2 Jan 2024 09:47:00 +0000 Subject: [PATCH 2/9] flake8 --- mcmc_examples/arma/arma_float_model.py | 2 +- mcmc_examples/arma/arma_model.py | 2 +- mcmc_examples/lighthouse/lighthouse_float_model.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mcmc_examples/arma/arma_float_model.py b/mcmc_examples/arma/arma_float_model.py index a0f358b..2fd623b 100644 --- a/mcmc_examples/arma/arma_float_model.py +++ b/mcmc_examples/arma/arma_float_model.py @@ -55,7 +55,7 @@ def get_parameters(self) -> List[MCMCParameter]: return return_params @overrides(MCMCModel.get_state_variables) - def get_state_variables(self)-> List[MCMCStateVariable]: + def get_state_variables(self) -> List[MCMCStateVariable]: # Best here to convert the arrays into individual values return_state_vars = [] for i in range(len(self._parameters)): diff --git a/mcmc_examples/arma/arma_model.py b/mcmc_examples/arma/arma_model.py index 1093ea4..3b7e6f8 100644 --- a/mcmc_examples/arma/arma_model.py +++ b/mcmc_examples/arma/arma_model.py @@ -60,7 +60,7 @@ def get_parameters(self) -> List[MCMCParameter]: return return_params @overrides(MCMCModel.get_state_variables) - def get_state_variables(self)-> List[MCMCStateVariable]: + def get_state_variables(self) -> List[MCMCStateVariable]: # It's probably best here to convert the arrays into individual values? return_state_vars = [] for i in range(len(self._parameters)): diff --git a/mcmc_examples/lighthouse/lighthouse_float_model.py b/mcmc_examples/lighthouse/lighthouse_float_model.py index 1427b66..6fd681a 100644 --- a/mcmc_examples/lighthouse/lighthouse_float_model.py +++ b/mcmc_examples/lighthouse/lighthouse_float_model.py @@ -56,7 +56,7 @@ def get_binary_name(self) -> str: return "lighthouse.aplx" @overrides(MCMCModel.get_parameters) - def get_parameters(self) -> List[MCMCParameter]: + def get_parameters(self) -> List[MCMCParameter]: return [ MCMCParameter(self._alpha_jump_scale, numpy.float32), MCMCParameter(self._beta_jump_scale, numpy.float32), From 8b755ebd5ebc4d53c66c1e8a684f89b2bcbd9ea2 Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Mon, 8 Jan 2024 08:24:58 +0000 Subject: [PATCH 3/9] activate mypy --- .github/workflows/python_actions.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/python_actions.yml b/.github/workflows/python_actions.yml index 72376f8..aa25c86 100644 --- a/.github/workflows/python_actions.yml +++ b/.github/workflows/python_actions.yml @@ -78,6 +78,9 @@ jobs: if: matrix.python-version == 3.12 uses: ./support/actions/check-copyrights + - name: Lint with mypy + run: mypy $BASE_PKG + # # Add the following as required in the future # - name: Validate XML # if: matrix.python-version == 3.8 From 6ac0b567cdcbe4953e6de2ae143ee3d35365dbe4 Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Mon, 8 Jan 2024 09:33:59 +0000 Subject: [PATCH 4/9] Install mypy --- .github/workflows/python_actions.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/python_actions.yml b/.github/workflows/python_actions.yml index aa25c86..dddce43 100644 --- a/.github/workflows/python_actions.yml +++ b/.github/workflows/python_actions.yml @@ -39,6 +39,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 From 5a33d4e5b32cf7b56054f8751bb2d41f527cdbc0 Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Mon, 8 Jan 2024 13:08:39 +0000 Subject: [PATCH 5/9] add py.typed marker --- mcmc/py.typed | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 mcmc/py.typed diff --git a/mcmc/py.typed b/mcmc/py.typed new file mode 100644 index 0000000..91eaa0c --- /dev/null +++ b/mcmc/py.typed @@ -0,0 +1,13 @@ +# Copyright (c) 2023 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. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. From 9e9d4bfda0a4983b8ec57e8cb47dd74fa46e7d32 Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Mon, 8 Jan 2024 16:20:09 +0000 Subject: [PATCH 6/9] mypy mcmc --- .github/workflows/python_actions.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python_actions.yml b/.github/workflows/python_actions.yml index dddce43..4eeb97e 100644 --- a/.github/workflows/python_actions.yml +++ b/.github/workflows/python_actions.yml @@ -81,7 +81,7 @@ jobs: uses: ./support/actions/check-copyrights - name: Lint with mypy - run: mypy $BASE_PKG + run: mypy mcmc # # Add the following as required in the future # - name: Validate XML From 83492b92faa76dc7c9dc0af7b2cff3e426831514 Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Mon, 8 Jan 2024 16:37:25 +0000 Subject: [PATCH 7/9] typing fixes --- mcmc/mcmc_cholesky_vertex.py | 12 ++++++------ mcmc/mcmc_coordinator_vertex.py | 11 ++++++----- mcmc/mcmc_model.py | 3 +++ mcmc/mcmc_root_finder_vertex.py | 4 ++-- mcmc/mcmc_vertex.py | 5 +++-- 5 files changed, 20 insertions(+), 15 deletions(-) diff --git a/mcmc/mcmc_cholesky_vertex.py b/mcmc/mcmc_cholesky_vertex.py index 7d4aae2..f20d2a3 100644 --- a/mcmc/mcmc_cholesky_vertex.py +++ b/mcmc/mcmc_cholesky_vertex.py @@ -13,11 +13,15 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from pacman.model.graphs.machine import MachineVertex -from pacman.model.resources import ConstantSDRAM +from enum import Enum + 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.abstract_models.abstract_has_associated_binary \ import AbstractHasAssociatedBinary @@ -25,10 +29,6 @@ .abstract_generates_data_specification \ import AbstractGeneratesDataSpecification from spinn_front_end_common.interface.ds import DataSpecificationGenerator -from spinn_front_end_common.utilities.utility_objs.executable_type \ - import ExecutableType - -from enum import Enum class MCMCCholeskyRegions(Enum): diff --git a/mcmc/mcmc_coordinator_vertex.py b/mcmc/mcmc_coordinator_vertex.py index 1b8b084..f0f576c 100644 --- a/mcmc/mcmc_coordinator_vertex.py +++ b/mcmc/mcmc_coordinator_vertex.py @@ -17,6 +17,8 @@ from pacman.model.resources import ConstantSDRAM from spinn_utilities.overrides import overrides +from spinnman.model.enums import ExecutableType + from pacman.model.placements import Placement from spinn_front_end_common.abstract_models.abstract_has_associated_binary \ @@ -27,8 +29,6 @@ from spinn_front_end_common.data import FecDataView from spinn_front_end_common.interface.ds import ( DataSpecificationGenerator, DataType) -from spinn_front_end_common.utilities.utility_objs.executable_type \ - import ExecutableType from spinn_utilities.progress_bar import ProgressBar import numpy @@ -236,16 +236,17 @@ def generate_data_specification( spec.write_value(len(keys), data_type=DataType.UINT32) # Write the key - routing_info = routing_info.get_routing_info_from_pre_vertex( + vertex_routing_info = routing_info.get_routing_info_from_pre_vertex( self, self._data_partition_name) - spec.write_value(routing_info.key, data_type=DataType.UINT32) + assert vertex_routing_info is not None + spec.write_value(vertex_routing_info.key, data_type=DataType.UINT32) # Write the window size spec.write_value(self._window_size, data_type=DataType.UINT32) # Write the sequence mask spec.write_value( - ~routing_info.mask & 0xFFFFFFFF, data_type=DataType.UINT32) + ~vertex_routing_info.mask & 0xFFFFFFFF, data_type=DataType.UINT32) # Write the timer spec.write_value(self._send_timer, data_type=DataType.UINT32) diff --git a/mcmc/mcmc_model.py b/mcmc/mcmc_model.py index 888c8a5..c6d6b3c 100644 --- a/mcmc/mcmc_model.py +++ b/mcmc/mcmc_model.py @@ -28,6 +28,7 @@ def get_parameters(self) -> List[MCMCParameter]: :rtype: list of :py:class:`mcmc.mcmc_parameter.MCMCParameter` """ + raise NotImplementedError @abstractmethod def get_state_variables(self) -> List[MCMCStateVariable]: @@ -35,6 +36,7 @@ def get_state_variables(self) -> List[MCMCStateVariable]: :rtype: list of :py:class:`mcmc.mcmc_state_variable.MCMCStateVariable` """ + raise NotImplementedError @abstractmethod def get_binary_name(self) -> str: @@ -42,3 +44,4 @@ def get_binary_name(self) -> str: :rtype: str """ + raise NotImplementedError diff --git a/mcmc/mcmc_root_finder_vertex.py b/mcmc/mcmc_root_finder_vertex.py index a2fde6f..97d490b 100644 --- a/mcmc/mcmc_root_finder_vertex.py +++ b/mcmc/mcmc_root_finder_vertex.py @@ -19,14 +19,14 @@ from pacman.model.placements import Placement +from spinnman.model.enums import ExecutableType + from spinn_front_end_common.abstract_models.abstract_has_associated_binary \ import AbstractHasAssociatedBinary from spinn_front_end_common.abstract_models\ .abstract_generates_data_specification \ import AbstractGeneratesDataSpecification from spinn_front_end_common.interface.ds import DataSpecificationGenerator -from spinn_front_end_common.utilities.utility_objs.executable_type \ - import ExecutableType from enum import Enum diff --git a/mcmc/mcmc_vertex.py b/mcmc/mcmc_vertex.py index f5a0c9b..303f65c 100644 --- a/mcmc/mcmc_vertex.py +++ b/mcmc/mcmc_vertex.py @@ -17,6 +17,8 @@ from pacman.model.resources import ConstantSDRAM from spinn_utilities.overrides import overrides +from spinnman.model.enums import ExecutableType + from pacman.model.placements import Placement from spinn_front_end_common.abstract_models.abstract_has_associated_binary \ @@ -32,8 +34,6 @@ from spinn_front_end_common.utilities import helpful_functions from spinn_front_end_common.interface.buffer_management \ import recording_utilities -from spinn_front_end_common.utilities.utility_objs.executable_type \ - import ExecutableType from enum import Enum import numpy @@ -262,6 +262,7 @@ def generate_data_specification( if (self._model.root_finder): routing_info_rf = routing_info.get_routing_info_from_pre_vertex( self, self._parameter_partition_name) + assert routing_info_rf is not None spec.write_value(routing_info_rf.key, data_type=DataType.UINT32) else: spec.write_value(0, data_type=DataType.UINT32) From a709d9e5ef034bcc67d67ddb6ce3efef915d2cd6 Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Tue, 9 Jan 2024 07:12:08 +0000 Subject: [PATCH 8/9] typing --- mcmc/mcmc_coordinator_vertex.py | 4 +++- mcmc/mcmc_vertex.py | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/mcmc/mcmc_coordinator_vertex.py b/mcmc/mcmc_coordinator_vertex.py index f0f576c..c2131bf 100644 --- a/mcmc/mcmc_coordinator_vertex.py +++ b/mcmc/mcmc_coordinator_vertex.py @@ -13,6 +13,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +from typing import List + from pacman.model.graphs.machine import MachineVertex from pacman.model.resources import ConstantSDRAM from spinn_utilities.overrides import overrides @@ -217,7 +219,7 @@ def generate_data_specification( # Get the placement of the vertices and find out how many chips # are needed - keys = list() + keys: List[int] = list() for vertex in self._mcmc_vertices: mcmc_placement = FecDataView.get_placement_of_vertex(vertex) self._mcmc_placements.append(mcmc_placement) diff --git a/mcmc/mcmc_vertex.py b/mcmc/mcmc_vertex.py index 303f65c..5a4f3ec 100644 --- a/mcmc/mcmc_vertex.py +++ b/mcmc/mcmc_vertex.py @@ -270,6 +270,7 @@ def generate_data_specification( if (self._model.cholesky): routing_info_ch = routing_info.get_routing_info_from_pre_vertex( self, self._cholesky_partition_name) + assert routing_info_ch is not None spec.write_value(routing_info_ch.key, data_type=DataType.UINT32) else: spec.write_value(0, data_type=DataType.UINT32) From d2646b3c8a49c39fdfdff3def6be447c185e2d56 Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Tue, 9 Jan 2024 07:28:54 +0000 Subject: [PATCH 9/9] check for None --- mcmc/mcmc_coordinator_vertex.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mcmc/mcmc_coordinator_vertex.py b/mcmc/mcmc_coordinator_vertex.py index c2131bf..6e42ba0 100644 --- a/mcmc/mcmc_coordinator_vertex.py +++ b/mcmc/mcmc_coordinator_vertex.py @@ -226,7 +226,8 @@ def generate_data_specification( if self._is_receiver_placement(mcmc_placement): key = routing_info.get_first_key_from_pre_vertex( vertex, self._acknowledge_partition_name) - keys.append(key) + if key is not None: + keys.append(key) keys.sort() # Write the data size in words