spinn_utilities package¶
Subpackages¶
- spinn_utilities.citation package
- spinn_utilities.configs package
- spinn_utilities.data package
- Submodules
- spinn_utilities.data.reset_status module
- spinn_utilities.data.run_status module
- spinn_utilities.data.utils_data_writer module
UtilsDataWriterUtilsDataWriter.ERRORED_FILENAMEUtilsDataWriter.FINISHED_FILENAMEUtilsDataWriter.REPORTS_DIRNAMEUtilsDataWriter.finish_run()UtilsDataWriter.get_report_dir_path()UtilsDataWriter.hard_reset()UtilsDataWriter.mock()UtilsDataWriter.request_stop()UtilsDataWriter.set_report_dir_path()UtilsDataWriter.set_run_dir_path()UtilsDataWriter.setup()UtilsDataWriter.shut_down()UtilsDataWriter.soft_reset()UtilsDataWriter.start_run()UtilsDataWriter.stopping()UtilsDataWriter.write_errored_file()UtilsDataWriter.write_finished_file()
- Module contents
DataStatusUtilsDataViewUtilsDataView.check_executable_path()UtilsDataView.check_user_can_act()UtilsDataView.check_valid_simulator()UtilsDataView.get_error_file()UtilsDataView.get_executable_finder()UtilsDataView.get_executable_path()UtilsDataView.get_executable_paths()UtilsDataView.get_global_reports_dir()UtilsDataView.get_log_database_keys_and_paths()UtilsDataView.get_log_database_path()UtilsDataView.get_requires_data_generation()UtilsDataView.get_requires_mapping()UtilsDataView.get_reset_number()UtilsDataView.get_reset_str()UtilsDataView.get_run_dir_path()UtilsDataView.get_run_number()UtilsDataView.get_timestamp_dir_path()UtilsDataView.is_hard_reset()UtilsDataView.is_no_stop_requested()UtilsDataView.is_ran_ever()UtilsDataView.is_ran_last()UtilsDataView.is_reset_last()UtilsDataView.is_running()UtilsDataView.is_setup()UtilsDataView.is_shutdown()UtilsDataView.is_soft_reset()UtilsDataView.is_stop_already_requested()UtilsDataView.is_user_mode()UtilsDataView.raise_skiptest()UtilsDataView.register_binary_search_path()UtilsDataView.set_requires_data_generation()UtilsDataView.set_requires_mapping()
- spinn_utilities.make_tools package
- Submodules
- spinn_utilities.make_tools.check_database_keys module
- spinn_utilities.make_tools.converter module
- spinn_utilities.make_tools.log_sqllite_database module
LogSqlLiteDatabaseLogSqlLiteDatabase.check_original()LogSqlLiteDatabase.close()LogSqlLiteDatabase.deprecated_database_file()LogSqlLiteDatabase.filename_by_key()LogSqlLiteDatabase.find_databases()LogSqlLiteDatabase.get_directory_id()LogSqlLiteDatabase.get_file_id()LogSqlLiteDatabase.get_log_info()LogSqlLiteDatabase.get_max_log_id()LogSqlLiteDatabase.key_from_filename()LogSqlLiteDatabase.set_log_info()
- spinn_utilities.make_tools.replacer module
- Module contents
- spinn_utilities.ranged package
- Submodules
- spinn_utilities.ranged.ids_view module
- spinn_utilities.ranged.single_view module
- spinn_utilities.ranged.slice_view module
- Module contents
AbstractDictAbstractDict.get_default()AbstractDict.get_ranges()AbstractDict.get_value()AbstractDict.has_key()AbstractDict.ids()AbstractDict.items()AbstractDict.iter_all_values()AbstractDict.iter_ranges()AbstractDict.iteritems()AbstractDict.itervalues()AbstractDict.keys()AbstractDict.reset()AbstractDict.set_value()AbstractDict.values()
AbstractListAbstractList.apply_operation()AbstractList.count()AbstractList.get_default()AbstractList.get_single_value_all()AbstractList.get_single_value_by_ids()AbstractList.get_single_value_by_slice()AbstractList.get_value_by_id()AbstractList.get_values()AbstractList.index()AbstractList.iter()AbstractList.iter_by_id()AbstractList.iter_by_ids()AbstractList.iter_by_selector()AbstractList.iter_by_slice()AbstractList.iter_ranges()AbstractList.iter_ranges_by_id()AbstractList.iter_ranges_by_ids()AbstractList.iter_ranges_by_slice()AbstractList.range_based()
AbstractSizedAbstractViewDualListMultipleValuesExceptionRangeDictionaryRangeDictionary.copy()RangeDictionary.copy_into()RangeDictionary.get_default()RangeDictionary.get_list()RangeDictionary.get_value()RangeDictionary.get_values_by_id()RangeDictionary.has_key()RangeDictionary.ids()RangeDictionary.iter_all_values()RangeDictionary.iter_ranges()RangeDictionary.iter_ranges_by_id()RangeDictionary.iter_ranges_by_ids()RangeDictionary.iter_ranges_by_slice()RangeDictionary.iter_values_by_ids()RangeDictionary.iter_values_by_slice()RangeDictionary.keys()RangeDictionary.list_factory()RangeDictionary.set_default()RangeDictionary.set_value()RangeDictionary.update_safe_iter_all_values()RangeDictionary.view_factory()
RangedListRangedList.as_list()RangedList.copy()RangedList.copy_into()RangedList.get_default()RangedList.get_ranges()RangedList.get_single_value_by_ids()RangedList.get_single_value_by_slice()RangedList.get_value_by_id()RangedList.is_list()RangedList.iter_by_slice()RangedList.iter_ranges()RangedList.iter_ranges_by_slice()RangedList.listness_check()RangedList.range_based()RangedList.set_default()RangedList.set_value()RangedList.set_value_by_id()RangedList.set_value_by_ids()RangedList.set_value_by_selector()RangedList.set_value_by_slice()
RangedListOfListSingleList
- spinn_utilities.testing package
- spinn_utilities.typing package
Submodules¶
spinn_utilities.abstract_base module¶
A trimmed down version of standard Python Abstract Base classes.
- class spinn_utilities.abstract_base.AbstractBase(name: str, bases: Tuple[Type, ...], namespace: Dict[str, Any], **kwargs: Any)[source]¶
Bases:
typeMetaclass for defining Abstract Base Classes (AbstractBases).
Use this metaclass to create an AbstractBase. An AbstractBase can be subclassed directly, and then acts as a mix-in class.
This is a trimmed down version of ABC. Unlike ABC you can not register unrelated concrete classes.
Usage:
class C(object, metaclass=AbstractBase): @abstractmethod def my_abstract_method(self, ...): ...
- spinn_utilities.abstract_base.abstractmethod(funcobj: T) T[source]¶
A decorator indicating abstract methods.
Requires that the metaclass is
AbstractBaseor derived from it. A class that has a metaclass derived fromAbstractBasecannot be instantiated unless all of its abstract methods are overridden. The abstract methods can be called using any of the normal ‘super’ call mechanisms.Usage:
class C(object, metaclass=AbstractBase): @abstractmethod def my_abstract_method(self, ...): ...
- Returns:
method being wrapped
spinn_utilities.abstract_context_manager module¶
spinn_utilities.bytestring_utils module¶
- spinn_utilities.bytestring_utils.as_hex(byte_string: bytes, start: int | None = None, end: int | None = None) str[source]¶
Returns the byte string as string showing the hex values
- Parameters:
byte_string – data as a byte string
start – the inclusive start of the slice to return. May be None
end – the exclusive end of the slice to return. May be None
- Returns:
Comma-separated hex values
- spinn_utilities.bytestring_utils.as_string(byte_string: bytes, start: int | None = None, end: int | None = None) str[source]¶
Returns the length and the hex values.
The length is always the full length irrespective of the start and end.
- Parameters:
byte_string – data as a byte string
start – The inclusive start of the slice to convert to hexadecimal. May be None
end – The exclusive end of the slice to convert to hexadecimal. May be None
- Returns:
The length of the byte string and the comma separated hex values, as a descriptive string
spinn_utilities.classproperty module¶
spinn_utilities.conf_loader module¶
- spinn_utilities.conf_loader.load_config(local_name: str | None, user_cfg: str | None, defaults: List[str]) CamelCaseConfigParser[source]¶
Load the configuration.
- Parameters:
local_name – Name of the file to look for in the current directory
user_cfg – Path to existing user cfg. This file must exist.
defaults – The list of files to get default configurations from.
- Returns:
the fully-loaded and checked configuration
- spinn_utilities.conf_loader.load_defaults(defaults: List[str]) CamelCaseConfigParser[source]¶
Load the default configuration.
- Parameters:
defaults – The list of files to get default configurations from.
- Returns:
the fully-loaded configuration
spinn_utilities.config_holder module¶
- spinn_utilities.config_holder.add_default_cfg(default: str) None[source]¶
Adds an extra default configuration file to be read after earlier ones.
- Parameters:
default – Absolute path to the configuration file
- spinn_utilities.config_holder.add_template(template: str) None[source]¶
Adds an extra default configuration file to be read after earlier ones.
- Parameters:
template – Absolute path to the template file
- spinn_utilities.config_holder.check_user_cfg() None[source]¶
Checks for a user cfg and if not create one and errors
Expected to be called when options to create a machine are missing
Installs a local configuration file based on the templates.
Then it prints a helpful message and throws an error with the same message.
- spinn_utilities.config_holder.clear_cfg_files(unittest_mode: bool) None[source]¶
Clears any previous set configurations and configuration files.
After this method
add_default_cfg()andset_cfg_files()need to be called.- Parameters:
unittest_mode – Flag to put the holder into unit testing mode
- spinn_utilities.config_holder.config_options(section: str) List[str][source]¶
- Parameters:
section – What section to list options for.
- Returns:
a list of option names for the given section name.
- spinn_utilities.config_holder.configs_loaded() bool[source]¶
- Returns:
True if and only if the configuration was loaded
- spinn_utilities.config_holder.get_config_bool(section: str, option: str) bool[source]¶
Get the Boolean value of a configuration option.
- Parameters:
section – What section to get the option from.
option – What option to read.
- Returns:
The option value.
- Raises:
ConfigException – if the Value would be None
- spinn_utilities.config_holder.get_config_bool_or_none(section: str, option: str, special_nones: List[str] | None = None) bool | None[source]¶
Get the Boolean value of a configuration option.
- Parameters:
section – What section to get the option from.
option – What option to read.
special_nones – What special values to except as None
- Returns:
The option value.
- Raises:
ConfigException – if the Value would be None
- spinn_utilities.config_holder.get_config_float(section: str, option: str) float[source]¶
Get the float value of a configuration option.
- Parameters:
section – What section to get the option from.
option – What option to read.
- Returns:
The option value.
- Raises:
ConfigException – if the Value would be None
- spinn_utilities.config_holder.get_config_float_or_none(section: str, option: str) float | None[source]¶
Get the float value of a configuration option.
- Parameters:
section – What section to get the option from.
option – What option to read.
- Returns:
The option value.
- spinn_utilities.config_holder.get_config_int(section: str, option: str) int[source]¶
Get the integer value of a configuration option.
- Parameters:
section – What section to get the option from.
option – What option to read.
- Returns:
The option value
- Raises:
ConfigException – if the Value would be None
- spinn_utilities.config_holder.get_config_int_or_none(section: str, option: str) int | None[source]¶
Get the integer value of a configuration option.
- Parameters:
section – What section to get the option from.
option – What option to read.
- Returns:
The option value
- Raises:
ConfigException – if the Value would be None
- spinn_utilities.config_holder.get_config_str(section: str, option: str) str[source]¶
Get the string value of a configuration option.
- Parameters:
section – What section to get the option from.
option – What option to read.
- Returns:
The option value
- Raises:
ConfigException – if the Value would be None
- spinn_utilities.config_holder.get_config_str_list(section: str, option: str, token: str = ',') List[str][source]¶
Get the string value of a configuration option split into a list.
- Parameters:
section – What section to get the option from.
option – What option to read.
token – The token to split the string into a list
- Returns:
The list (possibly empty) of the option values
- spinn_utilities.config_holder.get_config_str_or_none(section: str, option: str) str | None[source]¶
Get the string value of a configuration option.
- Parameters:
section – What section to get the option from.
option – What option to read.
- Returns:
The option value
- Raises:
ConfigException – if the Value would be None
- spinn_utilities.config_holder.get_default_cfgs() Tuple[str, ...][source]¶
The default configuration files
This is a read only values to be used outside of normal operations
- Returns:
The default configuration files as a tuple.
- spinn_utilities.config_holder.get_report_path(option: str, section: str = 'Reports', n_run: int | None = None, is_dir: bool = False) str[source]¶
Gets and fixes the path for this option
If the cfg path is relative it will be joined with the run_dir_path.
Creates the path’s directory if it does not exist.
(n_run) and (reset_str) will be replaced
Later updates may replace other bracketed expressions as needed so avoid using brackets in file names
- Parameters:
option – cfg option name
section – cfg section. Needed if not Reports
n_run – If provided will be used instead of the current run number
is_dir – When true will make sure this path exists as a directory. When False will make sure the parent directory is exists.
- Returns:
An unchecked absolute path to the file or directory
- spinn_utilities.config_holder.get_timestamp_path(option: str, section: str = 'Reports') str[source]¶
Gets and fixes the path for this option
If the cfg path is relative it will be joined with the timestamp_path.
Creates the path’s directory if it does not exist.
Later updates may replace bracketed expressions as needed so avoid using brackets in file names
- Parameters:
option – cfg option name
section – cfg section. Needed if not Reports
- Returns:
An unchecked absolute path to the file or directory
- spinn_utilities.config_holder.has_config_option(section: str, option: str) bool[source]¶
Check if the section has this configuration option.
- Parameters:
section – What section to check
option – What option to check.
- Returns:
True if and only if the option is defined. It may be None
- spinn_utilities.config_holder.is_config_none(section: str, option: str) bool[source]¶
Check if the value of a configuration option would be considered None
- Parameters:
section – What section to get the option from.
option – What option to read.
- Returns:
True if and only if the value would be considered None
- spinn_utilities.config_holder.load_config(config_file: str) CamelCaseConfigParser[source]¶
Reads in all the configuration files, resetting all values.
- Raises:
ConfigException – If called before setting defaults
- Returns:
A fully loaded parser object
- spinn_utilities.config_holder.logging_parser(config: CamelCaseConfigParser) None[source]¶
Create the root logger with the given level.
Create filters based on logging levels
- spinn_utilities.config_holder.set_config(section: str, option: str, value: str | None) None[source]¶
Sets the value of a configuration option.
This method should only be called by the simulator or by unit tests.
- Parameters:
section – What section to set the option in.
option – What option to set.
value – Value to set option to
- Raises:
ConfigException – If called unexpectedly
spinn_utilities.config_setup module¶
spinn_utilities.exceptions module¶
- exception spinn_utilities.exceptions.ConfigException[source]¶
Bases:
SpiNNUtilsExceptionRaised when reading or setting configurations went wrong.
- exception spinn_utilities.exceptions.DataNotMocked(data: str)[source]¶
Bases:
DataNotYetAvialableRaised when trying to get data before a mocked simulator has created it.
- Parameters:
data – Name of data accessed but not mocked
- exception spinn_utilities.exceptions.DataNotYetAvialable(data: str)[source]¶
Bases:
SpiNNUtilsExceptionRaised when trying to get data before simulator has created it.
- Parameters:
data – Name of the data that was accessed before it was created.
- exception spinn_utilities.exceptions.IllegalWriterException[source]¶
Bases:
SpiNNUtilsExceptionRaised when trying to create a writer other than setup or Mock.
- exception spinn_utilities.exceptions.InvalidDirectory(name: str, value: str)[source]¶
Bases:
SpiNNUtilsExceptionRaised when trying to set an invalid directory.
- Parameters:
name – The field trying to be set
value – The path that is invalid
- exception spinn_utilities.exceptions.NotSetupException(data: str)[source]¶
Bases:
SpiNNUtilsExceptionRaised when trying to get data before simulator has been setup.
- Parameters:
data – The value not yet setup
- exception spinn_utilities.exceptions.ShutdownException(data: str)[source]¶
Bases:
SpiNNUtilsExceptionRaised when trying to get simulator data after it has been shut down.
- Parameters:
data – Name of data being accessed after shutdown
- exception spinn_utilities.exceptions.SimulatorNotRunException[source]¶
Bases:
SpiNNUtilsExceptionRaised when trying to reset or stop before starting.
- exception spinn_utilities.exceptions.SimulatorNotSetupException[source]¶
Bases:
SpiNNUtilsExceptionRaised when trying to get simulator before it has been setup.
- exception spinn_utilities.exceptions.SimulatorRunningException[source]¶
Bases:
SpiNNUtilsExceptionRaised when trying an action that should not happen while the simulator is running.
- exception spinn_utilities.exceptions.SimulatorShutdownException[source]¶
Bases:
SpiNNUtilsExceptionRaised when trying to get simulator after it has been shut down.
- exception spinn_utilities.exceptions.SpiNNUtilsException[source]¶
Bases:
ExceptionSuperclass of all exceptions from the SpiNNUtils module.
- exception spinn_utilities.exceptions.UnexpectedCException[source]¶
Bases:
SpiNNUtilsExceptionRaised when the converter (which replaces log messages) found a pattern it did not expect and cannot handle.
- exception spinn_utilities.exceptions.UnexpectedStateChange[source]¶
Bases:
SpiNNUtilsExceptionRaised when trying to change the state in an unexpected way.
spinn_utilities.executable_finder module¶
- class spinn_utilities.executable_finder.ExecutableFinder[source]¶
Bases:
objectManages a set of folders in which to search for binaries, and allows for binaries to be discovered within this path.
- add_path(path: str) None[source]¶
Adds a path to the set of folders to be searched. The path is added to the end of the list, so it is searched after all the paths currently in the list.
- Parameters:
path – The path to add
- property binary_paths: str¶
The set of folders to search for binaries, as a printable colon-separated string.
- check_executable_path(executable_name: str) bool[source]¶
Checks for an executable within the set of folders.
Unlike get_executable_path(s) does not log the path as used.
- Parameters:
executable_name – The name of the executable to find
- Returns:
True if found. Then get_executable_path will work
- check_logs() None[source]¶
Compares the aplx files used against the ones available for use
Reports the aplx files never used.
- get_executable_path(executable_name: str) str[source]¶
Finds an executable within the set of folders. The set of folders is searched sequentially and the first match is returned.
- Parameters:
executable_name – The name of the executable to find
- Returns:
The full path of the discovered executable
- Raises:
KeyError – If no executable was found in the set of folders
- get_executable_paths(executable_names: str) List[str][source]¶
Finds each executable within the set of folders.
The names are assumed to be comma separated The set of folders is searched sequentially and the first match for each name is returned.
Names not found are ignored and not added to the list.
- Parameters:
executable_names – The name of the executable to find. Assumed to be comma separated.
- Returns:
The full path of the discovered executable, or
Noneif no executable was found in the set of folders
spinn_utilities.find_max_success module¶
- spinn_utilities.find_max_success.find_max_success(max_possible: int, check: Callable[[int], bool]) int[source]¶
Finds the maximum value that will pass the check
- Parameters:
max_possible – The maximum value that should be tested.
check – A Boolean function that given an int value returns True for every value up and including the cut-off and False for every value greater than the cut-off
- Returns:
The highest value that returns true for the check but is not more than the max_possible
- spinn_utilities.find_max_success.search_for_max_success(best_success: int, min_fail: int, check: Callable[[int], bool]) int[source]¶
Finds the maximum value in the range that pass the check
- Parameters:
best_success – A minimum value that needs not be tested because it is either known to succeed or is a flag for total failure. Can be negative
min_fail – A maximum value that needs not be tested because it is either known to fail or one more than the maximum interesting value but must be greater than best_success but may also be negative
check – A Boolean function that given an int value returns True for every value up and including the cut-off and False for every value greater than the cut-off
- Returns:
The highest value that returns true in the range between best_success and min_fail (both exclusive ends) or best_success if the whole range fails or is empty.
spinn_utilities.helpful_functions module¶
- spinn_utilities.helpful_functions.gcd(numbers: Collection[int] = (), /) int[source]¶
- spinn_utilities.helpful_functions.gcd(number: int, /, *numbers: int) int
Greatest common divisor of 1 or more integers.
GIGO: If any of the values are anything except positive int values this function will either produce incorrect results or raise an exception.
- Parameters:
numbers – The positive integers to get the GCD for. This can be one or more int values or a singleton which is an iterator (not empty) of ints.
- Returns:
the GCD
- Raises:
TypeError – If any value cannot be interpreted as an integer or if no values are provided
ZeroDivisionError – May be raised if one of the values is zero
- spinn_utilities.helpful_functions.is_singleton(value: Any) TypeGuard[bool | int | float][source]¶
Tests whether the value is a singleton.
Singleton types are strings and any other class that can not be iterated.
Strings are considered singleton as only rarely will someone use a string to represent an iterable of characters.
- Returns:
True if the value is a singleton, False otherwise.
- spinn_utilities.helpful_functions.lcm(numbers: Collection[int] = (), /) int[source]¶
- spinn_utilities.helpful_functions.lcm(number: int, /, *numbers: int) int
Lowest common multiple of 0, 1 or more integers.
GIGO: If any of the values are anything except positive int values this function will either produce incorrect results or raise an exception.
- Parameters:
numbers – The Positive integers to get the Lowest common multiple for. This can be zero, one or more int values or a singleton which is an iterator (possibly empty) of ints.
- Returns:
the Lowest common multiple, or 1 if numbers is empty or an empty iterator
- Raises:
TypeError – If any value cannot be interpreted as an integer
ZeroDivisionError – May be raised if one of the values is zero
spinn_utilities.log module¶
- class spinn_utilities.log.ConfiguredFilter(config: RawConfigParser)[source]¶
Bases:
objectAllow a parent logger to filter a child logger.
- Parameters:
config – Parser that read the cfg files
- class spinn_utilities.log.ConfiguredFormatter(config: CamelCaseConfigParser)[source]¶
Bases:
FormatterDefines the logging format for the SpiNNaker host software.
- Parameters:
config – Parser that read the cfg files
- static construct_logging_parents(config: RawConfigParser) Dict[str, int][source]¶
Create a dictionary of module names and logging levels.
This is based on the values if any found in the cfg files.
- Returns:
A dictionary of module names and logging levels.
- class spinn_utilities.log.FormatAdapter(logger: Logger, extra: Mapping[str, object] | None = None)[source]¶
Bases:
LoggerAdapterAn adaptor for logging with messages that uses Python format strings.
Example:
log = FormatAdapter(logging.getLogger(__name__)) log.info("this message has {} inside {}", 123, 'itself') # --> INFO: this message has 123 inside itself
- Parameters:
logger – Logger being wrapped by this adapter
extra – keyword arguments to pass to the underlying standard LoggerAdapter
- classmethod atexit_handler() None[source]¶
Adds code to print out high level log messages python run ends
- log(level: int, msg: object, *args: object, **kwargs: object) None[source]¶
Delegate a log call to the underlying logger, applying appropriate transformations to allow the log message to be written using Python format string, rather than via %-substitutions.
- process(msg: object, kwargs: Any) Tuple[object, dict][source]¶
Process the logging message and keyword arguments passed in to a logging call to insert contextual information. You can either manipulate the message itself, the keyword arguments or both. Return the message and kwargs modified (or not) to suit your needs.
- Returns:
the message and kwargs arguments in both the call and the underlying logger.
spinn_utilities.log_store module¶
- class spinn_utilities.log_store.LogStore[source]¶
Bases:
objectAPI supported by classes that can store logs for later retrieval.
- abstractmethod get_location() str[source]¶
Retrieves the location of the log store.
- Returns:
Path to the database holding the log store.
spinn_utilities.logger_utils module¶
- spinn_utilities.logger_utils.error_once(logger: FormatAdapter, msg: str) None[source]¶
Write an error message to the given logger where that message should only be written to the logger once.
- Parameters:
logger – The logger to write to.
msg –
The message to write.
Note
This must be a substitution-free message.
- spinn_utilities.logger_utils.reset() None[source]¶
Clear the store of what messages have already been seen.
Note
Only normally needed by test code.
- spinn_utilities.logger_utils.warn_once(logger: FormatAdapter, msg: str) None[source]¶
Write a warning message to the given logger where that message should only be written to the logger once.
- Parameters:
logger – The logger to write to.
msg –
The message to write.
Note
This must be a substitution-free message.
spinn_utilities.ordered_set module¶
- class spinn_utilities.ordered_set.OrderedSet(iterable: Iterable[T] | None = None)[source]¶
Bases:
MutableSet,Generic[T]A set like Object where peek, pop and iterate are in insert order
- Parameters:
iterable – An iterable of items to add to the set.
spinn_utilities.overrides module¶
- class spinn_utilities.overrides.overrides(super_class_method: Callable, *, extend_doc: bool = True)[source]¶
Bases:
objectA decorator for indicating that a method overrides another method in a superclass. This checks that the method does actually exist, copies the doc-string for the method, and enforces that the method overridden is specified, making maintenance easier.
- Parameters:
super_class_method – The method to override in the superclass
extend_doc – True the method doc string should be appended to the super-method doc string, False if the documentation should be set to the super-method doc string only if there isn’t a doc string already
spinn_utilities.package_loader module¶
- spinn_utilities.package_loader.all_modules(directory: str, prefix: str, remove_pyc_files: bool = False) Set[str][source]¶
List all the python files found in this directory giving then the prefix.
Any file that ends in either
.pyor.pycis assume a python module and added to the result set.- Parameters:
directory – path to check for python files
prefix – package prefix top add to the file name
remove_pyc_files – True if
.pycfiles should be deleted
- Returns:
set of python package names
- spinn_utilities.package_loader.load_module(name: str, remove_pyc_files: bool = False, exclusions: List[str] | None = None, gather_errors: bool = True) None[source]¶
Loads this modules and all its children.
- Parameters:
name – name of the modules
remove_pyc_files – True if
.pycfiles should be deletedexclusions – a list of modules to exclude
gather_errors – True if errors should be gathered, False to report on first error
- spinn_utilities.package_loader.load_modules(directory: str, prefix: str, remove_pyc_files: bool = False, exclusions: List[str] | None = None, gather_errors: bool = True) None[source]¶
Loads all the python files found in this directory, giving them the specified prefix.
Any file that ends in either
.pyor.pycis assume a python module and added to the result set.- Parameters:
directory – path to check for python files
prefix – package prefix top add to the file name
remove_pyc_files – True if
.pycfiles should be deletedexclusions – a list of modules to exclude
gather_errors – True if errors should be gathered, False to report on first error
spinn_utilities.ping module¶
- class spinn_utilities.ping.Ping[source]¶
Bases:
objectPlatform-independent ping support.
- static host_is_reachable(ip_address: str) bool[source]¶
Test if a host is unreachable via ICMP ECHO.
Note
This information may be cached in various ways. Transient failures are not necessarily detected or recovered from.
- Parameters:
ip_address – The IP address to ping. Hostnames can be used, but are not recommended.
- Returns:
True if and only if the ping worked when first tried.
- static ping(ip_address: str) int[source]¶
Send a ping (ICMP ECHO request) to the given host. SpiNNaker boards support ICMP ECHO when booted.
- Parameters:
ip_address – The IP address to ping. Hostnames can be used, but are not recommended.
- Returns:
return code of subprocess; 0 for success, anything else for failure
spinn_utilities.progress_bar module¶
- class spinn_utilities.progress_bar.DummyProgressBar(total_number_of_things_to_do: int | Sized, string_describing_what_being_progressed: str, step_character: str = '=', end_character: str = '|')[source]¶
Bases:
ProgressBarThis is a dummy version of the progress bar that just stubs out the internal printing operations with code that does nothing. It otherwise fails in exactly the same way.
- Parameters:
total_number_of_things_to_do – number of steps being shown.. Will use the length of any object if possible.
string_describing_what_being_progressed – text for the bar
step_character – Optional: characters to print
end_character – Optional: characters to print as start and end
- class spinn_utilities.progress_bar.ProgressBar(total_number_of_things_to_do: int | Sized, string_describing_what_being_progressed: str, step_character: str = '=', end_character: str = '|')[source]¶
Bases:
objectProgress bar for telling the user where a task is up to.
- Parameters:
total_number_of_things_to_do – number of steps being shown.. Will use the length of any object if possible.
string_describing_what_being_progressed – text for the bar
step_character – Optional: characters to print
end_character – Optional: characters to print as start and end
- MAX_LENGTH_IN_CHARS = 60¶
- TOO_MANY_ERROR = 'Too many update steps in progress bar! This may be a sign that something else has gone wrong!'¶
- over(collection: Iterable[T], finish_at_end: bool = True) Iterable[T][source]¶
Simple wrapper for the cases where the progress bar is being used to show progress through the iteration over a single collection. The progress bar should have been initialised to the size of the collection being iterated over.
- Parameters:
collection – The base collection (any iterable) being iterated over
finish_at_end – Flag to say if the bar should finish at the end of the collection
- Returns:
An iterable. Expected to be directly used in a for.
spinn_utilities.require_subclass module¶
- spinn_utilities.require_subclass.require_subclass(required_class: Type) Callable[[Type], Type][source]¶
Decorator that arranges for subclasses of the decorated class to require that they are also subclasses of the given class.
Usage example:
@require_subclass(AbstractVertex) class AbstractVirtual(object): ...
- Parameters:
required_class – The class that the subclass of the decorated class must be an instance of (if that subclass is concrete).
- Returns:
The decorate method to be called later
spinn_utilities.safe_eval module¶
- class spinn_utilities.safe_eval.SafeEval(*args: Callable | ModuleType, **kwargs: Any)[source]¶
Bases:
objectThis provides expression evaluation capabilities while allowing the set of symbols exposed to the expression to be strictly controlled.
Sample of use:
>>> import math >>> def evil_func(x): ... print("Hello World!") ... return x/0.0 ... >>> eval_safely = SafeEval(math) >>> eval_safely.eval("math.sqrt(x)", x=1.23) 1.1090536506409416 >>> eval_safely.eval("evil_func(1.23)") Traceback (most recent call last): File "<stdin>", line 1, in <module> File ".../safe_eval.py", line 62, in eval return eval(expression, self._environment, kwargs) File "<string>", line 1, in <module> NameError: name 'evil_func' is not defined
Warning
This is not guaranteed to be safe under all circumstances. It is not designed to be a fully secured interface; it just discourages abuse.
- Parameters:
args –
The symbols to use to populate the global reference table.
Note
All of these symbols must support the __name__ property, but that includes any function, method of an object, or module. If you want to make an object available by anything other than its inherent name, define it in the
eval()call.kwargs – Define the symbols with explicit names. Needed because some symbols (e.g., constants in numpy) do not have names that we can otherwise look up easily.
- eval(expression: str, **kwargs: Any) Any[source]¶
Evaluate an expression and return the result.
- Parameters:
expression – The expression to evaluate
kwargs – The extra symbol bindings to use for this evaluation. This is useful for passing in particular parameters to an individual evaluation run.
- Returns:
The expression result, the type of which will depend on the expression itself and the operations exposed to it.
spinn_utilities.socket_address module¶
- class spinn_utilities.socket_address.SocketAddress(notify_host_name: str | None = None, notify_port_no: int | None = None, listen_port: int | None = None)[source]¶
Bases:
objectData holder for a socket interface for notification protocol.
- Parameters:
notify_host_name – Host to talk to tell that the database (and application) is ready.
notify_port_no – Port to talk to tell that the database (and application) is ready.
listen_port – Port on which to listen for an acknowledgement that the simulation should start.
spinn_utilities.timer module¶
- class spinn_utilities.timer.Timer[source]¶
Bases:
objectA timer used for performance measurements.
Recommended usage:
with Timer() as timer: ... do stuff that takes time ... elapsed_time = timer.measured_interval
or alternatively:
timer = Timer() timer.start_timing() ... do stuff that takes time ... elapsed_time = timer.take_sample()
Mixing these two styles is not recommended.
- start_timing() None[source]¶
Start the timing. Use
take_sample()to get the end.
- take_sample() timedelta[source]¶
Describes how long has elapsed since the instance that the
start_timing()method was last called.- Returns:
now - start_timing