-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Supress warning SMC initialization #5827
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
Conversation
Might you be catching too many things with that context manager? Including whatever progressbar uses for piping the messages? |
It is not the catching, removing the warning has the same effect. And works as intended when no parallel sampling. |
What about a model that would not raise the warning? |
Codecov Report
@@ Coverage Diff @@
## main #5827 +/- ##
==========================================
- Coverage 89.40% 89.38% -0.02%
==========================================
Files 74 74
Lines 13772 13777 +5
==========================================
+ Hits 12313 12315 +2
- Misses 1459 1462 +3
|
Not working. Also I just checked that is not working inside VS code or the browser. And checked a couple of older versions of fastprogressbar as well. |
I remember the code was pretty hacky / fragile and I could only see output in some contexts (e.g., terminal vs pycharm). So I am not super shocked |
What about just leaving the "print()" for the moment and open an issue so we can back to this after the release? It is possible to locally disable the pre-commit so it does not complain about the print? |
You can do |
I just confirmed that I see the message in a vanilla bash terminal, but not in Jupyter Notebook. This definitely used to work in notebooks: import pymc as pm
with pm.Model() as m:
x = pm.Normal("x")
y = pm.Normal("y", x, observed=5)
pm.sample_smc() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What a hack xD!!! LGTM otherwise
Heads up that today this hack bit us, in an admittedly niche setup:
So it is interactive and called from something else than a terminal or a jupyter notebook, and on a Windows machine to boot. And in that case, apparently I'm heartbroken 💔 and super tickled of trying to find out what's going on. I'll do more debugging next week (need to dig up another Windows machine for my own tests), will report here. Maybe I'll simply add a check that In the meantime if you have any idea, they're very welcome! |
Yup, I can confirm that the below patch fixes the issue with reticulate (which indeed seems to mangle somewhat stdout). At the moment I'm monkey-patching the package on the fly (🐷 ). Want me to open a proper PR? --- a/kernels.py 2024-06-12 22:15:14.506303300 +0200
+++ b/kernels.py 2024-06-12 22:15:32.926642800 +0200
@@ -186,7 +186,8 @@
def initialize_population(self) -> dict[str, np.ndarray]:
"""Create an initial population from the prior distribution"""
- sys.stdout.write(" ") # see issue #5828
+ if sys.stdout is not None:
+ sys.stdout.write(" ") # see issue #5828
with warnings.catch_warnings():
warnings.filterwarnings(
"ignore", category=UserWarning, message="The effect of Potentials" |
This is a little bit weird. Catching the warning makes the progressbar not progress. But it seems this is not related to the warning itself, manually removing the warning from
sample_prior_predictive
has the same effect. Additionally it works when core=1, i.e. not parallel sampling and it also works if we add a print statement. So I guess is related to something going on herepymc/pymc/smc/sample_smc.py
Lines 398 to 417 in 5703a9d