py-why / pywhy-graphs

[Experimental] Causal graphs that are networkx-compliant for the py-why ecosystem.
https://py-why.github.io/pywhy-graphs/dev/index.html
MIT License
47 stars 8 forks source link

Bug in pywhy_graphs.viz.draw() #114

Open aryan26roy opened 3 months ago

aryan26roy commented 3 months ago

Checklist

Description

Unable to draw this particular PAG. The bug seems to be coming from viz/draw.py. When the interpreter gets to line 45, the variable arrowtail has not been initialised. It seems that there is no branch from lines 34 to 39 for handling the case where 'o->' edge has been provided.

Python traceback:

``` Traceback (most recent call last): File "", line 1, in File "/Users/aryanroy/Projects/causality/pywhy-graphs/pywhy_graphs/viz/draw.py", line 144, in draw dot, found_circle_sibs = _draw_circle_edges( ^^^^^^^^^^^^^^^^^^^ File "/Users/aryanroy/Projects/causality/pywhy-graphs/pywhy_graphs/viz/draw.py", line 45, in _draw_circle_edges arrowtail=arrowtail, ^^^^^^^^^ UnboundLocalError: cannot access local variable 'arrowtail' where it is not associated with a value ```

Related issues or possible duplicates

Environment

OS: MacOS 14.5 (Sonoma)

Python version:

Output of pip freeze:

``` accessible-pygments==0.0.5 alabaster==0.7.16 appnope==0.1.3 attrs==23.2.0 Babel==2.15.0 backcall==0.2.0 bandit==1.7.5 beautifulsoup4==4.12.3 black==22.12.0 bleach==6.1.0 causal-learn==0.1.3.8 certifi==2024.7.4 charset-normalizer==3.3.2 clarabel==0.9.0 click==8.1.3 cmake==3.28.1 codespell==2.2.5 contourpy==1.2.1 cvxpy==1.5.2 cycler==0.12.1 Cython==3.0.10 decorator==5.1.1 defusedxml==0.7.1 docutils==0.21.2 dodiscover @ file:///Users/aryanroy/Projects/causality/dodiscover dowhy @ file:///Users/aryanroy/Projects/causality/dowhy dunamai==1.18.0 ecos==2.0.14 fastjsonschema==2.20.0 filelock==3.15.4 flake8==5.0.4 fonttools==4.51.0 fsspec==2024.6.1 gitdb==4.0.10 GitPython==3.1.31 graphviz==0.20.1 idna==3.7 imagesize==1.4.1 iniconfig==2.0.0 ipython==7.34.0 isort==5.12.0 jedi==0.18.2 Jinja2==3.1.2 joblib==1.3.1 jsonschema==4.23.0 jsonschema-specifications==2023.12.1 jupyter_client==8.6.2 jupyter_core==5.7.2 jupyterlab_pygments==0.3.0 kiwisolver==1.4.5 latexcodec==3.0.0 markdown-it-py==3.0.0 MarkupSafe==2.1.3 matplotlib==3.8.4 matplotlib-inline==0.1.6 mccabe==0.7.0 mdurl==0.1.2 mistune==3.0.2 mpmath==1.3.0 mypy==0.971 mypy-extensions==1.0.0 nbclient==0.10.0 nbconvert==7.16.4 nbformat==5.10.4 nbsphinx==0.9.4 networkx==3.1 numpy==1.24.4 numpydoc==1.7.0 opt-einsum==3.3.0 osqp==0.6.7.post0 packaging==23.1 pandas==1.5.3 pandocfilters==1.5.1 parso==0.8.3 pastel==0.2.1 pathspec==0.11.1 patsy==0.5.6 pbr==5.11.1 pexpect==4.8.0 pgmpy==0.1.25 pickleshare==0.7.5 pillow==10.3.0 platformdirs==3.8.0 pluggy==1.2.0 poethepoet==0.20.0 poetry-dynamic-versioning==0.25.0 progressbar2==4.2.0 prompt-toolkit==3.0.39 ptyprocess==0.7.0 pybtex==0.24.0 pybtex-docutils==1.0.3 pycodestyle==2.9.1 pydata-sphinx-theme==0.15.4 pydocstyle==6.3.0 pydot==2.0.0 pyflakes==2.5.0 pygam==0.9.0 Pygments==2.15.1 pyparsing==3.1.2 pytest==7.4.0 python-dateutil==2.8.2 python-utils==3.7.0 pytz==2023.3 -e git+ssh://git@github.com/aryan26roy/pywhy-graphs.git@5844e0880672a92247a0324ed45783a4fd8f1ad1#egg=pywhy_graphs PyYAML==6.0 pyzmq==26.0.3 qdldl==0.1.7.post4 referencing==0.35.1 requests==2.32.3 rich==13.4.2 rpds-py==0.19.0 ruff==0.2.0 scikit-learn==1.3.0 scipy==1.11.1 scs==3.2.6 six==1.16.0 smmap==5.0.0 snowballstemmer==2.2.0 soupsieve==2.5 Sphinx==7.3.7 sphinx-copybutton==0.5.2 sphinx-gallery==0.16.0 sphinx-issues==4.1.0 sphinxcontrib-applehelp==1.0.8 sphinxcontrib-bibtex==2.6.2 sphinxcontrib-devhelp==1.0.6 sphinxcontrib-htmlhelp==2.0.5 sphinxcontrib-jsmath==1.0.1 sphinxcontrib-qthelp==1.0.7 sphinxcontrib-serializinghtml==1.1.10 statsmodels==0.14.2 stevedore==5.1.0 sympy==1.13.0 tabulate==0.9.0 threadpoolctl==3.2.0 tinycss2==1.3.0 tokenize-rt==5.1.0 toml==0.10.2 tomli==2.0.1 tomlkit==0.11.8 torch==2.3.1 tornado==6.4.1 tqdm==4.66.4 traitlets==5.9.0 typing_extensions==4.12.2 urllib3==2.2.2 wcwidth==0.2.6 webencodings==0.5.1 ```

Steps to reproduce

Example source:

``` from pywhy_graphs.viz import draw from pywhy_graphs import PAG pag = PAG() pag.add_edge("I", "S", pag.directed_edge_name) pag.add_edge("G", "S", pag.directed_edge_name) pag.add_edge("G", "L", pag.directed_edge_name) pag.add_edge("S", "L", pag.directed_edge_name) pag.add_edge("PSH", "L", pag.directed_edge_name) pag.add_edge("S", "PSH", pag.circle_edge_name) pag.add_edge("S", "G", pag.circle_edge_name) dot_graph = draw(pag) ```