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

pyro.render_model() fails to draw overlapping non-nested plates #2980

Closed
fritzo opened this issue Dec 7, 2021 · 5 comments · Fixed by #2983
Closed

pyro.render_model() fails to draw overlapping non-nested plates #2980

fritzo opened this issue Dec 7, 2021 · 5 comments · Fixed by #2983
Labels
bug help wanted Issues suitable for, and inviting external contributions

Comments

@fritzo
Copy link
Member

fritzo commented Dec 7, 2021

Due to a shortcoming in graphviz clusters, Pyro's and NumPyro's pyro.render_model() currently cannot render overlapping non-nested plates, e.g. the Venn diagram

def model():
    plate1 = pyro.plate("plate1", 2, dim=-2)
    plate2 = pyro.plate("plate2", 3, dim=-1)
    with plate1:
        x = pyro.sample("x", dist.Normal(0, 1))
    with plate1, plate2:
        y = pyro.sample("y", dist.Normal(x, 1))
    with plate2:
        pyro.sample("z", dist.Normal(y.sum(-2, True), 1), obs=torch.zeros(3))

pyro.render_model(model)

image

@fritzo fritzo added the bug label Dec 7, 2021
@eb8680
Copy link
Member

eb8680 commented Dec 7, 2021

One workaround would be to add an option to render with daft, which handles plates correctly (example).

@fritzo
Copy link
Member Author

fritzo commented Dec 7, 2021

One optional would be to replace graphviz by daft-pgm, which does support nested plates. However daft-pgm does not support automatic node layout.

A more basic problem is that not all plate nesting patterns can be drawn by rectangular overlapping plates. Maybe we could use a generic venn diagram plotting library?

@fritzo fritzo added the help wanted Issues suitable for, and inviting external contributions label Dec 7, 2021
@fehiepsi
Copy link
Member

fehiepsi commented Dec 8, 2021

@kpj mentioned that we can use graphviz to find positions then use daft for plotting. Probably that will work for a class of models.

@fehiepsi
Copy link
Member

fehiepsi commented Dec 8, 2021

It seems that in numpyro, we have
image
which can be seen as a temporary solution. What do you think @fritzo ?

@fritzo
Copy link
Member Author

fritzo commented Dec 8, 2021

@fehiepsi NumPyro's current behavior looks great, and I suspect it's the only fully general solution 👍 Do you know if that was a recent change, or did I make an error when porting code to Pyro #2962?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug help wanted Issues suitable for, and inviting external contributions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants