Undocumented
Class |
|
print dimension when changed and a single symbol for each call. |
Class |
|
a dict with observer options which can be passed to the (C-based) Observer via the as_string property. |
Class |
|
The non-anytime problem class. |
Class |
|
Count the number of consecutive instances of the same function. |
Class |
|
print minimal info during benchmarking. |
Function | about |
Return True if the floating point number ${a} and ${b} are about equal. |
Function | args |
return a dict from a list of "name=value" strings. |
Function | ascetime |
return elapsed time as str. |
Function | dict |
return a pruned dict so that ast.literal_eval(repr(dict_)) works. |
Function | forgiving |
Do nothing if import fails, return the imported module otherwise. |
Function | print |
print without newline but with flush |
Function | read |
return file content evaluated as Python literal (e.g. a dict ), |
Function | write |
write a simplified parameters dictionary to a file, |
return a dict
from a list of "name=value" strings.
args
come in the form of a list
of "name=value" strings
without spaces, like ["budget_multiplier=100"].
Return dict(arg.split(split) for arg in args) in the most
basic case, but additionally (i) checks that the keys of this
dict
are known names, (ii) evaluates the values in some cases
and (iii) handles specials
.
known_names
is an iterable (dict
or list
or tuple
) of strings.
If known_names is None, all args are processed, otherwise a
ValueError
is raised for unknown names. This is useful if we
want to re-assign variables (overwrite default values) and avoid
spelling mistakes pass silently.
The value is processed as a Python literal with ast.literal_eval
or remains a str
when this is unsuccessful.
specials
is a dict
and can currently only contain 'batch',
followed by "name1/name2" as value. name1 and name2 are
then assigned from the values in arg
, for example to 2 and 4 with
batch=2/4.
A main usecase is to process sys.argv[1:] into a dict
in a
python script, like:
command_line_dict = args_to_dict(sys.argv[1:], globals()) globals().update(command_line_dict)
>>> import cocoex >>> d = cocoex.utilities.args_to_dict(["budget=2.3", "bed=bed-name", "number=4"], ... ["budget", "bed", "number", "whatever"]) >>> len(d) 3 >>> assert d['bed'] == 'bed-name' >>> assert isinstance(d["budget"], float)
return a pruned dict
so that ast.literal_eval(repr(dict_)) works.
Keys that start with entries from ignore_list
when interpreted as
str
are removed, by default those starting with _ or self,
where ignore_list
must be a str
or a tuple
of str
.
See also write_setting
.
Do nothing if import fails, return the imported module otherwise.
Usage:
cma = forgiving_import('cma')
in place of:
import cma
This is helpful to keep some code smoothly working when cma
is not
installed and not used in the current use case.
return file content evaluated as Python literal (e.g. a dict
),
return None
if filename
is not a valid path.
If warn
, throw a warning when the file filename
does not exist.
A typical usecase could be old_multiplier = read_setting('parameters.pydat')['budget_multiplier'].
See also write_setting
.
write a simplified parameters dictionary to a file,
for keeping a record or, e.g., for checking the budget_multiplier
later.
A typical usecase is write_setting(locals(), 'parameters.pydat').
When ignore_list is not None it is passed to dict_to_eval
which determines which parameters are written or omitted. By default,
keys starting with _ or self are omitted and items that bail on
literal_eval
.
See also dict_to_eval
and read_setting
.