module documentation

Various tools.

Class AlgorithmList Not in use. Not necessary when the algorithm dict is an OrderedDict anyway.
Class Infolder Contextmanager to do some work in a folder of choice and change dir back in the end.
Class InfolderGoneWithTheWind with InfolderGoneWithTheWind(): ... executes the block in a
Class StringList A microtool to join a list of strings using property as_string.
Class StrList A list of str with search/find functionality.
Function diff_attr return list of [name, val1, val2] triplets for attributes with different values.
Function equals_approximately Undocumented
Function get_version_label Returns a string with the COCO version of the installed postprocessing, potentially adding the hash of the hypervolume reference values from the actual experiments (in the bbob-biobj setting). If algorithmID==None, the set of different hypervolume reference values from all algorithms, read in by the postprocessing, are returned in the string...
Function git Run a git command and return its output.
Function html_subsup typeset base_sub^sup in html math mode
Function legend Undocumented
Function less return a < b, while comparing nan results in False without warning
Function num2str returns the shortest string representation with either significant_digits digits shown or its true value, whichever is shorter.
Function number_of_digits returns the number of non-zero digits of a number, e.g. two for 1200 or three for 2.03.
Function number_to_html usage as number_to_html(num2str(1.023e-12)) == "'-1.0 x 10<sup>-12</sup>'"
Function number_to_latex usage as number_to_latex(num2str(1.023e-12)) == "'-1.0\times10^{-12}'"
Function path_in_package return the absolute path prepended to subpath in this module.
Function prepend_succ_str prepend single digit precision succ as subscript to tex and html strings
Function prepend_to_file "prepend lines the tex-command filename
Function print_done prints a message with time stamp
Function ratio2html return the relative change represented in ratio as html snippet
Function ratio2tex return the relative change represented in ratio as LaTeX snippet
Function replace_in_file "replace a string in the file with another string
Function str_to_latex do replacements in string such that it most likely compiles with latex
Function strip_pathname remove ../ and ./ and leading/trailing blanks and path separators from input string name and replace any remaining path separator with '/'
Function strip_pathname1 remove ../ and ./ and leading/trailing blanks and path separators from input string name, replace any remaining path separator with '/', and keep only the last part of the path
Function strip_pathname2 as strip_pathname1 but keep the last two parts of the path
Function strip_pathname3 as strip_pathname1 and also remove 'noiseless' from the name
Function truncate_latex_command_file truncate file but keep in good latex shape
Variable ratio2thresholds return relative additive change within this range and multiplicative change otherwise, used in ratio2html and ratio2tex
Function _num2str2 another attempt, not used, formats n=0.99, digits=1 poorly, num2str seems good
Function _ratio2str format ratio as additive percentage when in the threshold range
def diff_attr(m1, m2, exclude=('_')):

return list of [name, val1, val2] triplets for attributes with different values.

Attributes whose names start with any string from the exclude list are skipped. Furthermore, only attributes present in both m1 and m2 are compared.

This function was introduced to compare the genericsettings module with its state directly after import. It should be applicable any other two class instances as well.

Details: to "find" the attributes, m1.__dict__ is iterated over.

def equals_approximately(a, b, eps=1e-12):

Undocumented

def get_version_label(algorithmID=None):

Returns a string with the COCO version of the installed postprocessing, potentially adding the hash of the hypervolume reference values from the actual experiments (in the bbob-biobj setting). If algorithmID==None, the set of different hypervolume reference values from all algorithms, read in by the postprocessing, are returned in the string. If more than one reference value is present in the data, the string displays also a warning.

def git(args):

Run a git command and return its output.

All errors are deemed fatal and the system will quit.

WARNING: This method is also defined in ../../code-experiments/tools/cocoutils.py. If you change something you have to change it in both files.

def html_subsup(sub, sup, base='', endlower=''):

typeset base_sub^sup in html math mode

def legend(*args, **kwargs):

Undocumented

def less(a, b):

return a < b, while comparing nan results in False without warning

def num2str(val, significant_digits=2, force_rounding=False, max_predecimal_digits=5, max_postdecimal_leading_zeros=1, remove_trailing_zeros=True):

returns the shortest string representation with either significant_digits digits shown or its true value, whichever is shorter.

force_rounding shows no more than the desired number of significant digits, which means, e.g., 12345 becomes 12000.

remove_trailing_zeros removes zeros, if and only if the value is exactly.

>>> from cocopp import toolsdivers as td
>>> print([td.num2str(val) for val in [12345, 1234.5, 123.45, 12.345, 1.2345, .12345, .012345, .0012345]])
['12345', '1234', '123', '12', '1.2', '0.12', '0.012', '1.2e-3']
def number_of_digits(val, precision=1e-13):

returns the number of non-zero digits of a number, e.g. two for 1200 or three for 2.03.

def number_to_html(number_as_string):

usage as number_to_html(num2str(1.023e-12)) == "'-1.0 x 10<sup>-12</sup>'"

def number_to_latex(number_as_string):

usage as number_to_latex(num2str(1.023e-12)) == "'-1.0\times10^{-12}'"

def path_in_package(sub_path=''):

return the absolute path prepended to subpath in this module.

def prepend_succ_str(succ, tex, html, indent='-0.5em', lindent='\\!\\!\\!\\!'):

prepend single digit precision succ as subscript to tex and html strings

iff 0 < succ < 0.95.

return also a style-command for (negative) indent with html.

def prepend_to_file(filename, lines, maxlines=1000, warn_message=None):

"prepend lines the tex-command filename

def print_done(message=' done'):

prints a message with time stamp

def ratio2html(ratio, signed=True):

return the relative change represented in ratio as html snippet

which may be used within <math>.

def ratio2tex(ratio, signed=True):

return the relative change represented in ratio as LaTeX snippet

to be used in math mode.

def replace_in_file(filename, old_text, new_text):

"replace a string in the file with another string

def str_to_latex(string):

do replacements in string such that it most likely compiles with latex

def strip_pathname(name):

remove ../ and ./ and leading/trailing blanks and path separators from input string name and replace any remaining path separator with '/'

def strip_pathname1(name):

remove ../ and ./ and leading/trailing blanks and path separators from input string name, replace any remaining path separator with '/', and keep only the last part of the path

def strip_pathname2(name):

as strip_pathname1 but keep the last two parts of the path

def strip_pathname3(name):

as strip_pathname1 and also remove 'noiseless' from the name

def truncate_latex_command_file(filename, keeplines=200):

truncate file but keep in good latex shape

ratio2thresholds: tuple[float, ...] =

return relative additive change within this range and multiplicative change otherwise, used in ratio2html and ratio2tex

def _num2str2(n, digits=2, signed=False):

another attempt, not used, formats n=0.99, digits=1 poorly, num2str seems good

def _ratio2str(ratio, formplus='{}%', formtimes='&times;{}', formdiv='&divide;{}', signed=True, thresholds=(0.5, 1.995)):

format ratio as additive percentage when in the threshold range

and as factor otherwise. Assume ratio >= 0.

A single threshold indicates the upper value. formtimes or formdiv may be None thereby ignoring the respective threshold.