saveBN

pyagrum.saveBN(bn, filename, allowModificationWhenSaving=None)

save a BN into a file using the format corresponding to one of the pyagrum.availableBNExts suffixes.

Parameters:
  • bn (pyagrum.BayesNet) – the BN to save

  • filename (str) – the name of the output file

  • allowModificationWhenSaving (bool) – whether syntax errors in the BN should throw a FatalError or can be corrected. If None, pyagrum.config["core","allowModificationWhenSaving"] is used.

Raises:

pyagrum.InvalidArgument – If the extension is unknown, or if a .o3prm file is saved without import pyagrum.prm.

Return type:

None

Notes

pkl suffix is used to save a BN using pickle. In this case, options are ignored.

jgum/bgum suffixes use the native aGrUM JSON/binary format and also ignore allowModificationWhenSaving.

Warning

In the .jgum, .bgum, .bifxml and .pkl files, a variable whose name needs quotes (see pyagrum.quoteFastName) is written with a quoted name ('X-ray'[3]): pyAgrum 3.3.2 or older reads it with the quotes in the name.

A variable which the fast syntax does not read back exactly (the labels {10|9} of a pyagrum.LabelizedVariable, a description…) is written as a JSON object in the .jgum, .bgum and .pkl files: the file is then of version 2.0 of the GUM format, which pyAgrum 3.4 or older cannot read.

Example

import pyagrum as gum

bn = gum.fastBN("A->B<-C")
gum.saveBN(bn, "model.bif")  # the format is given by the extension
gum.loadBN("model.bif").sizeArcs()
# 2