Running Python in reverse
Hi everyone, Christian Tismer encouraged me to post the following directly to the pypy mailing list. My main Python project is Gato, a software for visualizing (or animating) graph algorithms; see http://gato.sourceforge.net/wiki/pmwiki.php/Main/Screenshots. The main ingredients of Gato are a debugger subclass, some GUI elements and code for drawing graphs. The goal is to have an interactive, dynamic version of the classical comp.sci. text book, where, typically, some graph algorithm is given as pseudo code and you see (at best) a before, during, and after snapshot picture of its working on some graph. Python is a perfectly fine replacement for pseudo code and the execution and directly coupled visualization, which you can control just like a debugger, convey much more than static pictures. Winfried Hochstaettler, some university colleagues, and myself have used this for teaching discrete math, combinatorial optimization and comp.sci.classes with quite favorable comments from everyone involved. The number one request was always the ability to track back. I started to implement an instant replay of the last visualization effect (change of color, blink etc.) and started to think about a proper way of supporting the ability to step back in time. This essentially boils down to implementing one of the classical design patterns for supporting unlimited undo (and redo), treating the visualization effects as commands. This decouples the state (values of all variables used) of the algorithm from the state of the visualization, hence running the algorithm after a couple of Undos is not possible (One could fake that by Redoing everything and then continuing execution). Supporting an update of all variables gets kind of messy in standard Python. A cleaner approach would be to have a Python interpreter which can run backwards. Christian thinks it would be feasible in PyPy. This actually would be extremely nice for a number of applications - teaching Python - teaching algorithms with Python - debugging in general I am somewhat embarrassed to ask for a feature without much to offer. But realistically, I cannot promise more than to be a tester and happy user. Best, Alexander PS: Gato is LGPL. The algorithms we have are copyright Springer, as we have a textbook & software package coming out this year. PPS: There is a C-syntax-based tool which can run backwards: http://www.dis.uniroma1.it/~demetres/Leonardo/Leonardo.html -- schliep@molgen.mpg.de http://algorithmics.molgen.mpg.de
Hi Alexander, On Fri, Jan 07, 2005 at 12:04 +0100, Alexander Schliep wrote:
Christian Tismer encouraged me to post the following directly to the pypy mailing list.
My main Python project is Gato, a software for visualizing (or animating) graph algorithms; see http://gato.sourceforge.net/wiki/pmwiki.php/Main/Screenshots. The main ingredients of Gato are a debugger subclass, some GUI elements and code for drawing graphs.
Looks really nice!
The goal is to have an interactive, dynamic version of the classical comp.sci. text book, where, typically, some graph algorithm is given as pseudo code and you see (at best) a before, during, and after snapshot picture of its working on some graph.
makes sense!
Python is a perfectly fine replacement for pseudo code and the execution and directly coupled visualization, which you can control just like a debugger, convey much more than static pictures. Winfried Hochstaettler, some university colleagues, and myself have used this for teaching discrete math, combinatorial optimization and comp.sci.classes with quite favorable comments from everyone involved.
The number one request was always the ability to track back. I started to implement an instant replay of the last visualization effect (change of color, blink etc.) and started to think about a proper way of supporting the ability to step back in time. This essentially boils down to implementing one of the classical design patterns for supporting unlimited undo (and redo), treating the visualization effects as commands.
This decouples the state (values of all variables used) of the algorithm from the state of the visualization, hence running the algorithm after a couple of Undos is not possible (One could fake that by Redoing everything and then continuing execution). Supporting an update of all variables gets kind of messy in standard Python.
Yes, i see the problem. At EuroPython 2004 there also was Michael Salib who also presented his wish to have a "time warp" debugger that allows to arbitrarily move within execution time of your program and see all the state. And IIRC, we have been discussing this between PyPy developers a bit sometimes under the term "History Object Space". An object space in PyPy encapsulates and manages all state of Python objects and all accesses and modifications take place through calling methods on such "Space" objects.
A cleaner approach would be to have a Python interpreter which can run backwards. Christian thinks it would be feasible in PyPy.
Rightfully so. I wouldn't call it "run backwards" though but to jump arbitrarily in execution and object states.
This actually would be extremely nice for a number of applications - teaching Python
- teaching algorithms with Python
- debugging in general
Yes, although for debugging in general there is the problem of "side effects" like dealing with files & sockets, databases etc.pp.
I am somewhat embarrassed to ask for a feature without much to offer. But realistically, I cannot promise more than to be a tester and happy user.
Well, the question is if we could tackle the "History Space" (working title) at some sprint and you would attend and we would together incorporate the functionality into your application for the fun of it. I imagine a "time slider" that you can arbitrarily move forward and backward which should be feasible especially for pure algorithms like the ones you show on your Gato webpage. With such functionality you would not need to worry about limited "visualization undo" at all because you could just cleanly redraw. cheers, holger
participants (2)
-
Alexander Schliep -
hpk@trillke.net