Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pymc/distributions/distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
convert_observed_data,
floatX,
)
from pymc.util import UNSET
from pymc.util import UNSET, safe_display
from pymc.vartypes import continuous_types, string_types

__all__ = [
Expand Down Expand Up @@ -544,6 +544,10 @@ def __new__(
rv_out._repr_latex_ = types.MethodType(
functools.partial(str_for_dist, formatting="latex"), rv_out
)

# https://docs.marimo.io/guides/integrating_with_marimo/displaying_objects/#option-1-implement-a-_display_-method
rv_out._display_ = types.MethodType(functools.partial(safe_display, model=model), rv_out)
Copy link
Member

@ricardoV94 ricardoV94 Nov 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's a good time as any to remove pretty print from the variables and leave it to the model graphviz only.

There was an issue/ PR to remove those others for ipython. This is never going to be exhaustive because there are many other ways of creating variables for models


return rv_out

@classmethod
Expand Down
3 changes: 3 additions & 0 deletions pymc/model/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
get_transformed_name,
get_value_vars_from_user_vars,
get_var_name,
safe_display,
treedict,
treelist,
)
Expand Down Expand Up @@ -2280,6 +2281,7 @@ def Deterministic(name, var, model=None, dims=None):
),
var,
)
var._display_ = types.MethodType(functools.partial(safe_display, model=model), var)

return var

Expand Down Expand Up @@ -2408,5 +2410,6 @@ def normal_logp(value, mu, sigma):
),
var,
)
var._display_ = types.MethodType(functools.partial(safe_display, model=model), var)

return var
8 changes: 8 additions & 0 deletions pymc/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,3 +570,11 @@ def get_random_generator(
return random_generator_from_state(get_state_from_generator(seed))
seed = deepcopy(seed)
return np.random.default_rng(seed)


def safe_display(variable, model):
import marimo as mo

from pymc.model_graph import model_to_mermaid

return mo.mermaid(model_to_mermaid(model=model, var_names=[variable.name]))