Project-Platypus / Platypus

A Free and Open Source Python Library for Multiobjective Optimization
GNU General Public License v3.0
553 stars 152 forks source link

Usage of LOGGER #216

Closed fabmid closed 9 months ago

fabmid commented 9 months ago

Hi, I would like to use the LOGGER in platypus but could not find any example of how to print logger messages or even save it to any log file.

Looking at the source code, there is a LOGGER called platypus initialized in core.py and evaluator.py, but I could not make it work. I set the log_frequency parameter from the Algorithm parent class to 1, but I can not see any logger output. The simple example adapted:

from platypus import NSGAII, DTLZ2
from platypus import LOGGER

# define the problem definition
problem = DTLZ2()

# instantiate the optimization algorithm
algorithm = NSGAII(problem,
                   population_size=10,
                   log_frequency=1)

# optimize the problem using 10,000 function evaluations
algorithm.run(10000)

I very appreciate any help on this! Thanks

dhadka commented 9 months ago

Please try putting this near the top of your file:

import logging

logging.basicConfig(level=logging.DEBUG)

Basically, by default the logger doesn't print informational lines. So we have to lower the level first.

https://docs.python.org/3/howto/logging.html has a bit more info if you want to redirect logs to a file, etc.

fabmid commented 9 months ago

Thanks a lot, this solved my Issue!