acerbilab / pyvbmc

PyVBMC: Variational Bayesian Monte Carlo algorithm for posterior and model inference in Python
https://acerbilab.github.io/pyvbmc/
BSD 3-Clause "New" or "Revised" License
114 stars 6 forks source link

Improve Logging #67

Closed Solosneros closed 2 years ago

Solosneros commented 2 years ago

Hello,

we are already using the default Python package for logging in PyVBMC. I believe that there are several open issues that need to be discussed.

In VBMC (MATLAB) the printing of messages is configured using the display option (see vbmc.m). In PyVBMC this has been done in a similar way (see vbmc.py). Logging messages are then logged using the logging levels (WARN/INFO/DEBUG). I believe that this part is ported in a pythonic way and does not need major refactoring.

Some details require refactoring in my opinion:

Output to stderr/stdout:

Currently, we initialize the root logger ourselves, when the user hasn't done that yet. That means by default we log to stdout, but the user can overwrite that logging setting before initializing PyVBMC. See the documentation of the baseConfig. We should give the user some kind of option to configure that.

Printing the column headers and plotting

In Jupiter notebooks when plotting of the iterations is enabled, we want to alternate between logging the column headers, the logging data and the plot of the current iterations. See the following picture: image

There are edge cases where this does not work (e.g. when logging to a file the columns are always printed, even though it is not necessary). I think this is related to the output to stderr/stdout point.

Testing of logging

The logging has not been tested yet. We need to do that, but this seems tricky.

How many loggers should be there?

Currently, there is only one logger, but maybe it makes sense to split the PyVBMC logger into multiple ones.

Maybe there is more to discuss - but those are the major points.

lacerbi commented 2 years ago

Thanks for the comments and the analysis!

Solosneros commented 2 years ago

Thanks for the reply, @lacerbi :)