econ-ark / HARK

Heterogenous Agents Resources & toolKit
Apache License 2.0
331 stars 198 forks source link

Make better / more flexible format for warnings #130

Closed mnwhite closed 3 months ago

mnwhite commented 7 years ago

Since the very first version of HARK, we've had a "monkey patch" to the warnings module to make warnings display in a single line, rather than a big angry chunk of red text (in Spyder). Some recent changes to numpy have increased the number of warnings it throws, for things like dividing by zero or using NaNs basically anywhere. As a bunch of methods in HARK exploit numpy's handling of division by zero (1./0. = np.inf), it's probably a bit worrisome to new users when they see a bunch of "invalid value encountered in divide" messages come up. I would like to turn off these warnings where we know that they're not relevant (because dividing by zero or carrying around some NaNs is our intended functionality), but our current warning format gives no opportunity for traceback.

Our monkey patch needs to evolve into a human patch, roughly speaking. The definition in HARKutilities should be greatly expanded to offer easy options. I'm not sure what's possible, but ideally I would like the option to:

I'm assigning this to Nathan because he wrote the initial warnings patch and knows the most about this.

sbenthall commented 4 years ago

See discussion in #283

There is a standard and flexible logging package in Python. https://docs.python.org/3/howto/logging.html#logging-basic-tutorial

I highly recommend using this standard functionality instead of creating new logging functionality.

sbenthall commented 4 years ago

Responding to this, which may have been meant for this issue: https://github.com/econ-ark/HARK/issues/283#issuecomment-597810736

The warnings controls in Python are managed through this package: https://docs.python.org/3/library/warnings.html

sbenthall commented 4 years ago

I think we are using the Python logging library now. So maybe it's a good time to revisit this?

MridulS commented 4 years ago

Already implemented for ConsIndShockModel, to be extended across HARK.

mnwhite commented 3 months ago

I think this was handled long ago. Warnings about intended HARK behavior are suppressed.