-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Graph evaluator caching and expression visualiser #98
Closed
Closed
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
1b542bc
testing out n-arity implementation with SizedVector
MilesCranmer 6b90350
Merge branch 'master' into n-arity
MilesCranmer ab7c65c
wip
MilesCranmer 3ed6b41
fix: various aspects of degree interface
MilesCranmer b5285f7
fix: segfault in NodeIndex
MilesCranmer 8707d24
refactor: no more need for `memoize_on`
MilesCranmer 2a0bd05
fix: various aspects of degree interface
MilesCranmer 60579fc
Add topological sort
robdancer f5925bd
Merge remote-tracking branch 'upstream/n-arity' into faster-graph-eval
robdancer 516a130
wip
robdancer a83bbe3
Fix toposort vector bug
robdancer 8f146cd
wip new evaluator
robdancer 2cb14b3
working eval_tree_array_graph, make loopvectorization a full dependency
robdancer 7330be7
Add graph visualizer
robdancer 789ae57
Add topological sort implementation for trees
robdancer d219f04
imports fix
robdancer 5148293
wip graph differentiation
robdancer d09db4e
Change Plots, GraphRecipes, LoopVectorization to weak deps
robdancer 8e081ba
Merge remote-tracking branch 'upstream/master' into faster-graph-eval
robdancer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
module DynamicExpressionsVisualizeExt | ||
|
||
using Plots, GraphRecipes, DynamicExpressions | ||
using DynamicExpressions: GraphNode, Node, topological_sort, AbstractOperatorEnum, get_op_name | ||
|
||
function DynamicExpressions.visualize( | ||
graph::Union{GraphNode,Node}, # types accepted by topological_sort | ||
operators::AbstractOperatorEnum, | ||
show = true | ||
) | ||
@info "Generating graph visualization" | ||
|
||
order = reverse(topological_sort(graph)) | ||
|
||
# multigraph adjacency list | ||
g = map( | ||
node -> convert(Vector{Int64}, map( | ||
cindex -> findfirst(x -> x === node.children[cindex][], order), | ||
1:node.degree | ||
)), | ||
order | ||
) | ||
|
||
# node labels | ||
n = map(x -> | ||
if x.degree == 0 | ||
x.constant ? x.val : 'x' * string(x.feature) | ||
elseif x.degree == 1 | ||
join(get_op_name(operators.unaops[x.op])) | ||
elseif x.degree == 2 | ||
join(get_op_name(operators.binops[x.op])) | ||
else | ||
@warn "Can't label operator node with degree > 2" | ||
end, | ||
order | ||
) | ||
|
||
# edge labels (specifies parameter no.) | ||
e = Dict{Tuple{Int64, Int64, Int64}, String}() | ||
for (index, node) in enumerate(order) | ||
edge_count = Dict{Int64, Int64}() # count number of edges to each child node | ||
for cindex in 1:node.degree | ||
order_cindex = findfirst(x -> x === node.children[cindex][], order) | ||
get!( | ||
e, | ||
( | ||
index, # source | ||
order_cindex, # dest | ||
get!(edge_count, order_cindex, pop!(edge_count, order_cindex, 0)+1) # edge no. | ||
), | ||
string(cindex) | ||
) | ||
end | ||
end | ||
|
||
# node colours | ||
c = map(x -> x == 1 ? 2 : 1, eachindex(order)) | ||
|
||
return graphplot( | ||
g, | ||
names = n, | ||
edgelabel = e, | ||
nodecolor = c, | ||
show = show, | ||
nodeshape=:circle, | ||
edge_label_box = false, | ||
edgelabel_offset = 0.015, | ||
nodesize=0.15 | ||
) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to use https://github.com/JuliaPlots/Plots.jl/tree/master/RecipesBase so we don't need to directly depend on Plots.jl? If using RecipesBase.jl it can usually interface with other plotting packages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually is Plots.jl used here?