bingo.util package#

Submodules#

bingo.util.argument_validation module#

Argument validation for functions.

This modules contains a decorator which will perform input argument validation for a function.

class bingo.util.argument_validation.FunctionArgChecker(func, positional_args, keyword_args)#

Bases: object

A functor for managing arguments and performing validation checks

Parameters:
  • func (function) – the function for which argument checking will be performed

  • positional_args (tuple) – the positional arguments passed to the function

  • keyword_args (dict) – the keyword arguments passed to the function

bingo.util.argument_validation.argument_validation(**argchecks)#

Function input argument validation:

Parameters:

argchecks (dict) – keyword arguments used as a dictionary of checks to be performed on input arguments

Notes

Defaulted arguments are ignored in checking.

Examples

Argument validation for x between 0-10 and y greater than 3.14

>>> @argument_validation(x={">=": 0, "<=": 10},
...                      y={">": 3.14})
... def some_function(x, y=10):
...    pass

Argument validation for algorithm is “bubble” or “quick”

>>> @argument_validation(algorithm={"in": ["bubble", "quick"]})
... def sort(algorithm):
...     pass

bingo.util.log module#

This Logging module is just a simplified interface to the python built-in logging library. Its sets up default logging options which are typical of most bingo runs.

class bingo.util.log.DiagnosticsFilter(filter_out)#

Bases: Filter

This is a filter which filters based on the identifier “<diagnostics>” at the beginning of a log message

Parameters:

filter_out (bool) – Whether to filter-out or filter-in stats messages

filter(record)#

If filter_out is True, will block all records with identifier “<diagnostics>” set to True. Otherwise, will only allow records with identifier “<diagnostics>” set to True.

Parameters:

record (LogRecord) – the record to filter

Returns:

whether the record will be logged or not

Return type:

bool

class bingo.util.log.MpiFilter(add_proc_number=True)#

Bases: Filter

This is a filter which filters out messages from auxiliary processes at the INFO level

Parameters:

add_proc_number (bool (optional)) – Add processor identifier to multi-processor log messages. default True.

filter(record)#

Filters out INFO records from processes that aren’t rank 0.

Also adds process rank to the record’s message if add_proc_number is set to True.

Parameters:

record (LogRecord) – the record to filter

Returns:

whether the record will be logged or not

Return type:

bool

class bingo.util.log.StatsFilter(filter_out)#

Bases: Filter

This is a filter which filters based on the identifier “<stats>” at the beginning of a log message

Parameters:

filter_out (bool) – Whether to filter-out or filter-in stats messages

filter(record)#

If filter_out is True, will block all records with identifier “<stats>” set to True. Otherwise, will only allow records with identifier “<stats>” set to True.

Parameters:

record (LogRecord) – the record to filter

Returns:

whether the record will be logged or not

Return type:

bool

bingo.util.log.configure_logging(verbosity='standard', module=False, timestamp=False, stats_file=None, logfile=None, diagnostics_file=None)#

Configuration of Bingo logging

Parameters:
  • verbosity (str or int) – verbosity options are “quiet”, “standard”, “detailed”, “debug”, or an integer (0 - 100) that corresponds to typical python log level.

  • module (bool) – whether to show the module name on logging output. Default False

  • timestamp (bool) – whether to show a time stamp on logging output. Default False

  • stats_file (str) – (optional) file name for evolution statistics to be logged to

  • logfile (str) – (optional) file name for a copy of the log to be saved

  • diagnostics_file (str) – (optional) file name for evolution diagnostics to be logged to

bingo.util.probability_mass_function module#

This module implements a probability mass function from which single samples can be drawn

class bingo.util.probability_mass_function.ProbabilityMassFunction(items=None, weights=None)#

Bases: object

The ProbabilityMassFunction (PMF) class is designed to allow for easy creation and use of a probability mass function. Items and associated probability weights are given. Samples (items) can then be drawn from the pmf according to their relative weights.

Parameters:
  • items (list, optional) – The starting items in the PMF.

  • weights (list-like of numeric, optional) – The relative weights of the items. The default is even weighting.

items#

The current items in the PMF

Type:

list

normalized_weights#

The probabilities of items

Type:

list-like numeric

add_item(new_item, new_weight=None)#

Adds a single item to the PMF.

Parameters:
  • new_item – The item to be added.

  • new_weight (numeric) – (Optional) The weight associated with the item. The default is the average weight of the other items.

draw_sample()#

Draw a sample from the PMF

Draw a random sample from the PMF according to the probabilities associated with weighting of items.

Return type:

A single item

Module contents#