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

Unable to see graphviz output from PyMC #4203

Open
ericmjl opened this issue Mar 22, 2025 · 4 comments
Open

Unable to see graphviz output from PyMC #4203

ericmjl opened this issue Mar 22, 2025 · 4 comments
Labels
bug Something isn't working

Comments

@ericmjl
Copy link

ericmjl commented Mar 22, 2025

Describe the bug

When I try to display a PyMC model's graphviz format in Marimo notebooks, nothing shows up:

Image

I am running marimo through uvx. The exact command I used is this:

uvx marimo edit --sandbox notebooks/pymc_demo.py

pymc_demo.py is pasted below.

I am unsure if this is due to a code bug in Marimo or in PyMC. Would love to help out somehow to make it work!

Environment

{
  "marimo": "0.11.25",
  "OS": "Darwin",
  "OS Version": "24.3.0",
  "Processor": "arm",
  "Python Version": "3.13.2",
  "Binaries": {
    "Browser": "--",
    "Node": "--"
  },
  "Dependencies": {
    "click": "8.1.8",
    "docutils": "0.21.2",
    "itsdangerous": "2.2.0",
    "jedi": "0.19.2",
    "markdown": "3.7",
    "narwhals": "1.31.0",
    "packaging": "24.2",
    "psutil": "7.0.0",
    "pygments": "2.19.1",
    "pymdown-extensions": "10.14.3",
    "pyyaml": "6.0.2",
    "ruff": "0.11.2",
    "starlette": "0.46.1",
    "tomlkit": "0.13.2",
    "typing-extensions": "missing",
    "uvicorn": "0.34.0",
    "websockets": "15.0.1"
  },
  "Optional Dependencies": {},
  "Experimental Flags": {
    "rtc": true,
    "chat_sidebar": true,
    "inline_ai_tooltip": true
  }
}

Code to reproduce

# /// script
# requires-python = ">=3.13"
# dependencies = [
#     "graphviz==0.20.3",
#     "marimo",
#     "pymc==5.21.1",
# ]
# ///

import marimo

__generated_with = "0.11.25"
app = marimo.App(width="medium")


@app.cell
def _():
    import pymc as pm
    return (pm,)


@app.cell
def _(pm):
    with pm.Model() as model:
        x = pm.Normal("x", mu=0, sigma=1)
        y = pm.Normal("y", mu=2, sigma=3)
    return model, x, y


@app.cell
def _(model, pm):
    with model:
        trace = pm.sample_prior_predictive()
    return (trace,)


@app.cell
def _(model, pm):
    with model:
        pm.model_to_graphviz()
    return


@app.cell
def _():
    return


if __name__ == "__main__":
    app.run()
@ericmjl ericmjl added the bug Something isn't working label Mar 22, 2025
@ericmjl
Copy link
Author

ericmjl commented Mar 22, 2025

(In case it's of any encouragement, I've fully recommended marimo notebooks to my teammates as part of a broader toolset upgrade!)

@mscolnick
Copy link
Contributor

@ericmjl

you need to return an expression or variable as the last line, but if-statements or with-blocks won't work.

can you try this code:

with model:
    _out = pm.model_to_graphviz()
_out

@ericmjl
Copy link
Author

ericmjl commented Mar 26, 2025

Thanks for getting back, @mscolnick! It looks like that doesn't work:

Image

As a hint, I tried displaying the return from pm.model_to_graphviz(), and it indeed isn't a NoneType, which is reassuring. Can I ask, what is the requirement for an object to be rendered? Does it have to implement, say, __repr_html__? Or is it something else? (Perhaps I should go read the docs and answer it for myself in parallel!)

@mscolnick
Copy link
Contributor

@ericmjl , there are a few ways to render objects in marimo: https://docs.marimo.io/guides/integrating_with_marimo/displaying_objects/

It looks like it tried to output something, but maybe could not be rendered properly. If it outputs HTML that runs scripts and has lots of globals/styles, it is best to put it in an iframe. mo.iframe(out.to_html())

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