pymc-devs / pymc

Bayesian Modeling and Probabilistic Programming in Python
https://docs.pymc.io/
Other
8.47k stars 1.97k forks source link

Allow opting out of model nesting by setting `model=None` #7352

Closed ricardoV94 closed 2 weeks ago

ricardoV94 commented 3 weeks ago

Description

This PR allows setting model=None to explicitly disable model nesting. This is needed for model transformations do, observe, clone, remove_value_transforms, freeze_rv_and_dims to be possible under a model context without side-effects on the original model.

I still think model nesting is an overkill, but a lot of code out there depends on it so I am not touching it.

I also updated the docstrings with more relevant (imo) examples. The previous example was broken as per #6715 and I am not sure we really want to incentivize people to subclass PyMC models. That certainly shouldn't be the focus of the docstrings?

Finally, removed deprecated functionality.

Related Issue

Checklist

Type of change


📚 Documentation preview 📚: https://pymc--7352.org.readthedocs.build/en/7352/

ricardoV94 commented 2 weeks ago

I wonder how .to_graphviz looks for hierarchical models 🤔

Doesn't do anything different for the outer model. You can just call .to_graphviz on submodels and will only show the variables that belong to it IIRC