Supress PyStan 2 logging in Jupyter Notebook

Summary

I would like to suppress PyStan (2.19) loggings from the function sampling in Jupyter Notebook since I will use it as a Jupyter Book.

What was the process?

I started a new conda environment (conda create) and installed numpy, pandas, seaborn, matplotlib, ipykernel, arviz, and pystan (conda install), except pystan that I used the version (conda install pystan=2). After that I installed the environment as a kernel in Jupyter. However, I couldn’t compile stan files, and I solved this problem including the parameter extra_compile_args=["-w"] in StanModel class. I think this should be sufficient to reproduce this situation.

Additional Info

  • Operating System: Linux Ubuntu 21.04
  • Python Version: 3.9.7
  • PyStan Version: 2.19.1.1
  • gcc-version: 10.3.0

What I have already tried?

How the logging looks like?

Gradient evaluation took 9e-06 seconds
Gradient evaluation took 1.2e-05 seconds
1000 transitions using 10 leapfrog steps per transition would take 0.09 seconds.
Adjust your expectations accordingly!
1000 transitions using 10 leapfrog steps per transition would take 0.12 seconds.
Gradient evaluation took 8e-06 seconds

I would appreciate some help. Thanks!

1 Like

Hi, try the following

import logging
logger = logging.getLogger('pystan')
logger.addHandler(logging.NullHandler())
import pystan
1 Like

Thanks for the fast answer, I appreciate it! However, this did not work for me :(

Then, I tried to create an environment from the following environment.yml file:

name: test
channels:
  - conda-forge
dependencies:
  - python=3.8
  - jupyterlab=2.1
  - numba
  - numpy=1.21
  - pip
  - pandas=1.3
  - ipykernel
  - pip:
      - pystan==2.19.1.1

I cannot explain why, but these specifications solved this problem. Maybe it is related to a dependency on conda installation? But, again, thanks for the reply!

1 Like

If you are willing, I think it would be good to report this as a bug to the maintainers of the conda PyStan installation. You can do that here if you have a GitHub account. I would also be willing to report it for you, but they may have a few questions to help track down the issue

2 Likes

Thanks! I’ll do it!