From 0e2d2d228dd248a48d9d47d41a7e8d6b8a6f44cf Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Mon, 17 Jun 2024 11:24:42 +0100 Subject: [PATCH 01/11] move machine_name to SpinnMachine level --- spinn_machine/spinn_machine.cfg | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spinn_machine/spinn_machine.cfg b/spinn_machine/spinn_machine.cfg index 5cc2cee1..7db21bd6 100644 --- a/spinn_machine/spinn_machine.cfg +++ b/spinn_machine/spinn_machine.cfg @@ -42,3 +42,6 @@ max_machine_core = None # Urls for servers remote_spinnaker_url = None spalloc_server = None +# machine name is typically a URL and then version is required +machine_name = None + From 55b498dffb294441e9f9e41e63e18537487aa876 Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Mon, 17 Jun 2024 13:40:46 +0100 Subject: [PATCH 02/11] move cfg virtual_board --- spinn_machine/spinn_machine.cfg | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spinn_machine/spinn_machine.cfg b/spinn_machine/spinn_machine.cfg index 7db21bd6..b601111b 100644 --- a/spinn_machine/spinn_machine.cfg +++ b/spinn_machine/spinn_machine.cfg @@ -45,3 +45,5 @@ spalloc_server = None # machine name is typically a URL and then version is required machine_name = None +# If using virtual_board both width and height must be set +virtual_board = False From 15860f158efce2cabae7647cf5129250e5484709 Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Mon, 17 Jun 2024 13:51:29 +0100 Subject: [PATCH 03/11] eq and hash --- spinn_machine/version/abstract_version.py | 3 +++ spinn_machine/version/version_201.py | 3 +++ spinn_machine/version/version_248.py | 3 +++ spinn_machine/version/version_3.py | 3 +++ spinn_machine/version/version_5.py | 3 +++ 5 files changed, 15 insertions(+) diff --git a/spinn_machine/version/abstract_version.py b/spinn_machine/version/abstract_version.py index 6ff2cd79..73f9c763 100644 --- a/spinn_machine/version/abstract_version.py +++ b/spinn_machine/version/abstract_version.py @@ -527,3 +527,6 @@ def version_parse_cores_string(self, core_string: str) -> Iterable[int]: :rtype: list(int) """ raise NotImplementedError + + def __hash__(self): + return self.number diff --git a/spinn_machine/version/version_201.py b/spinn_machine/version/version_201.py index 8867b0dc..ea84696d 100644 --- a/spinn_machine/version/version_201.py +++ b/spinn_machine/version/version_201.py @@ -89,3 +89,6 @@ def spinnaker_links(self) -> List[Tuple[int, int, int]]: @overrides(VersionSpin2.fpga_links) def fpga_links(self) -> List[Tuple[int, int, int, int, int]]: return [] + + def __eq__(self, other): + return isinstance(other, Version201) diff --git a/spinn_machine/version/version_248.py b/spinn_machine/version/version_248.py index c6ae7fc6..50bc4ad7 100644 --- a/spinn_machine/version/version_248.py +++ b/spinn_machine/version/version_248.py @@ -68,3 +68,6 @@ def spinnaker_links(self) -> List[Tuple[int, int, int]]: def fpga_links(self) -> List[Tuple[int, int, int, int, int]]: # TODO return [] + + def __eq__(self, other): + return isinstance(other, Version248) diff --git a/spinn_machine/version/version_3.py b/spinn_machine/version/version_3.py index 9d82f2a0..4cdfe41e 100644 --- a/spinn_machine/version/version_3.py +++ b/spinn_machine/version/version_3.py @@ -85,3 +85,6 @@ def spinnaker_links(self) -> List[Tuple[int, int, int]]: @overrides(VersionSpin1.fpga_links) def fpga_links(self) -> List[Tuple[int, int, int, int, int]]: return [] + + def __eq__(self, other): + return isinstance(other, Version3) diff --git a/spinn_machine/version/version_5.py b/spinn_machine/version/version_5.py index 519cbefd..70711600 100644 --- a/spinn_machine/version/version_5.py +++ b/spinn_machine/version/version_5.py @@ -82,3 +82,6 @@ def fpga_links(self) -> List[Tuple[int, int, int, int, int]]: (7, 5, 0, 2, 12), (7, 5, 1, 2, 11), (7, 6, 0, 2, 10), (7, 6, 1, 2, 9), (7, 7, 0, 2, 8), (7, 7, 1, 2, 7), (7, 7, 2, 2, 6)] + + def __eq__(self, other): + return isinstance(other, Version5) From a21fa79ec873730b506ecb813ac1f9e7d4f46541 Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Mon, 17 Jun 2024 13:51:49 +0100 Subject: [PATCH 04/11] safety code /better errors for bad cfg --- spinn_machine/version/version_factory.py | 156 ++++++++++++++++++++++- 1 file changed, 154 insertions(+), 2 deletions(-) diff --git a/spinn_machine/version/version_factory.py b/spinn_machine/version/version_factory.py index e655ff10..005859f8 100644 --- a/spinn_machine/version/version_factory.py +++ b/spinn_machine/version/version_factory.py @@ -15,9 +15,9 @@ from __future__ import annotations import logging import sys -from typing import TYPE_CHECKING +from typing import Optional,TYPE_CHECKING from spinn_utilities.config_holder import ( - get_config_int_or_none, get_config_str_or_none) + get_config_bool, get_config_int_or_none, get_config_str_or_none) from spinn_utilities.log import FormatAdapter from spinn_machine.exceptions import SpinnMachineException from .version_strings import VersionStrings @@ -38,6 +38,158 @@ def version_factory() -> AbstractVersion: """ Creates a Machine Version class based on cfg settings. + :return: A subclass of AbstractVersion + :raises SpinnMachineException: If the cfg version is not set correctly + """ + cfg_version = _get_cfg_version() + url_version = _get_url_version() + size_version = _get_size_version() + + if cfg_version is None: + if url_version is None: + version: Optional[AbstractVersion] = None + else: + version = _number_to_version(url_version) + else: + if url_version is None: + version = _number_to_version(cfg_version) + else: + version_cfg = _number_to_version(cfg_version) + version_url = _number_to_version(url_version) + if version_cfg == version_url: + version = version_cfg + + if size_version is None: + if version is None: + raise_no_version() + else: + return version + else: + if version is None: + logger.warning("Please add a version to your cfg file.") + return _number_to_version(size_version) + else: + version_sized = _number_to_version(size_version) + if version == version_sized: + return version + else: + raise SpinnMachineException( + "cfg width and height do not match other cfg setting.") + +def _get_cfg_version() -> Optional[int]: + version = get_config_int_or_none("Machine", "version") + versions = get_config_str_or_none("Machine", "versions") + if versions is not None: + if version is not None: + raise SpinnMachineException( + f"Both {version=} and {versions=} found in cfg") + vs = VersionStrings.from_string(versions) + options = vs.options + # Use the fact that we run actions against different python versions + minor = sys.version_info.minor + version = options[minor % len(options)] + return version + +def _get_url_version() -> Optional[int]: + spalloc_server = get_config_str_or_none("Machine", "spalloc_server") + remote_spinnaker_url = get_config_str_or_none( + "Machine", "remote_spinnaker_url") + machine_name = get_config_str_or_none("Machine", "machineName") + virtual_board = get_config_bool("Machine", "virtual_board") + + if spalloc_server is not None: + if remote_spinnaker_url is not None: + raise SpinnMachineException( + "Both spalloc_server and remote_spinnaker_url " + "specified in cfg") + if machine_name is not None: + raise SpinnMachineException( + "Both spalloc_server and machine_name specified in cfg") + if virtual_board: + raise SpinnMachineException( + "Both spalloc_server and virtual_board specified in cfg") + return 5 + + if remote_spinnaker_url is not None: + if machine_name is not None: + raise SpinnMachineException( + "Both remote_spinnaker_url and machine_name specified in cfg") + if virtual_board: + raise SpinnMachineException( + "Both remote_spinnaker_url and virtual_board specified in cfg") + return 5 + + if machine_name is not None: + if virtual_board: + raise SpinnMachineException( + "Both machine_name and virtual_board specified in cfg") + + return None + + +def _get_size_version() -> Optional[int]: + height = get_config_int_or_none("Machine", "height") + width = get_config_int_or_none("Machine", "width") + if height is None: + if width is None: + return None + else: + raise SpinnMachineException("cfg has width but not height") + else: + if width is None: + raise SpinnMachineException("cfg has height but not width") + else: + logger.warning("cfg width and height are deprecated. " + "Please remove then.") + if height == width == 2: + return 3 + elif height == width == 1: + return 201 + # if width and height are valid checked later + return 5 + +def _number_to_version(version: int): + # Delayed import to avoid circular imports + # pylint: disable=import-outside-toplevel + from .version_3 import Version3 + from .version_5 import Version5 + from .version_201 import Version201 + from .version_248 import Version248 + + if version in [2, 3]: + return Version3() + + if version in [4, 5]: + return Version5() + + if version == SPIN2_1CHIP: + return Version201() + + if version == SPIN2_48CHIP: + return Version248() + + raise SpinnMachineException(f"Unexpected cfg [Machine]version {version}") + +def raise_no_version(): + height = get_config_int_or_none("Machine", "height") + width = get_config_int_or_none("Machine", "width") + + spalloc_server = get_config_str_or_none("Machine", + "spalloc_server") + remote_spinnaker_url = get_config_str_or_none( + "Machine", "remote_spinnaker_url") + machine_name = get_config_str_or_none("Machine", "machineName") + virtual_board = get_config_bool("Machine", "virtual_board") + raise SpinnMachineException( + "cfg [Machine]version {version} is None. " + f"Other cfg settings are {machine_name=} {spalloc_server=}, " + f"{remote_spinnaker_url=} {width=} {height=}") + + +def version_factoryX() -> AbstractVersion: + """ + Creates a Machine Version class based on cfg settings. + :return: A subclass of AbstractVersion :raises SpinnMachineException: If the cfg version is not set correctly """ From 753806626fe5f66f8e9a06111dc96f5477e97e68 Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Mon, 17 Jun 2024 15:27:39 +0100 Subject: [PATCH 05/11] tests and fix warnings --- spinn_machine/version/version_factory.py | 83 +++---------------- unittests/test_version_factory.py | 101 +++++++++++++++++++++++ 2 files changed, 111 insertions(+), 73 deletions(-) create mode 100644 unittests/test_version_factory.py diff --git a/spinn_machine/version/version_factory.py b/spinn_machine/version/version_factory.py index 005859f8..4ebec48f 100644 --- a/spinn_machine/version/version_factory.py +++ b/spinn_machine/version/version_factory.py @@ -58,10 +58,12 @@ def version_factory() -> AbstractVersion: version_url = _number_to_version(url_version) if version_cfg == version_url: version = version_cfg + else: + raise_version_error("Incorrect version", cfg_version) if size_version is None: if version is None: - raise_no_version() + raise_version_error("No version", None) else: return version else: @@ -88,6 +90,9 @@ def _get_cfg_version() -> Optional[int]: # Use the fact that we run actions against different python versions minor = sys.version_info.minor version = options[minor % len(options)] + if version is None: + logger.warning( + "The cfg has no version. This is deprecated! Please add a version") return version def _get_url_version() -> Optional[int]: @@ -139,8 +144,6 @@ def _get_size_version() -> Optional[int]: if width is None: raise SpinnMachineException("cfg has height but not width") else: - logger.warning("cfg width and height are deprecated. " - "Please remove then.") if height == width == 2: return 3 elif height == width == 1: @@ -170,7 +173,7 @@ def _number_to_version(version: int): raise SpinnMachineException(f"Unexpected cfg [Machine]version {version}") -def raise_no_version(): +def raise_version_error(error: str, version: Optional[int]): height = get_config_int_or_none("Machine", "height") width = get_config_int_or_none("Machine", "width") @@ -181,72 +184,6 @@ def raise_no_version(): machine_name = get_config_str_or_none("Machine", "machineName") virtual_board = get_config_bool("Machine", "virtual_board") raise SpinnMachineException( - "cfg [Machine]version {version} is None. " - f"Other cfg settings are {machine_name=} {spalloc_server=}, " - f"{remote_spinnaker_url=} {width=} {height=}") - - -def version_factoryX() -> AbstractVersion: - """ - Creates a Machine Version class based on cfg settings. - - :return: A subclass of AbstractVersion - :raises SpinnMachineException: If the cfg version is not set correctly - """ - # Delayed import to avoid circular imports - # pylint: disable=import-outside-toplevel - from .version_3 import Version3 - from .version_5 import Version5 - from .version_201 import Version201 - from .version_248 import Version248 - - version = get_config_int_or_none("Machine", "version") - versions = get_config_str_or_none("Machine", "versions") - if versions is not None: - if version is not None: - raise SpinnMachineException( - f"Both {version=} and {versions=} found in cfg") - vs = VersionStrings.from_string(versions) - options = vs.options - # Use the fact that we run actions against different python versions - minor = sys.version_info.minor - version = options[minor % len(options)] - - if version in [2, 3]: - return Version3() - - if version in [4, 5]: - return Version5() - - if version == SPIN2_1CHIP: - return Version201() - - if version == SPIN2_48CHIP: - return Version248() - - spalloc_server = get_config_str_or_none("Machine", "spalloc_server") - if spalloc_server is not None: - return Version5() - - remote_spinnaker_url = get_config_str_or_none( - "Machine", "remote_spinnaker_url") - if remote_spinnaker_url is not None: - return Version5() - - height = get_config_int_or_none("Machine", "height") - width = get_config_int_or_none("Machine", "width") - if height is not None and width is not None: - logger.info("Your cfg file does not have a version") - if height == width == 2: - return Version3() - elif height == width == 1: - return Version201() - return Version5() - - if version is None: - machine_name = get_config_str_or_none("Machine", "machineName") - raise SpinnMachineException( - "cfg [Machine]version {version} is None. " - f"Other cfg settings are {machine_name=} {spalloc_server=}, " - f"{remote_spinnaker_url=} {width=} {height=}") - raise SpinnMachineException(f"Unexpected cfg [Machine]version {version}") + f"{error} with cfg [Machine] values {version=}, " + f"{machine_name=}, {spalloc_server=}, {remote_spinnaker_url=}, " + f"{width=}, and {height=}") diff --git a/unittests/test_version_factory.py b/unittests/test_version_factory.py new file mode 100644 index 00000000..b93ebaf5 --- /dev/null +++ b/unittests/test_version_factory.py @@ -0,0 +1,101 @@ +# Copyright (c) 2014 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. + +import unittest +from spinn_utilities.config_holder import set_config +from spinn_machine.config_setup import unittest_setup +from spinn_machine.exceptions import ( + SpinnMachineException) +from spinn_machine.version.version_5 import Version5 +from spinn_machine.version.version_factory import version_factory + + +class TestVersionFactory(unittest.TestCase): + + def setUp(self): + unittest_setup() + + def test_no_info(self): + with self.assertRaises(SpinnMachineException): + version_factory() + + def test_bad_spalloc_3(self): + set_config("Machine", "version", 3) + set_config("Machine", "spalloc_server", "Somewhere") + with self.assertRaises(SpinnMachineException): + version_factory() + + def test_ok_spalloc_4(self): + set_config("Machine", "version", 4) + set_config("Machine", "spalloc_server", "Somewhere") + version = version_factory() + self.assertEqual(Version5(), version) + + def test_ok_spalloc(self): + # warning this behaviour may break if spalloc ever support spin2 + set_config("Machine", "spalloc_server", "Somewhere") + version = version_factory() + self.assertEqual(Version5(), version) + + def test_ok_remote_5(self): + set_config("Machine", "version", 4) + set_config("Machine", "remote_spinnaker_url", "Somewhere") + version = version_factory() + self.assertEqual(Version5(), version) + + def test_bad_spalloc_and_remote(self): + set_config("Machine", "spalloc_server", "Somewhere") + set_config("Machine", "remote_spinnaker_url", "Somewhere") + with self.assertRaises(SpinnMachineException): + version_factory() + + def test_bad_spalloc_and_name(self): + set_config("Machine", "spalloc_server", "Somewhere") + set_config("Machine", "machine_name", "Somewhere") + #with self.assertRaises(SpinnMachineException): + version_factory() + + def test_bad_spalloc_and_name(self): + set_config("Machine", "spalloc_server", "Somewhere") + set_config("Machine", "machine_name", "Somewhere") + with self.assertRaises(SpinnMachineException): + version_factory() + + def test_bad_spalloc_and_virtual(self): + set_config("Machine", "spalloc_server", "Somewhere") + set_config("Machine", "virtual_board", "True") + with self.assertRaises(SpinnMachineException): + version_factory() + + def test_bad_remote_and_name(self): + set_config("Machine", "remote_spinnaker_url", "Somewhere") + set_config("Machine", "machine_name", "Somewhere") + with self.assertRaises(SpinnMachineException): + version_factory() + + def test_bad_remote_and_virtual(self): + set_config("Machine", "remote_spinnaker_url", "Somewhere") + set_config("Machine", "virtual_board", "True") + with self.assertRaises(SpinnMachineException): + version_factory() + + def test_bad_name_and_virtual(self): + set_config("Machine", "machine_name", "Somewhere") + set_config("Machine", "virtual_board", "True") + with self.assertRaises(SpinnMachineException): + version_factory() + + +if __name__ == '__main__': + unittest.main() From eaf4caa1e687915b1f9cbf9d38301c8956555fb0 Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Thu, 20 Jun 2024 11:45:55 +0100 Subject: [PATCH 06/11] json_path moved --- spinn_machine/spinn_machine.cfg | 2 -- 1 file changed, 2 deletions(-) diff --git a/spinn_machine/spinn_machine.cfg b/spinn_machine/spinn_machine.cfg index b601111b..4fc34cb3 100644 --- a/spinn_machine/spinn_machine.cfg +++ b/spinn_machine/spinn_machine.cfg @@ -6,8 +6,6 @@ version = None versions = None width = None height = None -# Note: if json_path is set all other configs for virtual boards are ignored -json_path = None # Can decrease actual but never increase. Used for testing max_sdram_allowed_per_chip = None From 88282ed29bbd265b867dc67a681536bb6ba51c8c Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Thu, 20 Jun 2024 13:01:35 +0100 Subject: [PATCH 07/11] do not edit message improved --- spinn_machine/spinn_machine.cfg | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/spinn_machine/spinn_machine.cfg b/spinn_machine/spinn_machine.cfg index 4fc34cb3..7c9822f1 100644 --- a/spinn_machine/spinn_machine.cfg +++ b/spinn_machine/spinn_machine.cfg @@ -1,4 +1,9 @@ -# Adds or overwrites values in SpiNNUtils/spinn_utilities/spinn_utilities.cfg +# DO NOT EDIT! +# The are the default values +# Edit the cfg in your home directory to change your preferences +# Add / Edit a cfg in the run directory for script specific changes + +# Adds to values in SpiNNUtils/spinn_utilities/spinn_utilities.cfg [Machine] version = None From d7c989ed02ed8f5a4a3a9a1ac3a12f0955e86691 Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Thu, 20 Jun 2024 13:25:18 +0100 Subject: [PATCH 08/11] flake8 fixes --- spinn_machine/version/version_factory.py | 9 ++++++--- unittests/test_version_factory.py | 6 ------ 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/spinn_machine/version/version_factory.py b/spinn_machine/version/version_factory.py index 4ebec48f..2eb87015 100644 --- a/spinn_machine/version/version_factory.py +++ b/spinn_machine/version/version_factory.py @@ -15,7 +15,7 @@ from __future__ import annotations import logging import sys -from typing import Optional,TYPE_CHECKING +from typing import Optional, TYPE_CHECKING from spinn_utilities.config_holder import ( get_config_bool, get_config_int_or_none, get_config_str_or_none) from spinn_utilities.log import FormatAdapter @@ -63,7 +63,7 @@ def version_factory() -> AbstractVersion: if size_version is None: if version is None: - raise_version_error("No version", None) + raise_version_error("No version", None) else: return version else: @@ -95,6 +95,7 @@ def _get_cfg_version() -> Optional[int]: "The cfg has no version. This is deprecated! Please add a version") return version + def _get_url_version() -> Optional[int]: spalloc_server = get_config_str_or_none("Machine", "spalloc_server") remote_spinnaker_url = get_config_str_or_none( @@ -151,6 +152,7 @@ def _get_size_version() -> Optional[int]: # if width and height are valid checked later return 5 + def _number_to_version(version: int): # Delayed import to avoid circular imports # pylint: disable=import-outside-toplevel @@ -173,6 +175,7 @@ def _number_to_version(version: int): raise SpinnMachineException(f"Unexpected cfg [Machine]version {version}") + def raise_version_error(error: str, version: Optional[int]): height = get_config_int_or_none("Machine", "height") width = get_config_int_or_none("Machine", "width") @@ -186,4 +189,4 @@ def raise_version_error(error: str, version: Optional[int]): raise SpinnMachineException( f"{error} with cfg [Machine] values {version=}, " f"{machine_name=}, {spalloc_server=}, {remote_spinnaker_url=}, " - f"{width=}, and {height=}") + f"{virtual_board=}, {width=}, and {height=}") diff --git a/unittests/test_version_factory.py b/unittests/test_version_factory.py index b93ebaf5..0f74f2a2 100644 --- a/unittests/test_version_factory.py +++ b/unittests/test_version_factory.py @@ -60,12 +60,6 @@ def test_bad_spalloc_and_remote(self): with self.assertRaises(SpinnMachineException): version_factory() - def test_bad_spalloc_and_name(self): - set_config("Machine", "spalloc_server", "Somewhere") - set_config("Machine", "machine_name", "Somewhere") - #with self.assertRaises(SpinnMachineException): - version_factory() - def test_bad_spalloc_and_name(self): set_config("Machine", "spalloc_server", "Somewhere") set_config("Machine", "machine_name", "Somewhere") From 8299a44708996cc6ab4061ad519a7445f275ee54 Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Thu, 20 Jun 2024 14:01:02 +0100 Subject: [PATCH 09/11] flake8 --- spinn_machine/version/version_factory.py | 1 + 1 file changed, 1 insertion(+) diff --git a/spinn_machine/version/version_factory.py b/spinn_machine/version/version_factory.py index 2eb87015..6625e614 100644 --- a/spinn_machine/version/version_factory.py +++ b/spinn_machine/version/version_factory.py @@ -78,6 +78,7 @@ def version_factory() -> AbstractVersion: raise SpinnMachineException( "cfg width and height do not match other cfg setting.") + def _get_cfg_version() -> Optional[int]: version = get_config_int_or_none("Machine", "version") versions = get_config_str_or_none("Machine", "versions") From 7b5014f994971b8ff1ffe03c2a14c8a785e45de6 Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Thu, 20 Jun 2024 15:20:01 +0100 Subject: [PATCH 10/11] docs --- spinn_machine/version/version_factory.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/spinn_machine/version/version_factory.py b/spinn_machine/version/version_factory.py index 6625e614..c79ac9e2 100644 --- a/spinn_machine/version/version_factory.py +++ b/spinn_machine/version/version_factory.py @@ -45,9 +45,10 @@ def version_factory() -> AbstractVersion: url_version = _get_url_version() size_version = _get_size_version() + version: Optional[AbstractVersion] = None if cfg_version is None: if url_version is None: - version: Optional[AbstractVersion] = None + version = None else: version = _number_to_version(url_version) else: @@ -178,6 +179,14 @@ def _number_to_version(version: int): def raise_version_error(error: str, version: Optional[int]): + """ + Collects main cfg values and raises an exception + + :param str error: message for the exception + :param version: version claimed + :type version: int or None + :raises SpinnMachineException: Always! + """ height = get_config_int_or_none("Machine", "height") width = get_config_int_or_none("Machine", "width") From b4050af05ebe519004ffcbaa23dd9a4c58168589 Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Thu, 20 Jun 2024 15:41:33 +0100 Subject: [PATCH 11/11] error to help mypy know this is unreachable --- spinn_machine/version/version_factory.py | 1 + 1 file changed, 1 insertion(+) diff --git a/spinn_machine/version/version_factory.py b/spinn_machine/version/version_factory.py index c79ac9e2..fc19f07f 100644 --- a/spinn_machine/version/version_factory.py +++ b/spinn_machine/version/version_factory.py @@ -78,6 +78,7 @@ def version_factory() -> AbstractVersion: else: raise SpinnMachineException( "cfg width and height do not match other cfg setting.") + raise SpinnMachineException("Should not get here") def _get_cfg_version() -> Optional[int]: