Skip to content

Issue Drawing #322

@njmmerrill

Description

@njmmerrill

I tried to make a hierarchical model and use the hcm.to_pygraphviz() function but have missing dependencies. I am using a Windows Machine and installed graphviz, including adding it to the path but still have missing dependencies.

from IPython.display import SVG
from matplotlib_inline.backend_inline import set_matplotlib_formats

from y0.algorithm.identify import Identification, Query, Unidentifiable, identify, identify_outcomes
from y0.dsl import A, P, U, Variable, Y, Z
from y0.examples import hierarchical as hcme
from y0.graph import NxMixedGraph
from y0.hierarchical import (
    HierarchicalCausalModel,
    QVariable,
    augment_collapsed_model,
    collapse_hcm,
    marginalize_augmented_model,
)

set_matplotlib_formats("svg")


def _draw(hcm: HierarchicalCausalModel) -> SVG:
    graph = hcm.to_pygraphviz()
    graph.layout("dot")
    svg = graph.draw(format="svg:cairo").decode("utf8")
    return SVG(svg)

MeanScores, MeanTutoring = Variable("Ȳ_i"), Variable("Ā_i")

school_mean_model = NxMixedGraph.from_edges(
    directed=[(MeanTutoring, MeanScores)], undirected=[(MeanTutoring, MeanScores)]
)

StudentScores, StudentTutoring, SchoolBudget = Variable("Y"), Variable("A"), Variable("U")

hierarchical_model = HierarchicalCausalModel.from_lists(
    observed_subunits=[StudentTutoring, StudentScores],
    unobserved_units=[SchoolBudget],
    edges=[
        (SchoolBudget, StudentTutoring),
        (StudentTutoring, StudentScores),
        (SchoolBudget, StudentScores),
    ],
)

_draw(hierarchical_model)
---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
Cell In[9], line 13
      1 StudentScores, StudentTutoring, SchoolBudget = Variable("Y"), Variable("A"), Variable("U")
      3 hierarchical_model = HierarchicalCausalModel.from_lists(
      4     observed_subunits=[StudentTutoring, StudentScores],
      5     unobserved_units=[SchoolBudget],
   (...)     10     ],
     11 )
---> 13 _draw(hierarchical_model)

Cell In[6], line 21, in _draw(hcm)
     19 def _draw(hcm: HierarchicalCausalModel) -> SVG:
     20     graph = hcm.to_pygraphviz()
---> 21     graph.layout("dot")
     22     svg = graph.draw(format="svg:cairo").decode("utf8")
     23     return SVG(svg)

File ~\AppData\Local\miniconda3\envs\y0env\Lib\site-packages\pygraphviz\agraph.py:1479, in AGraph.layout(self, prog, args)
   1462 """Assign positions to nodes in graph.
   1463 
   1464 Optional prog=['neato'|'dot'|'twopi'|'circo'|'fdp'|'nop']
   (...)   1476 
   1477 """
   1478 output_fmt = "dot"
-> 1479 data = self._run_prog(prog, " ".join([args, "-T", output_fmt]))
   1480 self.from_string(data)
   1481 self.has_layout = True

File ~\AppData\Local\miniconda3\envs\y0env\Lib\site-packages\pygraphviz\agraph.py:1400, in AGraph._run_prog(self, prog, args)
   1397 p.wait()
   1399 if not data:
-> 1400     raise OSError(b"".join(errors).decode(self.encoding))
   1402 if len(errors) > 0:
   1403     warnings.warn(b"".join(errors).decode(self.encoding), RuntimeWarning)

OSError: Warning: Could not load "C:\Users\merrill\AppData\Local\miniconda3\envs\y0env\Library\bin\gvplugin_pango.dll" - It was found, so perhaps one of its dependents was not.  Try ldd.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions