JuliaGraphs / MetaGraphsNext.jl

A package for graphs with vertex labels and metadata in Julia
http://juliagraphs.org/MetaGraphsNext.jl/
Other
73 stars 17 forks source link

MetaGraph to DOT seems buggy #73

Open tecosaur opened 10 months ago

tecosaur commented 10 months ago

MWE

julia> using MetaGraphsNext # v0.6.0

julia> struct Foo end

julia> g2 = MetaGraph(DiGraph(), label_type=Int, vertex_data_type=Foo)
Meta graph based on a SimpleDiGraph{Int64} with vertex labels of type Int64, vertex metadata of type Foo, edge metadata of type Nothing, graph metadata given by nothing, and default weight 1.0

julia> savegraph("data.dot", g2, DOTFormat())
ERROR: MethodError: no method matching length(::Foo)

Closest candidates are:
  length(::LibGit2.GitStatus)
   @ LibGit2 ~/.julia/juliaup/julia-1.10.0-rc1+0.x64.linux.gnu/share/julia/stdlib/v1.10/LibGit2/src/status.jl:21
  length(::Tables.DictRowTable)
   @ Tables ~/.julia/packages/Tables/NSGZI/src/dicts.jl:118
  length(::Base.MethodSpecializations)
   @ Base reflection.jl:1164
  ...

Stacktrace:
 [1] show_meta_list(io::IOStream, meta::Foo)
   @ MetaGraphsNext ~/.julia/packages/MetaGraphsNext/YvA1m/src/persistence.jl:31
 [2] savedot(io::IOStream, meta_graph::MetaGraph{…})
   @ MetaGraphsNext ~/.julia/packages/MetaGraphsNext/YvA1m/src/persistence.jl:76
 [3] #32
   @ ~/.julia/packages/MetaGraphsNext/YvA1m/src/persistence.jl:100 [inlined]
 [4] open(::MetaGraphsNext.var"#32#33"{MetaGraph{…}}, ::String, ::Vararg{String}; kwargs::@Kwargs{})
   @ Base ./io.jl:396
 [5] open
   @ Base ./io.jl:393 [inlined]
 [6] savegraph(file::String, meta_graph::MetaGraph{…}, ::DOTFormat)
   @ MetaGraphsNext ~/.julia/packages/MetaGraphsNext/YvA1m/src/persistence.jl:99
 [7] top-level scope
   @ REPL[13]:1
Some type information was truncated. Use `show(err)` to see complete types.
gdalle commented 10 months ago

It's not clear to me how custom Julia types should be serialized as part of the DOT format.

https://en.m.wikipedia.org/wiki/DOT_(graph_description_language)

Perhaps JLD and friends are better options for this use case?

tecosaur commented 10 months ago

In this case, I'm just serialising to DOT to try it as an alternative for plotting. Perhaps a better behaviour than current would be either:

gdalle commented 5 months ago

That sounds reasonable, if you want to open a PR because it serves your use case I'll be happy to try and review