9

I am running FBProphet with cmdstanpy instead of pystan. For my purpose, I have to run training and predictions multiple times in a jupyter notebook which results in constantly printing :

INFO:cmdstanpy:start chain 1
INFO:cmdstanpy:finish chain 1

The issue arises when I have to run this for more than 10000 models (Im predicting values for each day individually after updating the training set) and which prints 20000 lines. This makes the notebook extremely slow. Is there any way I can stop FBProphet frmo printing these two lines?

Things Ive tried:

  1. Verbose False gives an error :
TypeError                                 Traceback (most recent call last)
<ipython-input-126-586e1241babb> in <module>
     17             model = Prophet(uncertainty_samples=True, weekly_seasonality = True, 
     18                             yearly_seasonality= True, changepoint_prior_scale = 0.5,
---> 19                             daily_seasonality=False, verbose = False)
     20             model.add_seasonality(name='monthly', period=30.5, fourier_order=2)
TypeError: __init__() got an unexpected keyword argument 'verbose'
  1. how to control output from fbprophet? This does not supress the output.

Please Advice.

Madness
  • 127
  • 1
  • 6

3 Answers3

9

This answer works for me to turn off cmdstanpy info

mainly

import logging
logger = logging.getLogger('cmdstanpy')
logger.addHandler(logging.NullHandler())
logger.propagate = False
logger.setLevel(logging.CRITICAL)
uniquegino
  • 1,841
  • 1
  • 12
  • 11
2

The logging level can be controlled by the logger option in the CmdStanModel object when it is created:

import logging
logger = logging.getLogger('simple_example')
logger.setLevel(logging.WARNING)

CmdStanModel(stan_file=your_path,logger=logger)

See https://docs.python.org/3/howto/logging.html#logging-levels for more options. The above just creates a custom logger so that only warning-level messages will be printed, rather than the default info-level as defined in the CmdStanPy utils (https://cmdstanpy.readthedocs.io/en/v0.9.67/_modules/cmdstanpy/utils.html)

GC83
  • 21
  • 3
1

This is how I solved the issue while I was working with PyCharm:

Go to <your_virtual_env>\Lib\site-packages\cmdstanpy\utils.py. Inside get_logger() method, update:

handler.setLevel(logging.INFO)

To this:

handler.setLevel(logging.WARNING)
0sVoid
  • 2,547
  • 1
  • 10
  • 25
  • This is an option but will not work if you want your code to be run by others and have it function identically (since they will not have manually edited `utils.py` on their end) – codeananda Oct 20 '22 at 12:25