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)
Section titled “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
>>> import pyagrum as gum>>> gum.config["dynamicBN", "default_graph_size"] = 10>>> gum.config["dynamicBN", "default_graph_size"]"10"add_hook(fn)
Section titled “add_hook(fn)”diff()
Section titled “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)
Section titled “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)
Section titled “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()
Section titled “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 the last config from the stack and set it as the current configuration
push()
Section titled “push()”Push the current configuration in the stack
reset()
Section titled “reset()”back to defaults
run_hooks()
Section titled “run_hooks()”save()
Section titled “save()”Save the diff with the defaults in pyagrum.ini in the current directory
set(section, option, value, no_hook=False)
Section titled “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