Bishalsarang / Recursion-Tree-Visualizer

A simple python package that helps to visualise any recursive function by adding a single line of code.
https://pypi.org/project/recursion-visualiser/
MIT License
111 stars 17 forks source link

Unexpected behavior #25

Closed ManiAm closed 2 years ago

ManiAm commented 2 years ago

I have graphviz-5.0.1, python 3.10.6, windows 10. Running the following code,

import os
os.environ["PATH"] += os.pathsep +  'C:/Program Files/Graphviz/bin/'

from visualiser.visualiser import Visualiser as vs

@vs(node_properties_kwargs={"shape":"record", "color":"#f57542", "style":"filled", "fillcolor":"grey"})
def fib(n):
    if n <= 1:
        return n
    return fib(n=n-1) + fib(n=n-2)

print(fib(n=3))
# Save recursion tree to a file
vs.make_animation("fibonacci.gif", delay=2)

produces an incorrect png/gif.

fibonacci

fibonacci

Bishalsarang commented 2 years ago

Seems like it is working for me. Can you try installing this version of graphviz and see if that works

ManiAm commented 2 years ago

I found the root cause. When I am running the script inside ipynb, then it starts to misbehave sometimes. Running the script directly seems to be ok.

ManiAm commented 2 years ago

inside ipynb, when I run two instances of the program one after the other, the results messed up together.

2022-08-27_12-41-28

ManiAm commented 2 years ago

it looks like the result of the two gets merged. visualizer does not clear the result of the previous invocation.

fact

Bishalsarang commented 2 years ago

Thank you for the detailed steps for reproducing the issue. Will look into that.

Bishalsarang commented 2 years ago

The issue has been fixed and released in https://github.com/Bishalsarang/Recursion-Tree-Visualizer/releases/tag/v1.0.3

Install the latest version from pip and it should work fine.

ManiAm commented 2 years ago

thanks! it is working now.