Skip to content

BUG: d3viz html template is not found after installation #333

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
l8l opened this issue Jun 10, 2023 · 14 comments
Open

BUG: d3viz html template is not found after installation #333

l8l opened this issue Jun 10, 2023 · 14 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@l8l
Copy link
Contributor

l8l commented Jun 10, 2023

Describe the issue:

I followed the example described here: https://pytensor.readthedocs.io/en/latest/library/d3viz/index.html

I did not change any line of the example code provided and everything executes fine (including the installation of pydot-ng) until the line d3v.d3viz(predict, 'examples/mlp.html'), where an error is thrown, even though the import statement import pytensor.d3viz as d3v returns no error.

The error is: No such file or directory: '<HOME>/.local/lib/python3.11/site-packages/pytensor/d3viz/html/template.html'. When checking the directory, I can see that the directory '<HOME>/.local/lib/python3.11/site-packages/pytensor/d3viz/ actually does exist but there is no /html/ folder inside.

I also made sure that graphviz is installed on the system.

What to do about this? Thanks!

Reproducable code example:

import pytensor.d3viz as d3v
d3v.d3viz(predict, 'examples/mlp.html')
# where predict is the function specified in this example: https://pytensor.readthedocs.io/en/latest/library/d3viz/index.html

Error message:

FileNotFoundError                         Traceback (most recent call last)
Cell In[16], line 2
      1 import pytensor.d3viz as d3v
----> 2 d3v.d3viz(predict, 'examples/mlp.html')

File ~/.local/lib/python3.11/site-packages/pytensor/d3viz/d3viz.py:88, in d3viz(fct, outfile, copy_deps, *args, **kwargs)
     86 # Read template HTML file
     87 template_file = os.path.join(__path__, "html", "template.html")
---> 88 with open(template_file) as f:
     89     template = f.read()
     91 # Copy dependencies to output directory

FileNotFoundError: [Errno 2] No such file or directory: '~/.local/lib/python3.11/site-packages/pytensor/d3viz/html/template.html'

PyTensor version information:

Pytensor Version 2.12.1, installed with pip
Python Version 3.11.3
Linux

Context for the issue:

The graph visualization feature would be very important for my work.

@l8l l8l added the bug Something isn't working label Jun 10, 2023
@ricardoV94
Copy link
Member

The d3viz functionality is not being tested or really used by the developers, so I am not surprised it is broken.

Hopefully someone will be able to take a look to give feedback

@ricardoV94 ricardoV94 added the help wanted Extra attention is needed label Jun 12, 2023
@l8l
Copy link
Contributor Author

l8l commented Jun 12, 2023

Thanks for the post! I hope so too. It seems that one only needs to make sure some template html file is copied to the d3viz directory upon installation to fix the issue.

You're saying that developers don't really use this feature? But isn't the graph visualization quite useful? I think it is a really cool feature, distinguishing it from other computational graph frameworks that is worth maintaining!

@ricardoV94
Copy link
Member

Yeah, I think it could be useful, I just haven't seen much use (or any at all) since we forked from Theano/Aesara.

Other libraries usually rely on a condensed type of graph, for instance just showing relationship between named nodes, such as this utility in PyMC:
https://www.pymc.io/projects/docs/en/stable/api/generated/pymc.model_to_graphviz.html

Some example outputs in:
https://www.pymc.io/projects/examples/en/latest/case_studies/multilevel_modeling.html

For pure PyTensor graphs I usually just use dprint, I find a graphical form of all operations too much to digest in practice.


Anyway, in the codebase, it seems we have just these tests: https://github.com/pymc-devs/pytensor/blob/main/tests/d3viz/test_d3viz.py

However it doesn't seem the dependency is being installed according to the CI logs: https://github.com/pymc-devs/pytensor/actions/runs/5212573519/jobs/9406421099#step:6:1730

Even though we request it be installed:

mamba install --yes -q "python~=${PYTHON_VERSION}=*_cpython" mkl numpy scipy pip mkl-service graphviz cython pytest coverage pytest-cov pytest-benchmark sympy

So a first step, would be to try and run those tests locally and see if they pass or are broken.

@maresb
Copy link
Contributor

maresb commented Jun 12, 2023

I think this is a setuptools issue. One probably needs to add the correct files to MANIFEST.in. Or even better, switch to Hatch so that we don't have to deal with setuptools weirdness.

@ricardoV94
Copy link
Member

ricardoV94 commented Jun 12, 2023

[Deleted wrong comment]

@ricardoV94
Copy link
Member

ricardoV94 commented Jun 12, 2023

I think this is a setuptools issue. One probably needs to add the correct files to MANIFEST.in. Or even better, switch to Hatch so that we don't have to deal with setuptools weirdness.

You mean the specific template.html issue?

For the tests it seems we actually have to install pydot and not just graphviz:

if hasattr(pd, "find_graphviz"):
if pd.find_graphviz():
pydot_imported = True
else:
pydot_imported_msg = "pydot can't find graphviz"
else:
pd.Dot.create(pd.Dot())
pydot_imported = True

However I am not sure this package is still maintaned? Last release was February 2021: https://pypi.org/project/pydot/#history

@maresb
Copy link
Contributor

maresb commented Jun 12, 2023

Ah, I meant the original issue, not the CI tests

@ricardoV94
Copy link
Member

Okay, so we should fix the setup to handle those path issues correctly and decide whether we want to test pydot/graphviz support or not.

If not, I guess there's no other reason to install graphviz either

@ricardoV94
Copy link
Member

The pydot_ng recommendation should definitely be dropped and the code logic as well, since that project is officially archived in favor of pydot: https://github.com/pydot/pydot-ng

@l8l
Copy link
Contributor Author

l8l commented Jun 12, 2023

Thanks everyone for trying to solve the problem!
@ricardoV94 : I tried model_to_graphviz() and dprint() that you recommended and they seem nice and useful but the first one has much less information about the computational graph than I need and the second one is not very visual (and only for single tensors). So I strongly vote in favor of maintaining the pydot-d3viz implementation.
Yeah, it sounds reasonable to replace the pydot_ng recommendation by pydot.

@ricardoV94
Copy link
Member

Sure thanks for the feedback.

dprint allows multiple tensors. Just pass a list with multiple variables, or you can pass a compiled function as well.

But I agree it's a different use case.

Would you have availability to update the docs regarding the ng library?

Also @maresb do you have more specific recommendations for what the fix could look like?

@l8l
Copy link
Contributor Author

l8l commented Jun 12, 2023

I committed a pull request to fix the -ng-recommendation: #336

@ricardoV94
Copy link
Member

It seems this file used to exist in Theano, and no longer exists in PyTensor: https://github.com/Theano/Theano/blob/master/theano/d3viz/html/template.html

@ricardoV94
Copy link
Member

It was lost in the rename to PyTensor: 19e1a98#diff-976e71f8933be25c4bd13d49f8ebf4c8b9f524585a85b1303409ffc44182d577

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants