AlgebraicJulia / Catlab.jl

A framework for applied category theory in the Julia language
https://www.algebraicjulia.org
MIT License
614 stars 58 forks source link

Graphviz graphics in julia-vscode cannot spawn `dot` #737

Closed anandijain closed 1 year ago

anandijain commented 1 year ago

If I don't start the process via the extensions it just shows the text instead of erroring, which is okay, but would prefer to see the graph. How can I fix this?

julia> draw(path_graph(Graph, 5))
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 => "1")), Catlab.Graphics.Graphviz.Node("n2", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => "2")), Catlab.Graphics.Graphviz.Node("n3", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => "3")), Catlab.Graphics.Graphviz.Node("n4", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => "4")), Catlab.Graphics.Graphviz.Node("n5", OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => "5")), 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}}(:label => "1")), 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}}(:label => "2")), Catlab.Graphics.Graphviz.Edge(Catlab.Graphics.Graphviz.NodeID[Catlab.Graphics.Graphviz.NodeID("n3", "", ""), Catlab.Graphics.Graphviz.NodeID("n4", "", "")], OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => "3")), Catlab.Graphics.Graphviz.Edge(Catlab.Graphics.Graphviz.NodeID[Catlab.Graphics.Graphviz.NodeID("n4", "", ""), Catlab.Graphics.Graphviz.NodeID("n5", "", "")], OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:label => "4"))], 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 => "circle", :width => "0.05"), OrderedCollections.OrderedDict{Symbol, Union{String, Catlab.Graphics.Graphviz.Html}}(:arrowsize => "0.5"))

mwe:

using Catlab, Catlab.Theories
using Catlab.CategoricalAlgebra
using Catlab.Graphs
using Catlab.Graphics
using Colors

draw(g) = to_graphviz(g, node_labels=true, edge_labels=true)
draw(path_graph(Graph, 5))

trace:

ERROR: IOError: could not spawn `dot -Tsvg`: no such file or directory (ENOENT)
Stacktrace:
  [1] _spawn_primitive(file::String, cmd::Cmd, stdio::Vector{Union{RawFD, IO}})
    @ Base ./process.jl:128
  [2] #761
    @ ./process.jl:139 [inlined]
  [3] setup_stdios(f::Base.var"#761#762"{Cmd}, stdios::Vector{Union{RawFD, IO}})
    @ Base ./process.jl:223
  [4] _spawn
    @ ./process.jl:138 [inlined]
  [5] open(cmds::Cmd, stdio::IOBuffer; write::Bool, read::Bool)
    @ Base ./process.jl:397
  [6] open(f::Catlab.Graphics.Graphviz.var"#34#35"{Catlab.Graphics.Graphviz.Graph}, cmds::Cmd, args::IOBuffer; kwargs::Base.Pairs{Symbol, Bool, Tuple{Symbol}, NamedTuple{(:write,), Tuple{Bool}}})
    @ Base ./process.jl:415
  [7] run_graphviz(io::IOBuffer, graph::Catlab.Graphics.Graphviz.Graph; prog::Nothing, format::String)
    @ Catlab.Graphics.Graphviz ~/.julia/packages/Catlab/87RDU/src/graphics/Graphviz.jl:172
  [8] show
    @ ~/.julia/packages/Catlab/87RDU/src/graphics/Graphviz.jl:183 [inlined]
  [9] __binrepr(m::MIME{Symbol("image/svg+xml")}, x::Catlab.Graphics.Graphviz.Graph, context::Nothing)
    @ Base.Multimedia ./multimedia.jl:171
 [10] display(d::VSCodeServer.InlineDisplay, m::MIME{Symbol("image/svg+xml")}, x::Catlab.Graphics.Graphviz.Graph)
    @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.41.1/scripts/packages/VSCodeServer/src/display.jl:0
 [11] display(d::VSCodeServer.InlineDisplay, mime::String, x::Any)
    @ Base.Multimedia ./multimedia.jl:228
 [12] display(d::VSCodeServer.InlineDisplay, x::Catlab.Graphics.Graphviz.Graph)
    @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.41.1/scripts/packages/VSCodeServer/src/display.jl:165
 [13] display(x::Any)
    @ Base.Multimedia ./multimedia.jl:340
 [14] #invokelatest#2
    @ ./essentials.jl:823 [inlined]
 [15] invokelatest
    @ ./essentials.jl:820 [inlined]
 [16] (::VSCodeServer.var"#66#70"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})()
    @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.41.1/scripts/packages/VSCodeServer/src/eval.jl:199
 [17] withpath(f::VSCodeServer.var"#66#70"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams}, path::String)
    @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.41.1/scripts/packages/VSCodeServer/src/repl.jl:249
 [18] (::VSCodeServer.var"#65#69"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})()
    @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.41.1/scripts/packages/VSCodeServer/src/eval.jl:155
 [19] hideprompt(f::VSCodeServer.var"#65#69"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})
    @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.41.1/scripts/packages/VSCodeServer/src/repl.jl:38
 [20] (::VSCodeServer.var"#64#68"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})()
    @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.41.1/scripts/packages/VSCodeServer/src/eval.jl:126
 [21] with_logstate(f::Function, logstate::Any)
    @ Base.CoreLogging ./logging.jl:514
 [22] with_logger
    @ ./logging.jl:626 [inlined]
 [23] (::VSCodeServer.var"#63#67"{VSCodeServer.ReplRunCodeRequestParams})()
    @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.41.1/scripts/packages/VSCodeServer/src/eval.jl:225
 [24] #invokelatest#2
    @ ./essentials.jl:823 [inlined]
 [25] invokelatest(::Any)
    @ Base ./essentials.jl:820
 [26] macro expansion
    @ ~/.vscode/extensions/julialang.language-julia-1.41.1/scripts/packages/VSCodeServer/src/eval.jl:34 [inlined]
 [27] (::VSCodeServer.var"#61#62")()
    @ VSCodeServer ./task.jl:514

