Skip to content
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

CausalModel's view_model() fails when dot is not installed #1041

Closed
kbattocchi opened this issue Oct 9, 2023 · 1 comment
Closed

CausalModel's view_model() fails when dot is not installed #1041

kbattocchi opened this issue Oct 9, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@kbattocchi
Copy link
Contributor

Describe the bug

In dowhy 0.10.1, calling view_model() on a CausalModel throws an exception when dot isn't available. In dowhy 0.9 this worked fine even when dot was not available.

Steps to reproduce the behavior

Install dowhy 0.10.1 on a computer without graphviz/dot installed. Then run:

import dowhy.datasets
from dowhy import CausalModel

# generate some data
data = dowhy.datasets.linear_dataset(beta=10, num_common_causes=5, num_samples=5000)

model=CausalModel(data = data["df"], treatment=data["treatment_name"], outcome=data["outcome_name"], graph=data["gml_graph"])

model.view_model()

Actual behavior

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\dowhy\utils\plotting.py:48, in plot(causal_graph, layout_prog, causal_strengths, colors, filename, display_plot, figure_size, **kwargs)
     47 try:
---> 48     from dowhy.utils.graphviz_plotting import plot_causal_graph_graphviz
     50     try:

File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\dowhy\utils\graphviz_plotting.py:7
      6 import numpy as np
----> 7 import pygraphviz
     10 def plot_causal_graph_graphviz(
     11     causal_graph: nx.Graph,
     12     layout_prog: Optional[str] = None,
   (...)
     18     figure_size: Optional[Tuple[int, int]] = None,
     19 ) -> None:

ModuleNotFoundError: No module named 'pygraphviz'

During handling of the above exception, another exception occurred:

FileNotFoundError                         Traceback (most recent call last)
File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pydot.py:1923, in Dot.create(self, prog, format, encoding)
   1922 try:
-> 1923     stdout_data, stderr_data, process = call_graphviz(
...
-> 1933     raise OSError(*args)
   1934 else:
   1935     raise

FileNotFoundError: [WinError 2] "dot" not found in path.

Expected behavior
The model is displayed even though dot is not available.

Version information:

  • DoWhy version 0.10.1

Additional context

One workaround is to explicitly set layout=None when calling view_model. However, it would be nice if the view_model method worked by default, as it used to - one possible fix might be to just set None as the default for layout, instead of the current value of "dot".

@amit-sharma
Copy link
Member

Fixed by #1042

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

No branches or pull requests

2 participants