I have just released the first version of the TreeView package, which makes it easy to visualize the syntax tree of a Julia Expression as a graph.
It is as simple as typing
using TreeView
@tree x^2 + y^2
in an IJulia notebook.
You can see a couple of examples here.
This uses the nice TikzGraphs package, so requires LaTeX to be installed on your system, as well as pdf2svg. (See the README of TikzGraphs.)
Apart from being useful for visualization purposes, it is also intended as a pedagogical example of how to walk a syntax tree and do basic metaprogramming.
Suggestions and Pull Requests are, of course, welcome.
Thanks @dpsanders, it can be very useful for people playing with Deep Learning or Mathematical Optimization. It would be great if all Julia packages that manipulate Julia expressions somehow used the same visualization API.
@lobingera I am not following the development of the Deep Learning frameworks in Julia closely, but I am sure they have a representation of the computation in graph form that can be visualized somewhere.
I forgot to say that apart from being useful in itself, it is also intended as a pedagogical example of how to walk a syntax tree and do basic metaprogramming.
It’s indeed a great pedagogical tool. I also needed to install pdf2svg (which wasn’t part of TeXLive on OSX). In the example with functions f and g, is it possible to go recursively into the functions?
I’m not quite sure what you mean by “recursively” here.
The package will just display a literal tree of the expression itself; no evaluation is carried out.
Can you give an example of what you had in mind?
That seems quite difficult to do in general. In the case you show it may not be hard, but what if you have eg f(1,y)? This is getting into parser territory. Maybe use Sugar.jl?
How hard might it be to get a style more like the tikz trees shown? (ie black and wite without boxes etc) To my eye they look much nicer, but I would rather use Plots.jl
lol. Good point … looking at the code for the recipe, I realize I don’t really understand how it works … so installing tikz it is … Thanks for the cool package.