MetaGraphs.jl icon indicating copy to clipboard operation
MetaGraphs.jl copied to clipboard

save/load not working?

Open cormullion opened this issue 3 years ago • 4 comments

I thought this should work, but it doesn't:

using Graphs
using MetaGraphs

g = path_graph(5)
mg = MetaGraph(g, 3.0)
set_prop!(mg, :description, "This is a metagraph.")

savegraph("/tmp/test_graph.lg", mg)

mg1 = loadgraph("/tmp/test_graph.lg")
ERROR: LoadError: BoundsError: attempt to access 2-element Vector{SubString{String}} at index [3]
Stacktrace:
  [1] getindex
    @ ./array.jl:861 [inlined]
  [2] indexed_iterate
    @ ./tuple.jl:90 [inlined]
  [3] _parse_header(s::SubString{String})
    @ Graphs ~/.julia/packages/Graphs/zrMoC/src/persistence/lg.jl:62
  [4] loadlg(io::IOStream, gname::String)
    @ Graphs ~/.julia/packages/Graphs/zrMoC/src/persistence/lg.jl:104
  [5] loadgraph
    @ ~/.julia/packages/Graphs/zrMoC/src/persistence/lg.jl:147 [inlined]
  [6] #120
    @ ~/.julia/packages/Graphs/zrMoC/src/persistence/common.jl:15 [inlined]
  [7] open(::Graphs.var"#120#121"{String, LGFormat}, ::String, ::Vararg{String}; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ Base ./io.jl:330
  [8] open
    @ ./io.jl:328 [inlined]
  [9] loadgraph
    @ ~/.julia/packages/Graphs/zrMoC/src/persistence/common.jl:14 [inlined]
 [10] loadgraph(fn::String)
    @ Graphs ~/.julia/packages/Graphs/zrMoC/src/persistence/common.jl:18
 [11] top-level scope
    @ untitled-55510ba3fa4677b8db7457446bdad39a:10

Is it something to do with the compressed format - savegraph(.. ... metagraph ... , compress=false) doesn't work either?

Using Graphs v1.7.0, MetaGraphs v0.7.1, Julia 1.7.

cormullion avatar May 29 '22 11:05 cormullion

savegraph saves by default a MetaGraphs using JLD2.jl to HDF5 format. loadgraph loads by default a MetaGraphs using LG format. You can load the graph using loadgraph(fn, gname, MGFormat())

We should probably have a consistent behavior here.

etiennedeg avatar May 30 '22 13:05 etiennedeg

Thanks, didn't see MGFormat() anywhere...

cormullion avatar May 30 '22 14:05 cormullion

Yes, I found it by digging in the code, we should also document this.

etiennedeg avatar May 30 '22 14:05 etiennedeg

for GraphML support there is this PR https://github.com/JuliaGraphs/GraphIO.jl/pull/49 on hold with an ongoing discussion. Please feel free to share your opinion.

filchristou avatar Aug 05 '22 05:08 filchristou