From ad1549aa85fa4ac5301af002e4460b211943e8cc Mon Sep 17 00:00:00 2001
From: Andreas Kloeckner <inform@tiker.net>
Date: Mon, 29 May 2023 17:32:46 -0500
Subject: [PATCH] Drop asciidag visualization

---
 .pylintrc-local.yml              |   1 -
 examples/visualization.py        |   2 -
 pytato/__init__.py               |   5 +-
 pytato/visualization/__init__.py |   4 -
 pytato/visualization/ascii.py    | 124 -------------------------------
 requirements.txt                 |   1 -
 test/test_pytato.py              |  31 --------
 7 files changed, 2 insertions(+), 166 deletions(-)
 delete mode 100644 pytato/visualization/ascii.py

diff --git a/.pylintrc-local.yml b/.pylintrc-local.yml
index f5a171e..ae0f920 100644
--- a/.pylintrc-local.yml
+++ b/.pylintrc-local.yml
@@ -1,6 +1,5 @@
 - arg: ignored-modules
   val:
-  - asciidag
   - matplotlib
   - ipykernel
   - ply
diff --git a/examples/visualization.py b/examples/visualization.py
index 2b569a3..ac71e60 100755
--- a/examples/visualization.py
+++ b/examples/visualization.py
@@ -22,8 +22,6 @@ def main():
     stack = pt.stack([array, 2*array, array + 6])
     result = stack @ stack.T
 
-    pt.show_ascii_graph(result)
-
     dot_code = pt.get_dot_graph(result)
 
     with open(GRAPH_DOT, "w") as outf:
diff --git a/pytato/__init__.py b/pytato/__init__.py
index 0509a8c..572e4a7 100644
--- a/pytato/__init__.py
+++ b/pytato/__init__.py
@@ -89,7 +89,6 @@ from pytato.target import Target
 from pytato.target.loopy import LoopyPyOpenCLTarget
 from pytato.target.python.jax import generate_jax
 from pytato.visualization import (get_dot_graph, show_dot_graph,
-                                  get_ascii_graph, show_ascii_graph,
                                   get_dot_graph_from_partition,
                                   show_fancy_placeholder_data_flow,
                                   )
