sisl / BayesNets.jl

Bayesian Networks for Julia
Other
218 stars 48 forks source link

BayesNets.plot error: no method matching plot #139

Closed SEICS closed 2 years ago

SEICS commented 2 years ago

Hi,

I am new to BayesNets.jl and I am really interested in this new PPL and would like to use it for my project. When I went through some tutorials, I found that BayesNets.plot doesn't work on neither my Jupyter notebook nor my Julia console. I have installed all packages specified at below.

The code for reproducing error from BayesNets.jl docs (Section: representation):

using Random
Random.seed!(0) # seed the random number generator to 0, for a reproducible demonstration
using BayesNets
using TikzGraphs # required to plot tex-formatted graphs (recommended), otherwise GraphPlot.jl is used
using TikzPictures
bn = BayesNet()
push!(bn, StaticCPD(:a, Normal(1.0)))
push!(bn, LinearGaussianCPD(:b, [:a], [2.0], 3.0, 1.0))
plot = BayesNets.plot(bn)
TikzPictures.save(SVG("plot1"), plot)

Expected output:

Screenshot 2022-07-06 at 16 38 01

The corresponding error message:

ERROR: MethodError: no method matching plot(::LightGraphs.SimpleGraphs.SimpleDiGraph{Int64}; layout=TikzGraphs.Layouts.Layered(-1, -1), labels=AbstractString["a", "b"])
Closest candidates are:
  plot(::Any, ::TikzGraphs.Layouts.Layout) at ~/.julia/packages/TikzGraphs/wTGtk/src/TikzGraphs.jl:44 got unsupported keyword arguments "layout", "labels"
  plot(::Any, ::TikzGraphs.Layouts.Layout, ::Vector{T}; args...) where T<:AbstractString at ~/.julia/packages/TikzGraphs/wTGtk/src/TikzGraphs.jl:44
  plot(::Any, ::Vector{T}; args...) where T<:AbstractString at ~/.julia/packages/TikzGraphs/wTGtk/src/TikzGraphs.jl:45
  ...
Stacktrace:
 [1] plot(g::LightGraphs.SimpleGraphs.SimpleDiGraph{Int64}, labels::Vector{AbstractString}; args::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ TikzGraphs ~/.julia/packages/TikzGraphs/wTGtk/src/TikzGraphs.jl:45
 [2] plot(g::LightGraphs.SimpleGraphs.SimpleDiGraph{Int64}, labels::Vector{AbstractString})
   @ TikzGraphs ~/.julia/packages/TikzGraphs/wTGtk/src/TikzGraphs.jl:45
 [3] plot(dag::LightGraphs.SimpleGraphs.SimpleDiGraph{Int64}, nodelabel::Vector{AbstractString})
   @ BayesNets ~/.julia/packages/BayesNets/yBu0u/src/io.jl:20
 [4] plot(bn::BayesNet{CPD})
   @ BayesNets ~/.julia/packages/BayesNets/yBu0u/src/io.jl:35
 [5] top-level scope
   @ REPL[17]:1

Can anyone help me with this? I don't if this's a bug or I did sth. wrong (e.g., missing package installation). Plot method is a really nice feature to have insights to Bayesian Networks' structure and it's helpful during the implementation. Really appreciated!

mossr commented 2 years ago

This is an (sneaky) issue between TikzGraphs use of Graphs.jl (replacement for LightGraphs.jl) and BayesNets.jl still using LightGraphs.jl.

This is already fixed on the master branch, so I'll release a new BayesNets.jl version today so you can officially get the fix.

mossr commented 2 years ago

All set. @SEICS update your local BayesNets package and this should be fixed:

] up BayesNets