egraphs-good / egraph-serialize

egraph <-> json
MIT License
8 stars 3 forks source link

Add support for exporting with Graphviz #4

Closed saulshanabrook closed 11 months ago

saulshanabrook commented 11 months ago

This PR adds support for exporting the graph to SVG using Graphviz.

Check out the ./tests-viz/README.md for each of the examples rendered. I choose to keep these files in VCS so that we can use diffs to see changes to the viz algorithm easily and also to give new users an overview of the examples.

This logic is pulled from https://github.com/egraphs-good/egglog/pull/147 which is ported to the new format.

There is some discussion in that PR about ways to deal with primitives, whether they should be split into their own nodes or collapsed into calls, for ease of readability (https://github.com/egraphs-good/egglog/pull/147#issuecomment-1645999383). This PR does not implement any of those transformations. I believe they can be implemented as follow-ups. I think they should all be able to be implemented as EGraph -> EGraph functions, which will allow us to keep the visualization logic unchanged.

EDIT: I have also added a function to inline primitives into their parent nodes and show both options in the README.

mwillsey commented 11 months ago

This looks great! I prefer the inlined version; the math-powers example in the demo images really did it for me.