Fix progressbar bug for parallel SMC sampling #7079
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
See discussion in #7078 (comment)
Description
As discussed in #7078, running parallel SMC sampling (cores > 1) from within a notebook crashes. The package
progressbar
throws an error because it is not findingHTML
. That error only occurs when running multiple chains in parallel from within a jupyter notebook.This is because the
progressbar
module conditionally importsHTML
at import time if it detects that it is imported from a notebook process, which is the case when the progress bar is created before the multi-chain forking. When the subprocess corresponding to one chain then tries to update the progress bar, it does so from a process that was not a notebook process when it imported theprogressbar
module after forking, and thusHTML
is not imported.The simplest fix, that I have implemented, is to force the use of a non-HTML (aka console, i.e. text mode) progressbar when
sample_smc
is running parallel chains. 2-lines fix :)While I discovered this bug while investing another behaviour in #7078, it is also the underlying issue to #5855 and #5980, which were closed but not really fixed.
I wish I could add a unit test, but not easy way as this behavior occurs only when
pymc.smc_sample
is called from within a jupyter notebook. A test would therefore have to run a jupyter server then run a notebook then catch the error.No documentation update needed.
Related Issue
Checklist
Type of change
📚 Documentation preview 📚: https://pymc--7079.org.readthedocs.build/en/7079/