Wengert list -- possible graphs?

Hello everybody,

I wonder if there is a Julia package that, from a given equation, produces the calculation graph (Wenger’s list). As if:

f(x1,x2) = x1*x2 - sin(x2)

A bit like Catalyst.jl allows the use of Graphiz…

See also the graph in this video (~6:38) cited in the present forum

Thanks for your advices,

GitHub - JuliaTeX/TreeView.jl: Draw Julia syntax trees as a graph does something similar.

Also GitHub - JuliaPlots/GraphRecipes.jl: Graph-related recipes to be used with Plots.jl.


Many thanks David!

I am looking at GraphRecipes but TreeView is already helpfull (I’ve just tried it without further investigation).
Is there anything more aesthetically pleasing for didactic forms.


GraphRecipes.jl is more aesthetically pleasing I guess.

Or else you can modify TreeView, which uses TikzGraphs, according to your taste (and send a PR :wink: )

When installing GraphRecipes, I see that the package has links to ChainRules + ChainRulesCore, Zygote and… Flux. This is great.
And probably the solution I am looking for. I am testing this!

OK… If I understand correctly, GraphRecipes cannot directly process a raw Wengert list like:

y1 = x ^ 2
y2 = 3 * y1
y3 = 2x
y4 = y3 + 1
y5 = y2 + y4

associated with:

y = :(3x^2 + (2x + 1))
w_y = Wengert(y)

It is necessary to provide it with the elements “by hand”. Is it right?

However, I find that TreeView (despite its apparent simplicity) renders the relationship with the parents very well, which allows a good link with automatic reverse differentiation for “simple” cases.
Exple with @dag ou @dag_cse

Many thanks for your rapid help. :grinning:

1 Like

One last (?) questions: once a TreeView graph is produced, how to save it?

Then I saw how it is possible to transform it into .svg for example. All the packages are installed (TikzGraphs, LightGraphs, TikzPictures, `pdf2svg). Of course LaTeX/Lyx is installed…

Good question. However you’re supposed to save Tikz pictures with those other packages I guess.

There is something that I don’t understand.
In the REPL, I do:

julia> @dag :(x1*x2 - sin(x2))

Juno opens a Plots panel and displays the graph

The type of graph is

I wonder how to save this graph. Thanks in advance.

What do you mean by save? As in save a pdf to a file?

What I was suggesting is that since TreeView uses TikzGraphs.jl to draw the graph, you need to look at their docs to work out how to do that.


Finally I used these lines (inspired by this notebook):

g = DiGraph(8)
add_edge!(g, 1,2)
add_edge!(g, 2,3)
add_edge!(g, 3,4)
add_edge!(g, 4,5)
add_edge!(g, 6,7)
add_edge!(g, 7,8)
add_edge!(g, 8,4)
add_edge!(g, 7,3)

Followed by:

t = TikzGraphs.plot(g, 
     [" ", L"v_1", L"v_3", L"v_5", " ", " ", L"v_2", L"v_4"], 
     node_style="draw, rounded corners, fill=blue!50", 
     edge_labels=Dict((1,2)=>L"x_1", (3,4)=>L"x_1x_2", (8,4)=>L"\sin(x_2)", 
                (4,5)=>L"x_1x_2 - \sin(x_2)", (6,7)=>L"x_2")


TikzPictures.save(SVG("graph"), t)

So I obtained:


  • Do you have any idea how to move the x1x2 term to the left of the arrow connecting v3 to v5?

  • How to replace arrow by simple lines?

Thanks in advance,

1 Like