loadGraph
- pyagrum.loadGraph(filename)
Read a graph from a file, its format being given by its extension: .jgum (GUM, text), .bgum (GUM, binary) or .pkl (pickle).
- Parameters:
filename (
str) – the name of the file (seepyagrum.availableGraphExts())- Returns:
the graph, of the class written in the file
- Return type:
pyagrum.DiGraphorpyagrum.DAGorpyagrum.UndiGraphorpyagrum.MixedGraphorpyagrum.PDAGorpyagrum.ChainGraphorpyagrum.MarkedGraphorpyagrum.PAGorpyagrum.CPDAGorpyagrum.MPDAGorpyagrum.MAGorpyagrum.EssentialGraph- Raises:
pyagrum.GumIOError – if the file can not be read or is not a graph in the GUM format, or if the graph does not respect the properties of its class (e.g. a cycle in a DAG)
pyagrum.InvalidArgument – if the extension is unknown (see
pyagrum.availableGraphExts())
Example
import pyagrum as gum
gum.saveGraph(gum.fastPDAG("A->B-C"), "graph.jgum")
g = gum.loadGraph("graph.jgum")
type(g).__name__
# 'PDAG'
sorted(g.arcs()), sorted(g.edges())
# ([(0, 1)], [(1, 2)])