py-why / dowhy

DoWhy is a Python library for causal inference that supports explicit modeling and testing of causal assumptions. DoWhy is based on a unified language for causal inference, combining causal graphical models and potential outcomes frameworks.
https://www.pywhy.org/dowhy
MIT License
6.91k stars 921 forks source link

GCM auto assignment now returns a summary object #1049

Closed bloebp closed 8 months ago

bloebp commented 9 months ago

The summary object contains information about the evaluated models and model choices. This object is printable to provide quick summary.

bloebp commented 9 months ago

My recommendation would be to use the global logger directly in functions where you need verbosity, and control the verbosity of the logger instead from the argument. Example that leverages a decorator to modify log level in a function where you need verbosity:

First, I will set the default log level to DEBUG.

@set_log_verbosity
def my_func(arg1, kwarg1=v1, verbosity=False):
     log.info('my verbose message')

Here the set_log_verbosity decorator function will modify the log level to INFO if verbosity is set to True, return the wrapped function, and reset the verbosity to DEBUG again.

The problem is, I want that these messages appear by default and not if a user sets a logger (which 99% of users probably won't). On the other hand, I also don't want to give it out as a print message, i.e., I set the loggign level to info and only add the messages if verbose is true.

Do you have another suggestions where a user does not need to put in additional work to get these insights?

kailashbuki commented 9 months ago

My recommendation would be to use the global logger directly in functions where you need verbosity, and control the verbosity of the logger instead from the argument. Example that leverages a decorator to modify log level in a function where you need verbosity: First, I will set the default log level to DEBUG.

@set_log_verbosity
def my_func(arg1, kwarg1=v1, verbosity=False):
     log.info('my verbose message')

Here the set_log_verbosity decorator function will modify the log level to INFO if verbosity is set to True, return the wrapped function, and reset the verbosity to DEBUG again.

The problem is, I want that these messages appear by default and not if a user sets a logger (which 99% of users probably won't). On the other hand, I also don't want to give it out as a print message, i.e., I set the loggign level to info and only add the messages if verbose is true.

Do you have another suggestions where a user does not need to put in additional work to get these insights?

This is what I mean roughly (there is of course a wiggle room for how to want to parse the verbosity arg):

def set_log_verbosity(func):
    def wrapper(*args, **kwargs):
        if kwargs.get('verbosity', None):
           # change log level to desired level
        res = func(*args, **kwargs)
        if kwargs.get('verbosity', None):
            # reset log level to default level
        return res
    return wrapper
bloebp commented 9 months ago

I revised the logic and the auto assignment now returns a summary object instead which the user can print. This is also helpful to have a more programmatic access to the evaluated models and their performances.