-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Do not expect model variables to always have str_repr
#6311
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
Comments
CC @larryshamalama in case you want to take on this one |
str_repr
str_repr
I'd love to! However, I'm quite busy this month and probably can only get to this once the semester is over. If anyone else reading this thread wants to take this issue in the meanwhile, you are more than welcome. Adding @ricardoV94's relevant comment from a discussion thread about this. |
Some progress is being made, but mostly taking nearly verbatim the code from aeppl/printing.py... Should we still attach import pymc as pm
from pymc.printing import str_repr # newly created dispatch function
with pm.Model() as model:
x = pm.Normal("x", 0., 1.)
y = pm.Normal.dist(0., 1.)
model.register(y, name="y")
# (1)
x.str_repr()
y.str_repr()
model.str_repr()
# (2)
str_repr(x)
str_repr(y)
str_repr(model) Should we expect (1), (2) or both of the examples above to work? |
I think it's enough if the Model has the pretty rendering, we don't need each variable to have it by itself. Would be good to adapt the code to work with dispatching so that RVs/Ops created by third party libraries can be given nice printing as well without PyMC having to know about them. |
I think we can keep attaching it to the Model and variables created via Distributions, we should just make sure the Model does not expect all it's variables to have the attached method (it can call the function itself). |
Uh oh!
There was an error while loading. Please reload this page.
When we create RVs via the the Distribution interface, they get some
str_repr
methods glued to them:pymc/pymc/distributions/distribution.py
Lines 302 to 306 in 4acd98e
The
Model.str_repr
then expects all named variables to have this method, which fails for automatically generated RVs such as those in automatic imputationIt also which makes it annoying to replace / register variables manually:
Suggestion
Do not rely on the methods being attached for
model.str_repr
pymc/pymc/printing.py
Line 103 in fd5a6cc
Instead just use a dispatch base approach to pretty-print any model variables based on their Op types as discussed elsewhere.
The text was updated successfully, but these errors were encountered: