Skip to content

Configuration for pyAgrum

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

Each key is declared in the defaults with a metadata line ### type :: documentation where the type is int, float, bool, str, an enumeration of the allowed values (svg|png) or a deprecation (deprecated -> section.key). The setter refuses any value that does not respect the declared type and canonicalizes boolean values (any accepted spelling such as yes/on/1 is stored as True or False) as well as enumerated values (stored with their declared casing). config.typed[section, key] gives the value converted according to the declared type, and accessing a deprecated key emits a DeprecationWarning while transparently using its replacement.

See also the tutorial notebooks/99-Tools_configForPyAgrum.

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].

Each key is described in defaults.ini by a metadata line ### type :: documentation where type is int, float, bool, str, an enumeration v1|v2|... or a deprecation deprecated -> section.key. Setting a value that does not respect the declared type raises a ValueError. Accessing a deprecated key emits a DeprecationWarning and transparently uses the replacement key. While values are always stored as strings, config.typed[section, key] gives the value converted according to the declared type. Boolean and enumerated values are canonicalized when set: any accepted boolean spelling (yes/on/1/…) is stored as True or False, an enumerated value is stored with the casing declared in defaults.ini.

See this notebook.

Examples

>>> import pyagrum
>>> pyagrum.config["dynamicBN", "default_graph_size"] = 10
>>> pyagrum.config["dynamicBN", "default_graph_size"]
"10"

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

Give the type and the one-line documentation declared for section.option in defaults.

Examples

>>> pyagrum.config.doc("notebook", "tensor_visible_digits")
"int :: number of visible digits when displaying a tensor"
  • Parameters:
    • section (str) – The section.
    • option (str) – The property.
  • Returns: The metadata as type :: documentation (deprecated -> section.key :: documentation for a deprecated key).
  • Return type: str
  • Raises: SyntaxError – If the section name or the property name does not exist.

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

Give the value associated to section.option, converted according to the type declared in defaults: int and float are converted, bool gives a Python bool, enumerations and str stay strings. Preferably use the typed accessor: config.typed[section, option].

Examples

>>> pyagrum.config.typed["notebook", "tensor_visible_digits"]
4
>>> pyagrum.config.typed["notebook", "tensor_with_colors"]
True
  • Parameters:
    • section (str) – The section.
    • option (str) – The property.
  • Returns: The value, converted according to the declared type.
  • Return type: int | float | bool | str

grep in the configuration any section or property matching the argument. If a section matches the argument, the whole section is displayed.

  • Parameters: search (str) – The string to find.

load pyagrum.ini in the current directory, and change the properties if needed. If pyagrum.ini contains deprecated keys or invalid values, a warning is emitted and pyagrum.ini is rewritten (deprecated keys migrated to their replacement, invalid values removed).

  • 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 the current configuration in the stack

back to defaults

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

Iterate over the whole configuration schema (in the order of the defaults).

Examples

>>> for section, option, meta, default in pyagrum.config.schema():
... print(f"{section}.{option} ({meta.kind}) = {default} : {meta.doc}")
  • Yields: Tuple[str, str, ConfigMetadata, Optional[str]] – section, option, the metadata of the key (type, allowed values, documentation, deprecation target) and its default value (None for a deprecated key).

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

>>> 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.
    • ValueError – If the value does not respect the type declared for this key in defaults.