versioninfo():

  Julia Version 1.10.0-DEV.460
Commit 94c4fb5e822 (2023-01-31 04:48 UTC)
Platform Info:
  OS: macOS (arm64-apple-darwin21.5.0)
  CPU: 8 × Apple M1
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-14.0.6 (ORCJIT, apple-m1)
  Threads: 8 on 4 virtual cores
Environment:
  JULIA_EDITOR = code
  JULIA_NUM_THREADS = 8
Manifest ```julia Project MyCatlab v0.1.0 Status `~/.julia/dev/MyCatlab/Manifest.toml` [c3fe647b] AbstractAlgebra v0.27.8 [1520ce14] AbstractTrees v0.4.4 [79e6a3ab] Adapt v3.5.0 [4f99eebe] AlgebraicPetri v0.8.4 [dce04be8] ArgCheck v2.3.0 [ec485272] ArnoldiMethod v0.2.0 [4fba245c] ArrayInterface v6.0.25 [30b0a656] ArrayInterfaceCore v0.1.29 [015c0d05] ArrayInterfaceOffsetArrays v0.1.7 [b0d46f97] ArrayInterfaceStaticArrays v0.1.5 [dd5226c6] ArrayInterfaceStaticArraysCore v0.1.3 [15f4f7f2] AutoHashEquals v0.2.0 [198e06fe] BangBang v0.3.37 [9718e550] Baselet v0.1.1 [e2ed5e7c] Bijections v0.1.4 [62783981] BitTwiddlingConvenienceFunctions v0.1.5 [2a0fbf3d] CPUSummary v0.2.2 [00ebfdb7] CSTParser v3.3.6 [49dc2e85] Calculus v0.5.1 [134e5e36] Catlab v0.14.14 [d360d2e6] ChainRulesCore v1.15.7 [fb6a15b2] CloseOpenIntervals v0.1.11 [3da002f7] ColorTypes v0.11.4 [5ae59095] Colors v0.12.10 [861a8166] Combinatorics v1.0.2 [a80b9123] CommonMark v0.8.10 [38540f10] CommonSolve v0.2.3 [bbf7d656] CommonSubexpressions v0.3.0 [0fb5dd42] CompTime v0.1.2 [34da2185] Compat v4.5.0 [a81c6b42] Compose v0.9.4 [b152e2b5] CompositeTypes v0.1.3 [a33af91c] CompositionsBase v0.1.1 [187b0558] ConstructionBase v1.4.1 [adafc99b] CpuId v0.3.1 [a8cc5b0e] Crayons v4.1.1 [9a962f9c] DataAPI v1.14.0 [864edb3b] DataStructures v0.18.13 [e2d170a0] DataValueInterfaces v1.0.0 [244e2a9f] DefineSingletons v0.1.2 [b429d917] DensityInterface v0.4.0 [2b5f629d] DiffEqBase v6.114.2 [459566f4] DiffEqCallbacks v2.24.3 [163ba53b] DiffResults v1.1.0 [b552c78f] DiffRules v1.12.2 [b4f34e82] Distances v0.10.7 [31c24e10] Distributions v0.25.80 [ffbed154] DocStringExtensions v0.9.3 ⌅ [5b8099bc] DomainSets v0.5.15 [fa6b7ba4] DualNumbers v0.6.8 [7c1d4256] DynamicPolynomials v0.4.5 [4e289a0a] EnumX v1.0.4 [e2ba6199] ExprTools v0.1.8 [7034ab61] FastBroadcast v0.2.4 [1a297f60] FillArrays v0.13.7 [6a86dc24] FiniteDiff v2.17.0 [53c48c17] FixedPointNumbers v0.8.4 [59287772] Formatting v0.4.2 [f6369f11] ForwardDiff v0.10.34 [069b7b12] FunctionWrappers v1.1.3 [77dc65aa] FunctionWrappersWrappers v0.1.1 [46192b85] GPUArraysCore v0.1.3 [6b9d7cbe] GeneralizedGenerated v0.3.3 [c27321d9] Glob v1.3.0 [86223c79] Graphs v1.7.4 [0b43b601] Groebner v0.2.11 [d5909c97] GroupsCore v0.4.0 [34004b35] HypergeometricFunctions v0.3.11 [615f187c] IfElse v0.1.1 [d25df0c9] Inflate v0.1.3 [22cec73e] InitialValues v0.3.1 [18e54dd8] IntegerMathUtils v0.1.0 ⌅ [8197267c] IntervalSets v0.7.3 [3587e190] InverseFunctions v0.1.8 [92d709cd] IrrationalConstants v0.1.1 [c8e1da08] IterTools v1.4.0 [82899510] IteratorInterfaceExtensions v1.0.0 [692b3bcd] JLLWrappers v1.4.1 [682c06a0] JSON v0.21.3 [98e50ef6] JuliaFormatter v1.0.20 [b14d175d] JuliaVariables v0.2.4 [ccbc3e58] JumpProcesses v9.3.1 [b964fa9f] LaTeXStrings v1.3.0 [2ee39098] LabelledArrays v1.13.0 [984bce1d] LambertW v0.4.6 [23fbe1c1] Latexify v0.15.18 [10f19ff3] LayoutPointers v0.1.13 [9c8b4983] LightXML v0.9.0 [d3d80556] LineSearches v7.2.0 [2ab3a3ac] LogExpFunctions v0.3.20 [d8e11817] MLStyle v0.4.16 [1914dd2f] MacroTools v0.5.10 [d125e4d3] ManualMemory v0.1.8 [442fdcdd] Measures v0.3.2 ⌅ [e9d8d322] Metatheory v1.3.5 [128add7d] MicroCollections v0.1.3 [e1d29d7a] Missings v1.1.0 [961ee093] ModelingToolkit v8.44.0 [46d2c3a1] MuladdMacro v0.2.4 [102ac46a] MultivariatePolynomials v0.4.6 [d8a4904e] MutableArithmetics v1.1.0 [d41bc354] NLSolversBase v7.8.3 [2774e3e8] NLsolve v4.5.1 [77ba4419] NaNMath v1.0.1 [71a1bf82] NameResolution v0.1.5 [6fe1bfb0] OffsetArrays v1.12.9 [bac558e1] OrderedCollections v1.4.1 [90014a1f] PDMats v0.11.16 [d96e819e] Parameters v0.12.3 [69de0a69] Parsers v2.5.3 [e409e4f3] PoissonRandom v0.4.3 [f517fe37] Polyester v0.7.2 [1d0040c9] PolyesterWeave v0.2.1 [d236fae5] PreallocationTools v0.4.8 [21216c6a] Preferences v1.3.0 [8162dcfd] PrettyPrint v0.2.0 [08abe8d2] PrettyTables v2.2.2 [27ebfcd6] Primes v0.5.3 [1fd47b50] QuadGK v2.7.0 [fb686558] RandomExtensions v0.4.3 [e6cf234a] RandomNumbers v1.5.3 [3cdcf5f2] RecipesBase v1.3.3 [731186ca] RecursiveArrayTools v2.36.0 [189a3867] Reexport v1.2.2 [42d2dcc6] Referenceables v0.1.2 [ae029012] Requires v1.3.0 [79098fc4] Rmath v0.7.1 [7e49a35a] RuntimeGeneratedFunctions v0.5.5 [94e857df] SIMDTypes v0.1.0 [0bca4576] SciMLBase v1.81.1 [efcf1570] Setfield v1.1.1 [727e6d20] SimpleNonlinearSolve v0.1.9 [699a6c99] SimpleTraits v0.9.4 [66db9d55] SnoopPrecompile v1.0.3 [a2af1166] SortingAlgorithms v1.1.0 [276daf66] SpecialFunctions v2.1.7 [171d559e] SplittablesBase v0.1.15 [aedffcd0] Static v0.8.3 [90137ffa] StaticArrays v1.5.12 [1e83bf80] StaticArraysCore v1.4.0 [82ae8749] StatsAPI v1.5.0 [2913bbd2] StatsBase v0.33.21 [4c63d2b9] StatsFuns v1.1.1 [7792a7ef] StrideArraysCore v0.4.6 [892a3eda] StringManipulation v0.3.0 [6ec83bb0] StructEquality v2.1.0 [2efcf032] SymbolicIndexingInterface v0.2.1 ⌅ [d1185830] SymbolicUtils v0.19.11 ⌅ [0c5d862f] Symbolics v4.14.0 [3783bdb8] TableTraits v1.0.1 [bd369af6] Tables v1.10.0 ⌅ [8ea1fca8] TermInterface v0.2.3 [8290d209] ThreadingUtilities v0.5.1 [ac1d9e8a] ThreadsX v0.1.11 [a759f4b9] TimerOutputs v0.5.22 [0796e94c] Tokenize v0.5.25 [28d57a85] Transducers v0.4.75 [a2a6695c] TreeViews v0.3.0 [410a4b4d] Tricks v0.1.6 [5c2747f8] URIs v1.4.1 [3a884ed6] UnPack v1.0.2 [1986cc42] Unitful v1.12.2 [700de1a5] ZygoteRules v0.2.2 [94ce4f54] Libiconv_jll v1.16.1+2 [efe28fd5] OpenSpecFun_jll v0.5.5+0 [f50d1b31] Rmath_jll v0.4.0+0 [02c8fc9c] XML2_jll v2.10.3+0 [0dad84c5] ArgTools v1.1.1 [56f22d72] Artifacts [2a0f44e3] Base64 [ade2ca70] Dates [8ba89e20] Distributed [f43a241f] Downloads v1.6.0 [7b1f6079] FileWatching [9fa8497b] Future [b77e0a4c] InteractiveUtils [b27032c2] LibCURL v0.6.3 [76f85450] LibGit2 [8f399da3] Libdl [37e2e46d] LinearAlgebra [56ddb016] Logging [d6f4376e] Markdown [a63ad114] Mmap [ca575930] NetworkOptions v1.2.0 [44cfe95a] Pkg v1.10.0 [de0858da] Printf [3fa0cd96] REPL [9a3f8284] Random [ea8e919c] SHA v0.7.0 [9e88b42a] Serialization [1a1011a3] SharedArrays [6462fe0b] Sockets [2f01184e] SparseArrays [10745b16] Statistics v1.9.0 [4607b0f0] SuiteSparse [fa267f1f] TOML v1.0.3 [a4e569a6] Tar v1.10.0 [8dfed614] Test [cf7118a7] UUIDs [4ec0a83e] Unicode [e66e0078] CompilerSupportLibraries_jll v1.0.2+0 [deac9b47] LibCURL_jll v7.84.0+0 [29816b5a] LibSSH2_jll v1.10.2+0 [c8ffd9c3] MbedTLS_jll v2.28.0+0 [14a3606d] MozillaCACerts_jll v2022.10.11 [4536629a] OpenBLAS_jll v0.3.21+0 [05823500] OpenLibm_jll v0.8.1+0 [bea87d4a] SuiteSparse_jll v5.10.1+6 [83775a58] Zlib_jll v1.2.13+0 [8e850b90] libblastrampoline_jll v5.4.0+0 [8e850ede] nghttp2_jll v1.48.0+0 [3f19e933] p7zip_jll v17.4.0+0 Info Packages marked with ⌅ have new versions available but compatibility constraints restrict them from upgrading. To see why use `status --outdated -m` ```
anandijain commented 1 year ago

