# 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)


gives:

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

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

Thierry

2 Likes

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.

T.

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 )

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.

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
TreeView.DirectedAcyclicGraph

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.

Hello,

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

g = DiGraph(8)


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")
)


And

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

So I obtained:

Questions:

• 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?