Skip to content
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

Pretty-printing for GEM #3833

Open
miklos1 opened this issue Dec 12, 2016 · 9 comments
Open

Pretty-printing for GEM #3833

miklos1 opened this issue Dec 12, 2016 · 9 comments

Comments

@miklos1
Copy link
Member

miklos1 commented Dec 12, 2016

A DAG-aware, nice pretty-printing for GEM would be handy when debugging.

@miklos1
Copy link
Member Author

miklos1 commented Dec 12, 2016

The branch point-evaluation contains an old sketch.

@tj-sun
Copy link
Contributor

tj-sun commented Dec 22, 2016

I vaguely remember have done some work on pretty printing in sympy before, might be able to work on this.
Probably can start by overloading repr_latex() for jupyter notebook?

@miklos1
Copy link
Member Author

miklos1 commented Jan 6, 2017

LaTeX or similar fancy formatting is not what I had in mind for this issue, but you can create another issue for that.

While the current __repr__ is okay for simple GEM expressions, for complicated ones it is hardly helpful. I was thinking of something like UFL's __repr__ vs __str__, and also of making this printing DAG-aware, i.e. shared subexpressions should not blow up during printing.

@tj-sun
Copy link
Contributor

tj-sun commented Jan 6, 2017

I see. So we want to implement str in a DAG-aware fashion, which is a nice idea.
I guess later days we can also implement repr_latex, in a DAG-aware fashion as well, but yeah that is a separate issue.
Can work on this after finishing COFFEE migration.

@miklos1 miklos1 self-assigned this Jan 12, 2017
@miklos1 miklos1 removed their assignment Jul 28, 2017
@sv2518
Copy link
Contributor

sv2518 commented Mar 25, 2020

I think @narciuch has done something on this using Graphviz. Maybe it's possible to get that to spew a nice string, but google did not give me a straight answer on how.

@wence-
Copy link
Contributor

wence- commented Mar 25, 2020

There is also gem.pprint which is DAG aware but only textual

@sv2518
Copy link
Contributor

sv2518 commented Mar 25, 2020

Yes true, but I don't think it's nice to read. If pprint is what Miklos was after maybe we can close this?

@miklos1
Copy link
Member Author

miklos1 commented Mar 25, 2020

I started something on DAG-aware pretty printing to ease debugging, which then I abandoned working on as I did not need it that much any more for debugging. This half-baked version was merged when I had left, that is now gem.pprint. Feel free to do something with graphviz if that helps you.

@narciuch
Copy link
Contributor

I've implemented a graph pretty printer on branch tsslac_optimisation, under firedrake/slate/view_gem_dag.py

It can generate DAG aware graphs, simple parent to child trees and DAG unaware full graphs. I've only used it on simpler trees for debugging, so not sure how well it will scale to large trees or if these graph types are useful to others, but its quite an easy tool to work with so shouldn't be too hard to adapt.

The graph can be printed to different formats as provided by Graphviz. I've found the png format quite reader-friendly, but unfortunately haven't seen any that give reader-friendly textual-based output.

@connorjward connorjward transferred this issue from firedrakeproject/tsfc Oct 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants