Skip to content

Printing and Visualization of the Backend AST

Printing

The __str__ and __repr__ methods of the backend AST nodes (pystencils.backend.ast) are so far implemented inconsistently and incompletely. They should be revised and reimplemented to the following goals:

  • __str__ should produce a brief, concise and informative string representation of a syntax tree, with as little clutter as possible.
    • A step toward this was done with the IRAstPrinter in !424 (merged), but that output can hardly be called 'brief and concise' for large subtrees.
  • __repr__ should produce a verbose representation that includes all details about the AST node (see the Python docs). It won't be possible to produce a string representation that can be passed to eval to recreate the AST in all cases (PsSymbolExpr in particular is problematic), but we should get as close to that as possible.

Visualization

  • For AST visualization, a dot printer for the backend AST should be implemented. The dot representation should be exportable to file. With !430 (merged) a framework for interactive inspection in Jupyter notebooks is being introduced. This should also include visualization using GraphViz once that is available.
Edited by Frederik Hennig