Okay I found https://github.com/AlgebraicJulia/Catlab.jl/blob/master/src/graphics/Graphviz.jl#L152-L161 and added and loaded Graphviz_jll

which gave

julia> draw(g)
dyld[7292]: Library not loaded: @rpath/libexpat.1.dylib
  Referenced from: <0A7C10B0-F8AF-321C-BC1A-651591ED4464> /Users/anand/.julia/artifacts/dbc1b7f42ddb07be07d55ad976317ad027618c63/bin/dot
  Reason: tried: '/Users/anand/.julia/artifacts/dbc1b7f42ddb07be07d55ad976317ad027618c63/bin/../lib/libexpat.1.dylib' (no such file), '/Users/anand/.julia/artifacts/dbc1b7f42ddb07be07d55ad976317ad027618c63/bin/../lib/libexpat.1.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS@rpath/libexpat.1.dylib' (no such file), '/Users/anand/.julia/artifacts/dbc1b7f42ddb07be07d55ad976317ad027618c63/bin/../lib/libexpat.1.dylib' (no such file), '/Users/anand/.julia/artifacts/dbc1b7f42ddb07be07d55ad976317ad027618c63/bin/../lib/libexpat.1.dylib' (no such file)
Error showing value of type Catlab.Graphics.Graphviz.Graph:
ERROR: failed process: Process(`/Users/anand/.julia/artifacts/dbc1b7f42ddb07be07d55ad976317ad027618c63/bin/dot -Tsvg`, ProcessSignaled(6)) [0]

this seems like a Graphviz issue

and I'm pretty sure the original issue is https://github.com/julia-vscode/julia-vscode/issues/3127, since the "Julia-REPL" doesn't have access to my path.

epatters commented 1 year ago

The recommended approach is to install Graphviz and put its programs on your system path. This will include the program dot. I am not sure about VS Code specifically since I don't use it.

You can also try to use Graphviz_jll by installing the JLL with the Julia package manager and then importing it. However, the JLL is known to have various problems. If it's not working for you, you should install the official Graphviz binaries on your system.

anandijain commented 1 year ago

It would probably be good to document this. I think vscode is the most common julia IDE. Since Julia-REPL won't have dot on my path, despite it being on my system path, a hacky fix is to just modify ENV ENV["PATH"] = "/usr/bin:/bin:/usr/sbin:/sbin:/opt/homebrew/bin"

Now everything works pretty much as expected. Thanks!