@@ -136,8 +135,8 @@ __all__ = (
 
         "Target", "LoopyPyOpenCLTarget",
 
-        "get_dot_graph", "show_dot_graph", "get_ascii_graph",
-        "show_ascii_graph", "get_dot_graph_from_partition",
+        "get_dot_graph", "show_dot_graph",
+        "get_dot_graph_from_partition",
         "show_fancy_placeholder_data_flow",
 
         "abs", "sin", "cos", "tan", "arcsin", "arccos", "arctan", "sinh", "cosh",
diff --git a/pytato/visualization/__init__.py b/pytato/visualization/__init__.py
index 6fed19f..e0138a7 100644
--- a/pytato/visualization/__init__.py
+++ b/pytato/visualization/__init__.py
@@ -2,19 +2,15 @@
 .. currentmodule:: pytato
 
 .. automodule:: pytato.visualization.dot
-.. automodule:: pytato.visualization.ascii
 .. automodule:: pytato.visualization.fancy_placeholder_data_flow
 """
 
 from .dot import get_dot_graph, show_dot_graph, get_dot_graph_from_partition
-from .ascii import get_ascii_graph, show_ascii_graph
 from .fancy_placeholder_data_flow import show_fancy_placeholder_data_flow
 
 
 __all__ = [
     "get_dot_graph", "show_dot_graph", "get_dot_graph_from_partition",
 
-    "get_ascii_graph", "show_ascii_graph",
-
     "show_fancy_placeholder_data_flow",
 ]
diff --git a/pytato/visualization/ascii.py b/pytato/visualization/ascii.py
deleted file mode 100644
index e417a9b..0000000
--- a/pytato/visualization/ascii.py
+++ /dev/null
@@ -1,124 +0,0 @@
-"""
-.. currentmodule:: pytato
-
-.. autofunction:: get_ascii_graph
-.. autofunction:: show_ascii_graph
-"""
-__copyright__ = """
-Copyright (C) 2021 University of Illinois Board of Trustees
-"""
-
-__license__ = """
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-"""
-
-from typing import Union, List, Dict
-from pytato.transform import ArrayOrNames
-from pytato.array import Array, DictOfNamedArrays, InputArgumentBase
-from pytato.visualization.dot import ArrayToDotNodeInfoMapper
-from pytato.codegen import normalize_outputs
-from pytools import UniqueNameGenerator
-
-
-# {{{ Show ASCII representation of DAG
-
-def get_ascii_graph(result: Union[Array, DictOfNamedArrays],
-                    use_color: bool = True) -> str:
-    """Return a string representing the computation of *result*
-    using the `asciidag <https://pypi.org/project/asciidag/>`_ package.
-
-    :arg result: Outputs of the computation (cf.
-        :func:`pytato.generate_loopy`).
-    :arg use_color: Colorized output
-    """
-    outputs: DictOfNamedArrays = normalize_outputs(result)
-    del result
-
-    mapper = ArrayToDotNodeInfoMapper()
-    for elem in outputs._data.values():
-        mapper(elem)
-
-    nodes = mapper.nodes
-
-    input_arrays: List[Array] = []
-    internal_arrays: List[ArrayOrNames] = []
-    array_to_id: Dict[ArrayOrNames, str] = {}
-
-    id_gen = UniqueNameGenerator()
-    for array in nodes:
-        array_to_id[array] = id_gen("array")
-        if isinstance(array, InputArgumentBase):
-            input_arrays.append(array)
-        else:
-            internal_arrays.append(array)
-
-    # Since 'asciidag' prints the DAG from top to bottom (ie, with the inputs
-    # at the bottom), we need to invert our representation of it, that is, the
-    # 'parents' constructor argument to Node() actually means 'children'.
-    from asciidag.node import Node  # type: ignore[import]
-    asciidag_nodes: Dict[ArrayOrNames, Node] = {}
-
-    from collections import defaultdict
-    asciidag_edges: Dict[ArrayOrNames, List[ArrayOrNames]] = defaultdict(list)
-
-    # Reverse edge directions
-    for array in internal_arrays:
-        for _, v in nodes[array].edges.items():
-            asciidag_edges[v].append(array)
-
-    # Add the internal arrays in reversed order
-    for array in internal_arrays[::-1]:
-        ary_edges = [asciidag_nodes[v] for v in asciidag_edges[array]]
-
-        if array == internal_arrays[-1]:
-            ary_edges.append(Node("Outputs"))
-
-        asciidag_nodes[array] = Node(f"{nodes[array].title}",
-                              parents=ary_edges)
-
-    # Add the input arrays last since they have no predecessors
-    for array in input_arrays:
-        ary_edges = [asciidag_nodes[v] for v in asciidag_edges[array]]
-        asciidag_nodes[array] = Node(f"{nodes[array].title}", parents=ary_edges)
-
-    input_node = Node("Inputs", parents=[asciidag_nodes[v] for v in input_arrays])
-
-    from asciidag.graph import Graph  # type: ignore[import]
-    from io import StringIO
-
-    f = StringIO()
-    graph = Graph(fh=f, use_color=use_color)
-
-    graph.show_nodes([input_node])
-
-    # Get the graph and remove trailing whitespace
-    res = "\n".join([s.rstrip() for s in f.getvalue().split("\n")])
-
-    return res
-
-
-def show_ascii_graph(result: Union[Array, DictOfNamedArrays]) -> None:
-    """Print a graph representing the computation of *result* to stdout using the
-    `asciidag <https://pypi.org/project/asciidag/>`_ package.
-
-    :arg result: Outputs of the computation (cf.
-        :func:`pytato.generate_loopy`) or the output of :func:`get_dot_graph`.
-    """
-
-    print(get_ascii_graph(result, use_color=True))
diff --git a/requirements.txt b/requirements.txt
index 7e69f17..4f9b14d 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -3,5 +3,4 @@ git+https://github.com/inducer/pymbolic.git#egg=pymbolic
 git+https://github.com/inducer/genpy.git#egg=genpy
 git+https://github.com/inducer/loopy.git#egg=loopy
 
-asciidag
 mako
diff --git a/test/test_pytato.py b/test/test_pytato.py
index 5d2343e..5b35bdd 100644
--- a/test/test_pytato.py
+++ b/test/test_pytato.py
@@ -371,37 +371,6 @@ def test_userscollector():
         assert nuc[dag] == 0
 
 
-def test_asciidag():
-    pytest.importorskip("asciidag")
-
-    n = pt.make_size_param("n")
-    array = pt.make_placeholder(name="array", shape=n, dtype=np.float64)
-    stack = pt.stack([array, 2*array, array + 6])
-    y = stack @ stack.T
-
-    from pytato import get_ascii_graph
-
-    res = get_ascii_graph(y, use_color=False)
-
-    ref_str = r"""* Inputs
-*-.   Placeholder
-|\ \
-* | | IndexLambda
-| |/
-|/|
-| * IndexLambda
-|/
-*   Stack
-|\
-* | AxisPermutation
-|/
-* Einsum
-* Outputs
-"""
-
-    assert res == ref_str
-
-
 def test_linear_complexity_inequality():
     # See https://github.com/inducer/pytato/issues/163
     import pytato as pt
-- 
GitLab