JuliaGraphs / MetaGraphs.jl

Graph data structures with multiple heterogeneous metadata for Graphs.jl.
https://juliagraphs.org/MetaGraphs.jl/
Other
59 stars 9 forks source link

save/load not working? #39

Open cormullion opened 2 years ago

cormullion commented 2 years ago

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.

etiennedeg commented 2 years ago

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.

cormullion commented 2 years ago

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

etiennedeg commented 2 years ago

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

filchristou commented 2 years ago

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.