Frequently Encountered Lazy Evaluation Gotchas

Handling RecursionError

Errors such as “RecursionError: maximum recursion depth exceeded” are seen when the computation graph for which code is being generated for has a path of the order of 1000 intermediate arrays. Following remedies may be helpful:

  • Assessing if the same result can be achieved with fewer number of array operations.

  • Increasing the recursion limit via sys.setrecursionlimit().

  • Checking for any broken memoization implementation in the sub-classed pytato.transform.Mapper.

Traversal order in a pytato.transform.Mapper

Although the direction of our DAG is similar to a data-flow graph, the traversal order in mapper is the opposite way around i.e. the mapper method of a node’s user would be entered before the node’s mapper method. However, the mapper method of a node would be returned before it’s user’s mapper method is returned. Similar traversal order is routinely seen in visitors of other packages like pymbolic, pycparser, etc.