sad.utils package
Submodules
sad.utils.job module
- id_generator(size: int = 6, chars: str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789')[source]
Randomly generate an id string.
- Parameters
size (
int
) – The length of the id, in characters.chars (
str
) – The set of characters that the random id string will be choosing from.
- Returns
A randomly generated string.
- Return type
str
- read_from_yaml(filename: str) Dict [source]
Read a local yml configuration file, and extract its
parameters
field and return.- Parameters
config_file (
str
) – A local yml file. Theparameters
field in the yml file contains configurations.- Returns
A dictionary containing configurations to initialize a task.
- Return type
dict
- Raises
IOError – When provided
filename
argument does not point to a valid yml file.AssertionError – When
parameters
is not contained in the yml file.
sad.utils.logging module
- class LoggingFormatter(fmt=None, datefmt=None, style='%')[source]
Bases:
logging.Formatter
A class that inherits from
logging.Formatter
. Instance methodformatTime
will be overwritten to produce the right format.- formatTime(record: logging.LogRecord, datefmt: Optional[str] = None) str [source]
Return the creation time of the specified LogRecord as formatted text.
This method should be called from format() by a formatter which wants to make use of a formatted time. This method can be overridden in formatters to provide for any specific requirement, but the basic behaviour is as follows: if datefmt (a string) is specified, it is used with time.strftime() to format the creation time of the record. Otherwise, an ISO8601-like (or RFC 3339-like) format is used. The resulting string is returned. This function uses a user-configurable function to convert the creation time to a tuple. By default, time.localtime() is used; to change this for a particular formatter instance, set the ‘converter’ attribute to a function with the same signature as time.localtime() or time.gmtime(). To change it for all formatters, for example if you want all logging times to be shown in GMT, set the ‘converter’ attribute in the Formatter class.
- setup_module_level_logger(logger_name_list: List[str], level: int = 20)[source]
Function to setup module level loggers. The format of loggers will be set using to
FORMATTER_STRING
, using classLoggingFormatter
.- Parameters
logger_name_list (
List[str]
) – A list of module names corresponding top-level namespace of loggers.level (
int
) – The level of loggers, determining the threshold of logging severity.
sad.utils.misc module
- my_logit(value: float, EPS: float = 1e-10) float [source]
Take logit of a given value. Input value will be restricted to
[EPS, 1-EPS]
interval.- Parameters
value (
float
) – A value is between(0, 1)
. Due to numerical consideration, the value will be truncated to[EPS, 1-EPS]
whereEPS
is a small number.EPS (
float
) – A small positive number that will be used to maintain numerical stability. Default to1e-10
.
- Returns
The logit of input
value
.- Return type
float
- update_dict_recursively(dict_a: Dict, dict_b: Dict)[source]
A helper function to absorb contents in
dict_b
intodict_a
, recursively.dict_a
will be modified in place.- Parameters
dict_a (
dict
) – First dictionary that absorbs.dict_b (
dict
) – Second dictionary in which all fields will be absorbed intodict_a
.
- Returns
Modified input dictionary
dict_a
.