carlsborg / rcviz Goto Github PK
View Code? Open in Web Editor NEWPython call graph visualization for recursive functions.
Python call graph visualization for recursive functions.
I adapted your great library to make a recursion visualizer for my students at UC Berkeley.
Source code @
https://github.com/pamelafox/recursive-visualizations
Usable @ https://www.recursionvisualizer.com/
I'm wondering if you can clarify the license of your repository, so that I can put an appropriate license on my repo? I currently link to your library on the website to give attribution, but I don't know if that's okay.
Thanks for the library!
Firstly - thank you for this. It's great!
rcviz working OK with other alfgorithms.
I'm using python 3.6.6.
I have an issue with a Tower of Hanoi algorithm (attached). Algorithm runs fine without rcviz. I'd like to visualise it if possible.
I get a traceback on line 177 or rcviz.py (KeyError)
If you have any ideas, it would be much appreciated! :)
hanoi.txt
Thanks in advance
Any ideas on how to fix it for python 3.8?
python --version
Python 3.8.2
python3 example_qsort.py
Traceback (most recent call last):
File "example_qsort.py", line 2, in <module>
from rcviz import callgraph, viz
File "/Users/x/Projects/rcviz/rcviz/__init__.py", line 2, in <module>
from .rcviz import callgraph, viz
File "/Users/x/Projects/rcviz/rcviz/rcviz.py", line 12, in <module>
class callgraph(object):
File "/Users/x/Projects/rcviz/rcviz/rcviz.py", line 17, in callgraph
_callers: Dict[int, node_data] = {} # caller_fn_id : node_data
NameError: name 'node_data' is not defined
after cloning repo on disk and installing required dependencies for ubuntu. I run sudo python setup.py install
. but it shows this message
vish@Trs99:~/gitrepos/rcviz$ sudo python setup.py install
running install
running bdist_egg
running egg_info
creating rcviz.egg-info
writing requirements to rcviz.egg-info/requires.txt
writing rcviz.egg-info/PKG-INFO
writing top-level names to rcviz.egg-info/top_level.txt
writing dependency_links to rcviz.egg-info/dependency_links.txt
writing manifest file 'rcviz.egg-info/SOURCES.txt'
reading manifest file 'rcviz.egg-info/SOURCES.txt'
writing manifest file 'rcviz.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_py
creating build
creating build/lib.linux-x86_64-2.7
creating build/lib.linux-x86_64-2.7/rcviz
copying rcviz/rcviz.py -> build/lib.linux-x86_64-2.7/rcviz
copying rcviz/init.py -> build/lib.linux-x86_64-2.7/rcviz
creating build/bdist.linux-x86_64
creating build/bdist.linux-x86_64/egg
creating build/bdist.linux-x86_64/egg/rcviz
copying build/lib.linux-x86_64-2.7/rcviz/rcviz.py -> build/bdist.linux-x86_64/egg/rcviz
copying build/lib.linux-x86_64-2.7/rcviz/init.py -> build/bdist.linux-x86_64/egg/rcviz
byte-compiling build/bdist.linux-x86_64/egg/rcviz/rcviz.py to rcviz.pyc
byte-compiling build/bdist.linux-x86_64/egg/rcviz/init.py to init.pyc
creating build/bdist.linux-x86_64/egg/EGG-INFO
copying rcviz.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO
copying rcviz.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying rcviz.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying rcviz.egg-info/not-zip-safe -> build/bdist.linux-x86_64/egg/EGG-INFO
copying rcviz.egg-info/requires.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying rcviz.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
creating dist
creating 'dist/rcviz-0.1-py2.7.egg' and adding 'build/bdist.linux-x86_64/egg' to it
removing 'build/bdist.linux-x86_64/egg' (and everything under it)
Processing rcviz-0.1-py2.7.egg
creating /usr/local/lib/python2.7/dist-packages/rcviz-0.1-py2.7.egg
Extracting rcviz-0.1-py2.7.egg to /usr/local/lib/python2.7/dist-packages
Adding rcviz 0.1 to easy-install.pth file
Installed /usr/local/lib/python2.7/dist-packages/rcviz-0.1-py2.7.egg
Processing dependencies for rcviz==0.1
Searching for pygraphviz
Reading https://pypi.python.org/simple/pygraphviz/
Reading http://networkx.lanl.gov/download
Reading http://networkx.lanl.gov/download/pygraphviz
Reading http://networkx.lanl.gov/pygraphviz
Reading http://networkx.lanl.gov/pygraphviz/
Reading http://networkx.lanl.gov/wiki/download
Reading http://pygraphviz.github.io
Reading http://sourceforge.net/project/showfiles.php?group_id=122233&package_id=161979
Reading https://pypi.python.org/pypi/pygraphviz
Best match: pygraphviz 1.3rc2
Downloading https://pypi.python.org/packages/source/p/pygraphviz/pygraphviz-1.3rc2.zip#md5=62bbf0cb4138fe569226ee923e0e04f7
Processing pygraphviz-1.3rc2.zip
Writing /tmp/easy_install-uYGEA5/pygraphviz-1.3rc2/setup.cfg
Running pygraphviz-1.3rc2/setup.py -q bdist_egg --dist-dir /tmp/easy_install-uYGEA5/pygraphviz-1.3rc2/egg-dist-tmp-rtvknc
Trying pkg-config
library_dirs=
include_dirs=/usr/include/graphviz
warning: no previously-included files matching '~' found anywhere in distribution
warning: no previously-included files matching '.pyc' found anywhere in distribution
warning: no previously-included files matching '.svn' found anywhere in distribution
no previously-included directories found matching 'doc/build'
pygraphviz/graphviz_wrap.c:130:21: fatal error: Python.h: No such file or directory
^
compilation terminated.
error: Setup script exited with error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
I'm running OS X 10.11.4, using Anaconda. If I paste your sample code into a python shell, it works fine, but using the %paste magic function in ipython results in the error pasted below. I also tried it in an iPython Notebook--same result.
$ ipython
Python 2.7.11 |Anaconda 2.4.1 (x86_64)| (default, Dec 6 2015, 18:57:58)
Type "copyright", "credits" or "license" for more information.
IPython 4.0.1 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: %paste
from rcviz import callgraph, viz
@viz
def quicksort(items):
if len(items) <= 1:
return items
else:
pivot = items[0]
lesser = quicksort([x for x in items[1:] if x < pivot])
greater = quicksort([x for x in items[1:] if x >= pivot])
return lesser + [pivot] + greater
print quicksort( list("helloworld") )
callgraph.render("sort.png")
## -- End pasted text --
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-1-2d0324c766ba> in <module>()
11 return lesser + [pivot] + greater
12
---> 13 print quicksort( list("helloworld") )
14 callgraph.render("sort.png")
/Users/harding/anaconda/lib/python2.7/site-packages/rcviz-0.1-py2.7.egg/rcviz/rcviz.pyc in __call__(self, *args, **kwargs)
172 if caller_frame_id:
173 edgeinfo = [this_frame_id, callgraph.get_counter()]
--> 174 g_callers[caller_frame_id].child_methods.append( edgeinfo )
175 callgraph.increment()
176
KeyError: 4329494704
In [2]:
I came across this library and I must say I am really happy to have it.
However, there is a critical issue that blocks basically every real-case use of this. This is related to the fact that arguments of calls are tracked by reference, and so if some arguments are changed during or after the call (side-effect), then the rendering visualizes the updated values and not the original values used when the call was made. The problem is that one cannot implement a workaround in the tracked procedure without removing the side-effects on the arguments.
Example:
suppose there is a quicksort procedure that does not relies on comprehension, e.g.:
def quicksort(a, i, j):
if i < j - 1:
k = partition(a, i, j)
quicksort(a, i, k)
quicksort(a, k + 1, j)
When this procedure is tracked, e.g. with decorator @rcviz.viz, the rendered tree shows the same content for the array argument a, since this is stored as a reference.
I think a possible fix to this is to edit the init method in the file node_data.py, replacing
self.args = _args
self.kwargs = _kwargs
self.fn_name = _fnname
self.ret = _ret
with
self.args = copy.deepcopy(_args)
self.kwargs = copy.deepcopy(_kwargs)
self.fn_name = _fnname
self.ret = copy.deepcopy(_ret)
Of course one needs to import the python module copy
BTW. it seems something similar is already done for auxdata.update when adding user assigned track data.
PS. I have created a pull request with the suggested fix.
Hi and thanks for you work. This is really useful for teaching my students.
Could you add an option to get a different output graph : the upper half of the tree only with the parameters and the lower half with an symetric, inverted tree, with all the values return, just like this :
Thanks again for this great library.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.