GraphRecipes.jl icon indicating copy to clipboard operation
GraphRecipes.jl copied to clipboard

call trace graphs?

Open mkborregaard opened this issue 5 years ago • 7 comments

@JackDevine does this repo want a recipe for call trace graphs? Based on https://gist.github.com/mkborregaard/81825c3d370bb4d8dbfe59c3b2ae4b33 but I don't really have the best interface yet. Probably a @userplot like tracegraph(modules, call, args...), allowing names to take value true. It would involve a dep on JuliaInterpreter. Which I think of as not problematic.

mkborregaard avatar Mar 11 '20 14:03 mkborregaard

That looks quite cool! here is my go at making a trace graph. I removed the module names to make the graph a little more manageable:

using GraphRecipes
using Plots

g, v = tracecall((Base,), sin, 3)
graphplot(g, nodeshape=:rect, names=getnames(v), nodesize=0.15, method=:buchheim, root=:left, size=(1000,1000))

sin_tree

I think that we should include this into src/misc.jl. Right now it seems that tracecall can only handle one argument, which wouldn't block merging, but it would be nice to have a variable number of args.

I also wonder about the API, we could have a function tracegraph, but looking at the call signature, I think that we could just use multiple dispatch to add the same functionality to graphplot

JackDevine avatar Mar 12 '20 08:03 JackDevine

I agree on the api. This should be a @tracegraph macro that takes a full expression (variable args) and returns a TraceGraph object, which GraphPlot should dispatch on. I think :circle works better than :rect by the way. I'll prep the PR. I also want to fix the dependency graph functionality in misc and add it to the docs.

mkborregaard avatar Mar 12 '20 10:03 mkborregaard

I've been having some issues with the code recently though - not sure what changed. Did you see my complaints here? : https://julialang.slack.com/archives/C6E4SU1D3/p1583931179239700

https://julialang.slack.com/archives/C6E4SU1D3/p1583937388240600?thread_ts=1583931179.239700&cid=C6E4SU1D3

mkborregaard avatar Mar 12 '20 10:03 mkborregaard

@mkborregaard sorry that I didn't notice your slack posts. I find slack a little inundating sometimes, so I tend not to check it. I should probably change my settings so that I get an email if someone tags me.

I do not understand your markershape/markersize problems, they do not occur for me. Also, the canonical names for those are nodehape/nodesize, marker* are just aliases in GraphRecipes.

The problem that I do notice is that graphplot doesn't perform well at all when the size is not square or close to square. That is probably some sort of scaling issue. I was able to get a semi-decent result with this:

using .TraceCalls2, GraphRecipes, Plots
a = rand(10);
d = scatter(a);
g, v = TraceCalls2.tracecall((Plots,), scatter, a)

graphplot(g, method=:buchheim, root=:left, names=getnames(v), size=(4000,4000),
          nodeshape=:rect, nodesize=0.15)

scatter_tree

It seems that these trace graphs really push our current tree methods to the breaking point. Which is good, because I will be able to use them to stress test those layout methods.

I also noticed that it is possible to pass :buchheim a layers_scalar, but it will do nothing. See here: https://github.com/JuliaPlots/GraphRecipes.jl/blob/34b1f7592ebe9ef6e17080fd7f6ab576a13aa95e/src/graph_layouts.jl#L227 Fixing that and the scaling issue will probably help a lot.

JackDevine avatar Mar 13 '20 09:03 JackDevine

Back when we set aspect_ratio to 1 - could we instead query the aspect ratio from the data limits and use that in the equation? That would make it more generic

mkborregaard avatar Mar 13 '20 12:03 mkborregaard

could we instead query the aspect ratio from the data limits and use that in the equation?

The node shape functionality that I created is rather basic, so setting aspect_ratio != 1 would make the nodes look a little wonky. It is not impossible to fix, but it is not trivial.

JackDevine avatar Mar 13 '20 21:03 JackDevine

yes because it's hard to discern the size of the plotted area from the total plot size I guess.

mkborregaard avatar Mar 13 '20 21:03 mkborregaard