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
>>> import pyagrum >>> pyagrum.config["dynamicBN", "default_graph_size"] = 10 >>> pyagrum.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.iniby the method PyAgrumConfiguration.save()
- get(section, option)
Give the value associated to section.option. Preferably use
__getitem__and__setitem__.Examples
>>> pyagrum.config["dynamicBN", "default_graph_size"] = 10 >>> pyagrum.config["dynamicBN", "default_graph_size"] "10"
- Parameters:
section (str) – The section.
option (str) – The property.
- Returns:
The value (as string).
- Return type:
str
- grep(search)
grep in the configuration any section or properties matching the argument. If a section match the argume, all the section is displayed.
- Parameters:
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.iniin the current directory
- set(section, option, value, no_hook=False)
set a property in a section. Preferably use
__getitem__and__setitem__.Examples
>>> pyagrum.config["dynamicBN", "default_graph_size"] = 10 >>> pyagrum.config["dynamicBN", "default_graph_size"] "10"
- Parameters:
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 stored as string).
no_hook (bool, optional) – Should this call trigger the hooks?
- Raises:
SyntaxError – If the section name or the property name does not exist.