KeyTypeDefaultDescription
default_maxnumberofthreadsint24default maximum number of threads used by aGrUM
default_jgumindentint-1default indentation when exporting a model to JGum (-1 = compact)
allow_modification_when_savingboolFalseallow to fix syntax errors in a model instead of raising when exporting to external format (BIF, etc.)
KeyTypeDefaultDescription
tensor_visible_digitsint4number of visible digits when displaying a tensor
tensor_with_colorsboolTrueuse a background color gradient for the values in a tensor
tensor_color_0str#FF7F64color for the minimal value of a tensor
tensor_color_1str#7FFF64color for the maximal value of a tensor
tensor_with_fractionboolFalsedisplay the values of a tensor as fractions when possible
tensor_fraction_limitint50maximal denominator for the fraction representation in a tensor
tensor_fraction_round_errorfloat1e-6maximal rounding error when looking for a fraction representation
tensor_fraction_with_latexboolTrueuse LaTeX to render the fractions in a tensor
histogram_horizontal_visible_digitsint2number of visible digits in horizontal histograms
histogram_vertical_visible_digitsint2number of visible digits in vertical histograms
histogram_horizontal_thresholdint8maximal domain size for a horizontal histogram (vertical above)
histogram_line_thresholdint40domain size above which a histogram becomes a line plot
histogram_colorstrdarkseagreencolor of the histogram bars
histogram_edge_colorstrdarkgreencolor of the edges of the histogram bars
histogram_use_percentboolTruedisplay probabilities as percentages in histograms
histogram_discretized_visualisation`histogrambar`histogram
histogram_discretized_scalefloat1.0scale for the histogram of a discretized variable
export_pdf_margin_xint50horizontal margin (in points) when exporting to pdf
export_pdf_margin_yint37vertical margin (in points) when exporting to pdf
histogram_mode`compactclassical`compact
histogram_epsilonfloat1e-8probabilities below this threshold are truncated in histograms
tensor_parent_values`mergerevmergenomerge`
figure_facecolorstr#E0E0E0face color of the matplotlib figures (see matplotlib)
flow_background_colorstrtransparentbackground color of an item in a flow
flow_border_colorstrtransparentborder color of an item in a flow
flow_border_widthint0border width (in pixels) of an item in a flow
graph_format`svgpng`svg
show_inference_timeboolTruedisplay the inference time below an inference graph
default_arc_colorstr#4A4A4Adefault color of the arcs
default_node_bgcolorstr#404040default background color of the nodes
default_node_fgcolorstrwhitedefault font color of the nodes
evidence_bgcolorstrsandybrownbackground color of a node with evidence
evidence_fgcolorstrblackfont color of a node with evidence
default_node_cmapstrPastel1matplotlib color map for the nodes
default_arc_cmapstrBuGnmatplotlib color map for the arcs
default_edge_cmapstrBuGnmatplotlib color map for the edges
default_graph_sizestr5default size (in inches) of a graph (graphviz size, e.g. “5” or “12!” for exact size)
default_graph_inference_sizestr8default size (in inches) of a graph during inference (graphviz size, e.g. “8” or “12!”)
graph_rankdir`TBLR`TB
graph_layout`dotneatofdp
default_markovrandomfield_view`graphfactorgraph`factorgraph
junctiontree_graph_sizestr10size (in inches) of a junction tree (graphviz size, e.g. “10” or “12!”)
junctiontree_with_namesboolTrueshow the variable names in the cliques of a junction tree
junctiontree_separator_bgcolorstrpalegreenbackground color of the separators of a junction tree
junctiontree_separator_fgcolorstrblackfont color of the separators of a junction tree
junctiontree_separator_fontsizeint8font size of the separators of a junction tree
junctiontree_clique_bgcolorstrburlywoodbackground color of the cliques of a junction tree
junctiontree_clique_fgcolorstrblackfont color of the cliques of a junction tree
junctiontree_clique_fontsizeint10font size of the cliques of a junction tree
junctiontree_map_cliquescalefloat0.3scale of the cliques in a junction tree map
junctiontree_map_sepscalefloat0.1scale of the separators in a junction tree map
junctiontree_map_edgelenfloat1length of the edges in a junction tree map
junctiontree_map_sizestr10size (in inches) of a junction tree map (graphviz size, e.g. “10” or “12!”)
graphdiff_missing_stylestrdashedstyle of an arc missing in the compared graph
graphdiff_missing_colorstrredcolor of an arc missing in the compared graph
graphdiff_overflow_stylestrdashedstyle of an arc absent from the reference graph
graphdiff_overflow_colorstrpurplecolor of an arc absent from the reference graph
graphdiff_reversed_stylestrsolidstyle of an arc reversed in the compared graph
graphdiff_reversed_colorstrpurplecolor of an arc reversed in the compared graph
graphdiff_correct_stylestrsolidstyle of an arc identical in both graphs
graphdiff_correct_colorstrgreycolor of an arc identical in both graphs
KeyTypeDefaultDescription
default_node_bgcolorstrcoraldefault background color of the variable nodes
default_node_fgcolorstrblackdefault font color of the variable nodes
default_factor_bgcolorstrburlywooddefault background color of the factor nodes
edge_lengthfloat0.7length of the edges in a factor graph
edge_length_inferencefloat0.9length of the edges in a factor graph during inference
graph_layout`dotneatofdp
KeyTypeDefaultDescription
default_graph_sizestr6default size (in inches) of a dynamic BN (graphviz size, e.g. “6” or “12!”)
KeyTypeDefaultDescription
default_graph_sizestr6default size (in inches) of an influence diagram (graphviz size, e.g. “6” or “12!”)
default_chance_bgcolorstr#808080default background color of the chance nodes
default_chance_fgcolorstrwhitedefault font color of the chance nodes
default_utility_bgcolorstr#50508Adefault background color of the utility nodes
default_utility_fgcolorstrwhitedefault font color of the utility nodes
default_decision_bgcolorstr#9A5050default background color of the decision nodes
default_decision_fgcolorstrwhitedefault font color of the decision nodes
chance_shapestrellipsegraphviz shape of the chance nodes
utility_shapestrhexagongraphviz shape of the utility nodes
decision_shapestrboxgraphviz shape of the decision nodes
decision_arc_stylestrtapered, bold, dottedgraphviz style of the arcs pointing to a decision node
utility_arc_stylestrdashedgraphviz style of the arcs pointing to a utility node
default_id_sizestr6default size (in inches) of an influence diagram (graphviz size, e.g. “6” or “12!”)
default_id_inference_sizestr6default size (in inches) of an influence diagram during inference (graphviz size, e.g. “6” or “12!”)
utility_visible_digitsint2number of visible digits when displaying a utility
utility_show_stdevboolTrueshow the standard deviation together with a utility
utility_show_lossboolFalseshow the loss (negative utility) instead of the utility
KeyTypeDefaultDescription
default_node_bgcolorstr#404040default background color of the nodes
default_node_fgcolorstrwhitedefault font color of the nodes
histo_max_colorstr#BBFFAAcolor for the maximal value in a credal set histogram
KeyTypeDefaultDescription
show_latent_namesboolFalseshow the names of the latent variables
latex_do_prefixstr\text{do}(LaTeX command inserted before an intervention (do) in a formula
latex_do_suffixstr)LaTeX command inserted after an intervention (do) in a formula
default_graph_sizestr2.5default size (in inches) of a causal model (graphviz size, e.g. “2.5” or “12!”)
default_node_bgcolorstr#404040default background color of the nodes
default_node_fgcolorstrwhitedefault font color of the nodes
default_latent_bgcolorstr#A08080default background color of the latent nodes
default_latent_fgcolorstrblackdefault font color of the latent nodes
KeyTypeDefaultDescription
draw_colorstr#008800color of the ROC/PR curve
fill_colorstr#AAEEAAcolor of the area under the ROC/PR curve
KeyTypeDefaultDescription
show_latent_namesboolFalseshow the names of the latent variables
default_graph_sizestr2.5default size (in inches) of a CTBN (graphviz size, e.g. “2.5” or “12!”)
default_node_bgcolorstr#404040default background color of the nodes
default_node_fgcolorstrwhitedefault font color of the nodes
default_latent_bgcolorstr#A08080default background color of the latent nodes
default_latent_fgcolorstrblackdefault font color of the latent nodes
KeyTypeDefaultDescription
default_graph_sizestr5default size (in inches) of a BN mixture (graphviz size, e.g. “5” or “12!”)
default_line_sizefloat1.0default width of the arcs
default_head_sizefloat0.25default size of the arrow heads
default_arrow_typestrnormalgraphviz type of the arrow heads
default_arc_cmapstrGreensmatplotlib color map for the arcs
default_arc_colorstr#4A4A4Adefault color of the arcs
default_arc_stylestrsolidgraphviz style of the arcs
default_node_bgcolorstr#404040default background color of the nodes
default_node_fgcolorstrwhitedefault font color of the nodes
default_layout`dotneatofdp
default_overlapfloat0overlap scaling for the graphviz layout
default_bar_capsizefloat1.5size of the caps on the error bars
default_bar_heightfloat0.8height of the bars in the bar plots
default_boot_histo_scalefloat2.0scale for the bootstrap histograms
default_histo_scalefloat1.0scale for the histograms
correct_arc_stylestrsolidgraphviz style of an arc present in the reference BN
correct_arc_colorstrgreencolor of an arc present in the reference BN
incorrect_arc_stylestrdashedgraphviz style of an arc absent from the reference BN
incorrect_arc_colorstrgreencolor of an arc absent from the reference BN
left_quantilefloat0.2lower quantile used when displaying the distribution of parameters
right_quantilefloat0.8upper quantile used when displaying the distribution of parameters

(none)