diff --git a/spinn_front_end_common/data/fec_data_writer.py b/spinn_front_end_common/data/fec_data_writer.py index 35e8e4660a..5023ad586d 100644 --- a/spinn_front_end_common/data/fec_data_writer.py +++ b/spinn_front_end_common/data/fec_data_writer.py @@ -18,7 +18,7 @@ import os import time from spinn_utilities.config_holder import ( - get_config_int, get_config_str) + get_config_int, get_config_int_or_none, get_config_str) from spinn_utilities.log import FormatAdapter from spinn_utilities.overrides import overrides from spinn_front_end_common.utilities.notification_protocol import ( @@ -280,7 +280,8 @@ def _set_time_scale_factor( """ if time_scale_factor is None: # Note while this reads from the cfg the cfg default is None - time_scale_factor = get_config_int("Machine", "time_scale_factor") + time_scale_factor = get_config_int_or_none( + "Machine", "time_scale_factor") if time_scale_factor is None: if default_time_scale_factor is not None: diff --git a/spinn_front_end_common/interface/abstract_spinnaker_base.py b/spinn_front_end_common/interface/abstract_spinnaker_base.py index 0829822481..5030969ed8 100644 --- a/spinn_front_end_common/interface/abstract_spinnaker_base.py +++ b/spinn_front_end_common/interface/abstract_spinnaker_base.py @@ -29,7 +29,8 @@ from spinn_utilities import __version__ as spinn_utils_version from spinn_utilities.config_holder import ( - get_config_bool, get_config_int, get_config_str, set_config) + get_config_bool, get_config_int, get_config_str, get_config_str_or_none, + is_config_none, set_config) from spinn_utilities.log import FormatAdapter from spinn_machine import __version__ as spinn_machine_version @@ -303,7 +304,7 @@ def __group_collab_or_job(self): match_obj.group(SHARED_WITH_GROUP)) # Try to use the config to get a group - group = get_config_str("Machine", "spalloc_group") + group = get_config_str_or_none("Machine", "spalloc_group") if group is not None: return {"group": group} @@ -729,14 +730,15 @@ def _execute_allocator(self, total_run_time): """ if self._data_writer.has_machine(): return None - if get_config_str("Machine", "spalloc_server") is not None: + if not is_config_none("Machine", "spalloc_server"): with FecTimer("SpallocAllocator", TimerWork.OTHER): return spalloc_allocator( self.__bearer_token, **self.__group_collab_or_job) - if get_config_str("Machine", "remote_spinnaker_url") is not None: + if not is_config_none("Machine", "remote_spinnaker_url"): with FecTimer("HBPAllocator", TimerWork.OTHER): # TODO: Would passing the bearer token to this ever make sense? return hbp_allocator(total_run_time) + return None def _execute_machine_generator(self, allocator_data): """ @@ -754,17 +756,16 @@ def _execute_machine_generator(self, allocator_data): """ if self._data_writer.has_machine(): return - machine_name = get_config_str("Machine", "machine_name") + machine_name = get_config_str_or_none("Machine", "machine_name") if machine_name is not None: self._data_writer.set_ipaddress(machine_name) - bmp_details = get_config_str("Machine", "bmp_names") + bmp_details = get_config_str_or_none("Machine", "bmp_names") auto_detect_bmp = get_config_bool( "Machine", "auto_detect_bmp") scamp_connection_data = None reset_machine = get_config_bool( "Machine", "reset_machine_on_startup") - board_version = get_config_int( - "Machine", "version") + board_version = FecDataView.get_machine_version().number elif allocator_data: (ipaddress, board_version, bmp_details, @@ -1615,7 +1616,7 @@ def _execute_pair_unordered_compressor(self): def _compressor_name(self): if get_config_bool("Machine", "virtual_board"): - name = get_config_str("Mapping", "virtual_compressor") + name = get_config_str_or_none("Mapping", "virtual_compressor") if name is None: logger.info("As no virtual_compressor specified " "using compressor setting") @@ -1634,7 +1635,7 @@ def _compression_skipable(self, tables): def _execute_pre_compression(self, pre_compress): if pre_compress: - name = get_config_str("Mapping", "precompressor") + name = get_config_str_or_none("Mapping", "precompressor") if name is None: self._data_writer.set_precompressed( self._data_writer.get_uncompressed()) diff --git a/spinn_front_end_common/interface/interface_functions/compute_energy_used.py b/spinn_front_end_common/interface/interface_functions/compute_energy_used.py index dd0cd307b7..333934166c 100644 --- a/spinn_front_end_common/interface/interface_functions/compute_energy_used.py +++ b/spinn_front_end_common/interface/interface_functions/compute_energy_used.py @@ -13,7 +13,7 @@ # limitations under the License. import itertools -from spinn_utilities.config_holder import (get_config_int, get_config_str) +from spinn_utilities.config_holder import (get_config_int, is_config_none) from spinn_front_end_common.data import FecDataView from spinn_front_end_common.interface.provenance import ( GlobalProvenance, ProvenanceReader, TimerCategory, TimerWork) @@ -244,8 +244,8 @@ def _calculate_fpga_energy( """ total_fpgas = 0 # if not spalloc, then could be any type of board - if (not get_config_str("Machine", "spalloc_server") and - not get_config_str("Machine", "remote_spinnaker_url")): + if (is_config_none("Machine", "spalloc_server") and + is_config_none("Machine", "remote_spinnaker_url")): # if a spinn2 or spinn3 (4 chip boards) then they have no fpgas if machine.n_chips <= 4: return 0, 0 diff --git a/spinn_front_end_common/interface/interface_functions/database_interface.py b/spinn_front_end_common/interface/interface_functions/database_interface.py index 82eb47f63a..93c02cfbba 100644 --- a/spinn_front_end_common/interface/interface_functions/database_interface.py +++ b/spinn_front_end_common/interface/interface_functions/database_interface.py @@ -13,7 +13,8 @@ # limitations under the License. import logging -from spinn_utilities.config_holder import get_config_bool +from spinn_utilities.config_holder import ( + get_config_bool, get_config_bool_or_none) from spinn_utilities.progress_bar import ProgressBar from spinn_utilities.log import FormatAdapter from pacman.model.graphs.application import ApplicationVertex @@ -33,7 +34,8 @@ def database_interface(runtime): """ # pylint: disable=too-many-arguments needs_db = DatabaseWriter.auto_detect_database() - user_create_database = get_config_bool("Database", "create_database") + user_create_database = get_config_bool_or_none( + "Database", "create_database") if user_create_database is not None: if user_create_database != needs_db: logger.warning(f"Database creating changed to " diff --git a/spinn_front_end_common/interface/interface_functions/local_tdma_builder.py b/spinn_front_end_common/interface/interface_functions/local_tdma_builder.py index ad703e1afa..dff39ddb41 100644 --- a/spinn_front_end_common/interface/interface_functions/local_tdma_builder.py +++ b/spinn_front_end_common/interface/interface_functions/local_tdma_builder.py @@ -15,7 +15,8 @@ import logging import math from spinn_utilities.log import FormatAdapter -from spinn_utilities.config_holder import get_config_float, get_config_int +from spinn_utilities.config_holder import ( + get_config_float_or_none, get_config_int, get_config_int_or_none) from spinn_front_end_common.abstract_models.impl.\ tdma_aware_application_vertex import ( TDMAAwareApplicationVertex) @@ -283,9 +284,9 @@ def __config_values(clocks_per_cycle): "Simulation", "app_machine_quantity") # set the time between cores to fire - time_between_cores = get_config_float( + time_between_cores = get_config_float_or_none( "Simulation", "time_between_cores") - clocks_between_cores = get_config_int( + clocks_between_cores = get_config_int_or_none( "Simulation", "clock_cycles_between_cores") __check_at_most_one( "time_between_cores", time_between_cores, @@ -300,9 +301,9 @@ def __config_values(clocks_per_cycle): clocks_between_cores = time_between_cores * CLOCKS_PER_US # time spend sending - fraction_of_sending = get_config_float( + fraction_of_sending = get_config_float_or_none( "Simulation", "fraction_of_time_spike_sending") - clocks_for_sending = get_config_int( + clocks_for_sending = get_config_int_or_none( "Simulation", "clock_cycles_sending") __check_only_one( "fraction_of_time_spike_sending", fraction_of_sending, @@ -312,7 +313,7 @@ def __config_values(clocks_per_cycle): clocks_per_cycle * fraction_of_sending)) # time waiting before sending - fraction_of_waiting = get_config_float( + fraction_of_waiting = get_config_float_or_none( "Simulation", "fraction_of_time_before_sending") clocks_waiting = get_config_int( "Simulation", "clock_cycles_before_sending") @@ -323,7 +324,7 @@ def __config_values(clocks_per_cycle): clocks_waiting = int(round(clocks_per_cycle * fraction_of_waiting)) # time to offset app vertices between each other - fraction_initial = get_config_float( + fraction_initial = get_config_float_or_none( "Simulation", "fraction_of_time_for_offset") clocks_initial = get_config_int( "Simulation", "clock_cycles_for_offset") diff --git a/spinn_front_end_common/interface/interface_functions/machine_bit_field_router_compressor.py b/spinn_front_end_common/interface/interface_functions/machine_bit_field_router_compressor.py index 8e54680ba5..44f17ade08 100644 --- a/spinn_front_end_common/interface/interface_functions/machine_bit_field_router_compressor.py +++ b/spinn_front_end_common/interface/interface_functions/machine_bit_field_router_compressor.py @@ -16,7 +16,8 @@ import logging import struct from collections import defaultdict -from spinn_utilities.config_holder import get_config_bool, get_config_int +from spinn_utilities.config_holder import ( + get_config_bool, get_config_int, get_config_int_or_none) from spinn_utilities.log import FormatAdapter from spinn_utilities.progress_bar import ProgressBar from spinn_machine import CoreSubsets, Router @@ -140,7 +141,7 @@ def run(self, compress_as_much_as_possible=False): routing_table_compressor_app_id = view.get_new_id() text = f"on chip {self._compressor_type} compressor with bitfields" - retry_count = get_config_int( + retry_count = get_config_int_or_none( "Mapping", "router_table_compression_with_bit_field_retry_count") if retry_count is not None: diff --git a/spinn_front_end_common/interface/interface_functions/spalloc_allocator.py b/spinn_front_end_common/interface/interface_functions/spalloc_allocator.py index 2eec620a3a..8223a78ced 100644 --- a/spinn_front_end_common/interface/interface_functions/spalloc_allocator.py +++ b/spinn_front_end_common/interface/interface_functions/spalloc_allocator.py @@ -15,13 +15,14 @@ import logging import math from typing import Dict, Tuple -from spinn_utilities.config_holder import get_config_str_list, get_config_bool +from spinn_utilities.config_holder import ( + get_config_bool, get_config_int, get_config_str, get_config_str_or_none, + get_config_str_list) from spinn_utilities.log import FormatAdapter from spinn_utilities.overrides import overrides from spalloc_client import Job from spalloc_client.states import JobState from spinn_utilities.abstract_context_manager import AbstractContextManager -from spinn_utilities.config_holder import get_config_int, get_config_str from spinnman.constants import SCP_SCAMP_PORT from spinnman.spalloc import ( is_server_address, SpallocClient, SpallocJob, SpallocState) @@ -348,7 +349,7 @@ def _allocate_job_old(spalloc_server: str, n_boards: int) -> Tuple[ 'port': port, 'owner': user } - spalloc_machine = get_config_str("Machine", "spalloc_machine") + spalloc_machine = get_config_str_or_none("Machine", "spalloc_machine") if spalloc_machine is not None: spalloc_kwargs['machine'] = spalloc_machine diff --git a/spinn_front_end_common/interface/interface_functions/virtual_machine_generator.py b/spinn_front_end_common/interface/interface_functions/virtual_machine_generator.py index e072dcbb14..5722b85db1 100644 --- a/spinn_front_end_common/interface/interface_functions/virtual_machine_generator.py +++ b/spinn_front_end_common/interface/interface_functions/virtual_machine_generator.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, get_config_str_or_none) from spinn_utilities.log import FormatAdapter from spinn_machine import json_machine, virtual_machine from spinn_front_end_common.data import FecDataView @@ -30,36 +31,11 @@ def virtual_machine_generator(): """ height = get_config_int("Machine", "height") width = get_config_int("Machine", "width") - json_path = get_config_str("Machine", "json_path") - # For backward compatibility support version in csf files for now - version = get_config_int("Machine", "version") - if version is not None: - if version in [2, 3]: - if height is None: - height = 2 - else: - assert height == 2 - if width is None: - width = 2 - else: - assert width == 2 - logger.warning("For virtual Machines version is deprecated." - "use width=2, height=2 instead") - elif version in [4, 5]: - if height is None: - height = 8 - else: - assert height == 8 - if width is None: - width = 8 - else: - assert width == 8 - logger.warning("For virtual Machines version is deprecated." - "use width=8, height=8 instead") - else: - raise ValueError(f"Unknown version {version}") + version = FecDataView.get_machine_version() + version.verify_size(height, width) + json_path = get_config_str_or_none("Machine", "json_path") if json_path is None: n_cores = FecDataView.get_machine_version().max_cores_per_chip machine = virtual_machine( @@ -69,9 +45,9 @@ def virtual_machine_generator(): else: if (height is not None or width is not None or version is not None or - get_config_str("Machine", "down_chips") is not None or - get_config_str("Machine", "down_cores") is not None or - get_config_str("Machine", "down_links") is not None): + get_config_str_or_none("Machine", "down_chips") is not None or + get_config_str_or_none("Machine", "down_cores") is not None or + get_config_str_or_none("Machine", "down_links") is not None): logger.warning("As json_path specified all other virtual " "machine settings ignored.") machine = json_machine.machine_from_json(json_path) diff --git a/spinn_front_end_common/interface/java_caller.py b/spinn_front_end_common/interface/java_caller.py index b0fb46d3c6..f26f3da722 100644 --- a/spinn_front_end_common/interface/java_caller.py +++ b/spinn_front_end_common/interface/java_caller.py @@ -17,7 +17,8 @@ import logging import os import subprocess -from spinn_utilities.config_holder import get_config_str +from spinn_utilities.config_holder import ( + get_config_str, get_config_str_or_none) from spinn_utilities.log import FormatAdapter from pacman.exceptions import PacmanExternalAlgorithmFailedToCompleteException from pacman.model.graphs import AbstractVirtual @@ -88,7 +89,8 @@ def __init__(self): self._monitor_cores = None self._gatherer_iptags = None self._gatherer_cores = None - self._java_properties = get_config_str("Java", "java_properties") + self._java_properties = get_config_str_or_none( + "Java", "java_properties") self._chipxy_by_ethernet = None if self._java_properties is not None: self._java_properties = self._java_properties.split() @@ -100,8 +102,9 @@ def __init__(self): f"found at {_property}") def _find_java_jar(self): - java_spinnaker_path = get_config_str("Java", "java_spinnaker_path") - java_jar_path = get_config_str("Java", "java_jar_path") + java_spinnaker_path = get_config_str_or_none( + "Java", "java_spinnaker_path") + java_jar_path = get_config_str_or_none("Java", "java_jar_path") if java_spinnaker_path is None: interface = os.path.dirname(os.path.realpath(__file__)) spinn_front_end_common = os.path.dirname(interface) diff --git a/spinn_front_end_common/interface/provenance/provenance_writer.py b/spinn_front_end_common/interface/provenance/provenance_writer.py index b9a6a21b1c..720f378a35 100644 --- a/spinn_front_end_common/interface/provenance/provenance_writer.py +++ b/spinn_front_end_common/interface/provenance/provenance_writer.py @@ -13,7 +13,7 @@ # limitations under the License. import logging -from spinn_utilities.config_holder import get_config_int +from spinn_utilities.config_holder import get_config_int_or_none from spinn_utilities.log import FormatAdapter from spinn_front_end_common.utilities.base_database import BaseDatabase @@ -156,7 +156,7 @@ def insert_report(self, message): VALUES(?) """, [message]) recorded = cur.lastrowid - cutoff = get_config_int("Reports", "provenance_report_cutoff") + cutoff = get_config_int_or_none("Reports", "provenance_report_cutoff") if cutoff is None or recorded < cutoff: logger.warning(message) elif recorded == cutoff: diff --git a/spinn_front_end_common/utilities/iobuf_extractor.py b/spinn_front_end_common/utilities/iobuf_extractor.py index ad1c6fa935..b803ee3416 100644 --- a/spinn_front_end_common/utilities/iobuf_extractor.py +++ b/spinn_front_end_common/utilities/iobuf_extractor.py @@ -21,7 +21,8 @@ from spinn_machine.core_subsets import CoreSubsets from spinnman.model.enums import ExecutableType from spinnman.model.io_buffer import IOBuffer -from spinn_utilities.config_holder import get_config_str +from spinn_utilities.config_holder import get_config_str_or_none + from spinn_front_end_common.data import FecDataView from spinn_front_end_common.utilities.helpful_functions import ( convert_string_into_chip_and_core_subset) @@ -71,9 +72,9 @@ def __init__(self, executable_targets=None, self.__app_path = FecDataView.get_app_provenance_dir_path() self.__sys_path = FecDataView.get_system_provenance_dir_path() - self.__from_cores = get_config_str( + self.__from_cores = get_config_str_or_none( "Reports", "extract_iobuf_from_cores") - self.__binary_types = get_config_str( + self.__binary_types = get_config_str_or_none( "Reports", "extract_iobuf_from_binary_types") if executable_targets is None: self.__executable_targets = FecDataView.get_executable_targets() diff --git a/spinn_front_end_common/utilities/report_functions/energy_report.py b/spinn_front_end_common/utilities/report_functions/energy_report.py index 530057a978..a3266a395b 100644 --- a/spinn_front_end_common/utilities/report_functions/energy_report.py +++ b/spinn_front_end_common/utilities/report_functions/energy_report.py @@ -15,7 +15,7 @@ from collections import defaultdict import logging import os -from spinn_utilities.config_holder import (get_config_int, get_config_str) +from spinn_utilities.config_holder import is_config_none from spinn_utilities.log import FormatAdapter from spinn_front_end_common.data import FecDataView from spinn_front_end_common.interface.provenance import ( @@ -208,10 +208,10 @@ def _write_fpga_cost(self, power_used, f): :param PowerUsed power_used: the runtime :param ~io.TextIOBase f: the file writer """ - version = get_config_int("Machine", "version") + version = FecDataView.get_machine_version().number # if not spalloc, then could be any type of board - if (not get_config_str("Machine", "spalloc_server") and - not get_config_str("Machine", "remote_spinnaker_url")): + if (is_config_none("Machine", "spalloc_server") and + is_config_none("Machine", "remote_spinnaker_url")): # if a spinn2 or spinn3 (4 chip boards) then they have no fpgas if version in (2, 3): f.write(