TreeView package release for visualizing syntax trees


#1

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.


#2

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.


#3

I believe there’s already a plot recipe for handling something like this. I wonder how it’s different. This does look nice though.


#4

Which other APIs do you in this area?


#5

There is indeed a recipe, I actually suggested the recipe to be part of Documenter.jl to have type DAGs a la Doxygen: https://github.com/JuliaDocs/Documenter.jl/issues/364


#6

@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.


#7

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.


#8

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?


#9

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?


#10

What I mean is descend recursively into functions. f itself has an expression graph associated to it. For example instead of

Can we get


#11

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?


#12

Note to myself: Ask concrete and understandable questions.

What i actually wanted to ask was: Have you seen other visualisation APIs in use here? Going to Tikz and LaTeX in the background sounds too heavy for drawing “simple” trees. I always wondered if Compose’s introspect could be reused here:
http://giovineitalia.github.io/Compose.jl/latest/#Trees-can-be-visualized-with-introspect-1


#13

Here’s an example: https://github.com/JuliaPlots/PlotRecipes.jl#julia-code----ast


#14

That is precisely what you are looking for @dpo


#15

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


#16

It just requires rewriting the plot recipe.


#17

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.


#18

As far as I can tell, the Plots recipe doesn’t do it either. Anyways, it was just curiosity.


#19

You could try passing arguments such as method = :tree, markercolor = :white, markerstrokewidth = 0 to the plot recipe?