Configuration for pyAgrum

Configuration for pyAgrum is centralized in an object pyAgrum.config, singleton of the (hidden) class PyAgrumConfiguration.

class pyAgrum.config.PyAgrumConfiguration(*args, **kwargs)

PyAgrumConfiguration is a the pyAgrum configuration singleton. The configuration is build as a classical ConfigParser with read-only structure. Then a value is adressable using a double key: [section,key].

See this notebook.

Examples

>>> gum.config['dynamicBN','default_graph_size']=10
>>> gum.config['dynamicBN','default_graph_size']
"10"
add_hook(fn)
diff()

print the diff between actual configuration and the defaults. This is what is saved in the file pyagrum.ini by the method PyAgrumConfiguration.save()

get(section, option)

Give the value associated to section.option. Preferably use __getitem__ and __setitem__.

Examples

>>> gum.config['dynamicBN','default_graph_size']=10
>>> gum.config['dynamicBN','default_graph_size']
"10"
Arguments:

section {str} – the section option {str} – the property

Returns:

str – the value (as string)

grep(search)

grep in the configuration any section or properties matching the argument. If a section match the argume, all the section is displayed.

Arguments:

search {str} – the string to find

load()

load pyagrum.ini in the current directory, and change the properties if needed

Raises:

FileNotFoundError: if there is no pyagrum.ini in the current directory

pop()

Pop the last config from the stack and set it as the current configuration

push()

Push the current configuration in the stack

reset()

back to defaults

run_hooks()
save()

Save the diff with the defaults in pyagrum.ini in the current directory

set(section, option, value, no_hook=False)

set a property in a section. Preferably use __getitem__ and __setitem__.

Examples

>>> gum.config['dynamicBN','default_graph_size']=10
>>> gum.config['dynamicBN','default_graph_size']
"10"
Arguments:

section {str} – the section name (has to exist in defaults) option {str} – the option/property name (has to exist in defaults) value {str} – the value (will be store as string) no_hook {bool} – (optional) should this call trigger the hooks ?

Raises:

SyntaxError: if the secion name or the property name does not exist