From 46c1e2227a92d23a7c2bb5de574374280bcbe681 Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Fri, 25 Aug 2023 08:41:31 +0100 Subject: [PATCH 1/2] config methods which do and do not return none --- spinn_machine/version/abstract_version.py | 12 +++++++----- spinn_machine/version/version_factory.py | 13 +++++++------ spinn_machine/virtual_machine.py | 8 ++++---- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/spinn_machine/version/abstract_version.py b/spinn_machine/version/abstract_version.py index 7d636743..197427b7 100644 --- a/spinn_machine/version/abstract_version.py +++ b/spinn_machine/version/abstract_version.py @@ -16,7 +16,7 @@ from spinn_utilities.abstract_base import ( AbstractBase, abstractmethod, abstractproperty) from spinn_utilities.log import FormatAdapter -from spinn_utilities.config_holder import get_config_int +from spinn_utilities.config_holder import get_config_int_or_none from spinn_machine.exceptions import SpinnMachineException logger = FormatAdapter(logging.getLogger(__name__)) @@ -45,8 +45,8 @@ def __verify_config_width_height(self): :raises SpinnMachineException: If the cfg width or height is unexpected """ - width = get_config_int("Machine", "width") - height = get_config_int("Machine", "height") + width = get_config_int_or_none("Machine", "width") + height = get_config_int_or_none("Machine", "height") if width is None: if height is None: pass @@ -62,7 +62,8 @@ def __verify_config_width_height(self): def __set_max_cores_per_chip(self, max_cores_per_chip): self._max_cores_per_chip = max_cores_per_chip - max_machine_core = get_config_int("Machine", "max_machine_core") + max_machine_core = get_config_int_or_none( + "Machine", "max_machine_core") if max_machine_core is not None: if max_machine_core > self._max_cores_per_chip: logger.info( @@ -78,7 +79,8 @@ def __set_max_cores_per_chip(self, max_cores_per_chip): def __set_max_sdram_per_chip(self, max_sdram_per_chip): self._max_sdram_per_chip = max_sdram_per_chip - max_sdram = get_config_int("Machine", "max_sdram_allowed_per_chip") + max_sdram = get_config_int_or_none( + "Machine", "max_sdram_allowed_per_chip") if max_sdram is not None: if max_sdram > self._max_sdram_per_chip: logger.info( diff --git a/spinn_machine/version/version_factory.py b/spinn_machine/version/version_factory.py index 3233b35a..6de7f6be 100644 --- a/spinn_machine/version/version_factory.py +++ b/spinn_machine/version/version_factory.py @@ -13,7 +13,8 @@ # limitations under the License. import logging -from spinn_utilities.config_holder import get_config_int, get_config_str +from spinn_utilities.config_holder import ( + get_config_int_or_none, get_config_str_or_none) from spinn_utilities.log import FormatAdapter from spinn_machine.exceptions import SpinnMachineException @@ -32,23 +33,23 @@ def version_factory(): from .version_3 import Version3 from .version_5 import Version5 - version = get_config_int("Machine", "version") + version = get_config_int_or_none("Machine", "version") if version in [2, 3]: return Version3() if version in [4, 5]: return Version5() - spalloc_server = get_config_str("Machine", "spalloc_server") + spalloc_server = get_config_str_or_none("Machine", "spalloc_server") if spalloc_server is not None: return Version5() - remote_spinnaker_url = get_config_str("Machine", "remote_spinnaker_url") + 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("Machine", "height") - width = get_config_int("Machine", "width") + 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: if height == width == 2: logger.info("Your cfg file does not have a ") diff --git a/spinn_machine/virtual_machine.py b/spinn_machine/virtual_machine.py index 2db77406..ef1bd2f4 100644 --- a/spinn_machine/virtual_machine.py +++ b/spinn_machine/virtual_machine.py @@ -14,7 +14,7 @@ from collections import defaultdict import logging -from spinn_utilities.config_holder import get_config_str +from spinn_utilities.config_holder import get_config_str_or_none from spinn_utilities.log import FormatAdapter from .chip import Chip from .router import Router @@ -72,7 +72,7 @@ def __init__( # Store the down items unused_chips = [] - for down_chip in IgnoreChip.parse_string(get_config_str( + for down_chip in IgnoreChip.parse_string(get_config_str_or_none( "Machine", "down_chips")): if isinstance(down_chip, IgnoreChip): if down_chip.ip_address is None: @@ -81,7 +81,7 @@ def __init__( unused_chips.append((down_chip[0], down_chip[1])) self._unused_cores = defaultdict(set) - for down_core in IgnoreCore.parse_string(get_config_str( + for down_core in IgnoreCore.parse_string(get_config_str_or_none( "Machine", "down_cores")): if isinstance(down_core, IgnoreCore): if down_core.ip_address is None: @@ -92,7 +92,7 @@ def __init__( down_core[2]) self._unused_links = set() - for down_link in IgnoreLink.parse_string(get_config_str( + for down_link in IgnoreLink.parse_string(get_config_str_or_none( "Machine", "down_links")): if isinstance(down_link, IgnoreLink): if down_link.ip_address is None: From cd16e8e5ff62c2802c140b17b291b5659767de94 Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Fri, 25 Aug 2023 09:41:00 +0100 Subject: [PATCH 2/2] flake8 --- spinn_machine/version/version_factory.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spinn_machine/version/version_factory.py b/spinn_machine/version/version_factory.py index 6de7f6be..85ff1d2b 100644 --- a/spinn_machine/version/version_factory.py +++ b/spinn_machine/version/version_factory.py @@ -44,7 +44,8 @@ def version_factory(): if spalloc_server is not None: return Version5() - remote_spinnaker_url = get_config_str_or_none("Machine", "remote_spinnaker_url") + remote_spinnaker_url = get_config_str_or_none( + "Machine", "remote_spinnaker_url") if remote_spinnaker_url is not None: return Version5()