Graphviz running but not printing

Hey,

I’m trying to run the code below in VS code. I have graphviz installed and have the Julia graphviz pkg installed as well. The code runs without errors besides the graphviz part which gives the below error.

using Catlab

using Catlab.CategoricalAlgebra

using Catlab.Theories

using Catlab.Graphs

using Catlab.Graphics

@present SchGraph(FreeSchema) begin

V::Ob

E::Ob

src::Hom(E,V)

tgt::Hom(E,V)

end

g = Graph()

add_parts!(g, :V, 3)

add_parts!(g, :E, 4, src=[1,2,2,3], tgt=[2,3,3,3])

g

to_graphviz(g)

LoadError: MethodError: no method matching show(::IOStream, ::MIME{Symbol("text/vnd.graphviz")}, ::Catlab.Graphics.Graphviz.Graph)
The function `show` exists, but no method is defined for this combination of argument types.

Please make sure you are on the latest released version of Catlab and post the versions of Julia and your Pkg.status(). This code should work, so there is probably a version issue or package loading issue.

So it is running now for some reason without any error. However, my question is what is

to_graphviz(g)

supposed to do? How do I get it to actually draw the graph?

The function to_graphviz constructs a Graphviz representation of the graph. VS Code then sees that object and calls show on it with the SVG mime type to indicates that it wants graphical output. Then the show method interprets that mime type to invoke graphviz executables like dot via the shell to do the drawing.

If you are getting terminal output that looks like serialized version of your graph instead of a picture of the graph in the plots pane, then there is likely a problem where VS Code is unable to shell out to graphviz.

I think that the mime type ::MIME{Symbol("text/vnd.graphviz")} is the fallback for what happens when VS Code wants to get back a textual representation of Graphviz code, rather than svg, which should trigger running graphviz via the command line.

You can call view_graphviz which will invoke the graphviz tools on a file and then invoke your system image viewer. This is how people can view the graph from environments like the terminal or a bash script.

The best approach is to uninstall the graphvizjll package and just rely on the system commands. That is how I use graphviz on my platform and on my university cluster. You do need a reasonably up to date version of graphviz (anything newer than 2022 should be fine).

That makes sense. Sorry, I’m pretty new to Julia and Graphviz as well. The output I’m getting if I run display on the to_graphviz(g) is

Catlab.Graphics.Graphviz.Graph("G", true, "dot", 
Catlab.Graphics.Graphviz.Statement[Catlab.Graphics.Graphviz.Node("n1", OrderedCollections.OrderedDict{Symbol, Union{String, 
Catlab.Graphics.Graphviz.Html}}(:label => "")), 
Catlab.Graphics.Graphviz.Node("n2", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => "")), 
Catlab.Graphics.Graphviz.Node("n3", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => "")), 
Catlab.Graphics.Graphviz.Edge(Catlab.Graphics.Graphviz.NodeID[Catlab.Graphics.Graphviz.NodeID("n1", "", ""), Catlab.Graphics.Graphviz.NodeID("n2", "", "")], OrderedCollections.OrderedDict{Symbol, Union{String, 
Catlab.Graphics.Graphviz.Html}}()), 
Catlab.Graphics.Graphviz.Edge(Catlab.Graphics.Graphviz.NodeID[Catlab.Graphi
cs.Graphviz.NodeID("n2", "", ""), Catlab.Graphics.Graphviz.NodeID("n3", "", "")], OrderedCollections.OrderedDict{Symbol, Union{String, 
Catlab.Graphics.Graphviz.Html}}()), 
Catlab.Graphics.Graphviz.Edge(Catlab.Graphics.Graphviz.NodeID[Catlab.Graphics.Graphviz.NodeID("n2", "", ""), Catlab.Graphics.Graphviz.NodeID("n3", "", "")],
 OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}()), 
Catlab.Graphics.Graphviz.Edge(Catlab.Graphics.Graphviz.NodeID[Catlab.Graphics.Graphviz.NodeID("n3", "", ""), Catlab.Graphics.Graphviz.NodeID("n3", "", "")], OrderedCollections.OrderedDict{Symbol, Union{String, 
Catlab.Graphics.Graphviz.Html}}())], OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:rankdir => "LR"), 
OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:height => "0.05", :margin => "0", :shape => 
"point", :width => "0.05"), OrderedCollections.OrderedDict{Symbol, Union{String,
 Catlab.Graphics.Graphviz.Html}}(:arrowsize => "0.5"))

Which seems like the appropriate serialization. So then, where and how would I run this to get some visualization?