Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is config none #1108

Merged
merged 7 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions spinn_front_end_common/data/fec_data_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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:
Expand Down
21 changes: 11 additions & 10 deletions spinn_front_end_common/interface/abstract_spinnaker_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}

Expand Down Expand Up @@ -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):
"""
Expand All @@ -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,
Expand Down Expand Up @@ -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")
Expand All @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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")
Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand All @@ -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)
Expand Down
11 changes: 7 additions & 4 deletions spinn_front_end_common/interface/java_caller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down
7 changes: 4 additions & 3 deletions spinn_front_end_common/utilities/iobuf_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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(
Expand Down