How can I save and load a MetaGraph object from LightGraphs, and MetaGraphs, so that if I load the metagraph I still have the metadata?
Right now I have a metagraph mg
that I save using:
LightGraphs.savegraph("net.lg", mg)
But trying to reload it :
reloaded = LightGraphs.loadgraph("net.lg")
gives me the following:
BoundsError: attempt to access 2-element Array{SubString{String},1} at index [3]
Is there anyway to read in the metagraphs in the MetaGaphs package?
We support MetaGraphs persistence using a JLD format provided by JLD2.jl:
using LightGraphs, MetaGraphs
julia> g = Graph(10,20)
{10, 20} undirected simple Int64 graph
julia> mg = MetaGraph(g)
{10, 20} undirected Int64 metagraph with Float64 weights defined by :weight (default weight 1.0)
julia> savegraph("foo.mg", mg)
1
julia> mg2 = loadgraph("foo.mg", MGFormat())
{10, 20} undirected Int64 metagraph with Float64 weights defined by :weight (default weight 1.0)
julia> mg2 == mg
true
Note that you need to specify MGFormat()
in the loadgraph
, otherwise LightGraphs won't know what type of graph you're trying to load.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With