o �J�h�(�@s4UddlmZddlZddlmZddlmZddlmZddlmZddlmZddlmZdd lm Z ddl Z ddl Z ddl Z ddl Z gd �Ze ��Zd ed <dad ed<d2dd�Zd3dd�Zd4dd�Zd5dd�Zd6dd�Zd6dd �Zd7d"d#�Zd8d%d&�Zd9d(d)�Zd6d*d+�Zd6d,d-�Zd6d.d/�Zd6d0d1�ZdS):�)� annotationsN)�CRITICAL)�DEBUG)�ERROR)�FATAL)�INFO)�WARN)�WARNING)rrrrrrr zthreading.Lock�_lockzlogging.Handler | None�_default_handler�return�logging.FormattercCs8d}d}t�rt�d|�d|���St�|�d|���S)z}Create a default formatter of log messages. This function is not supposed to be directly accessed by library users. z[%(levelname)1.1s %(asctime)s]z %(message)sz %(log_color)sz %(reset)s � )�_color_supported�colorlogZColoredFormatter�logging� Formatter)�header�message�r�LC:\pinokio\api\whisper-webui.git\app\env\lib\site-packages\optuna\logging.py�create_default_formatter s�r�boolcCs0tj�dd�r dSttjd�rtj��sdSdS)zDetection of color support.�NO_COLORNF�isattyT)�os�environ�get�hasattr�sys�stderrrrrrrr.s r�strcCst�d�dS)N�.r)�__name__�splitrrrr�_get_library_name:sr%�logging.LoggercCs t�t��S�N)r� getLoggerr%rrrr�_get_library_root_logger>s r)�NonecCsvt�/tr Wd�dSt��at�t��t�}|�t�|�tj �d|_ Wd�dS1s4wYdS)NF) r r r� StreamHandler� setFormatterrr)� addHandler�setLevelr� propagate��library_root_loggerrrr�_configure_library_root_loggerBs�   "�r2cCs`t�$ts Wd�dSt�}|�t�|�tj�daWd�dS1s)wYdSr')r r r)� removeHandlerr.r�NOTSETr0rrr�_reset_library_root_loggerSs�  "�r5�namecCst�t�|�S)zzReturn a logger with the specified name. This function is not supposed to be directly accessed by library users. )r2rr()r6rrr� get_logger`s r7�intcCst�t���S)a�Return the current level for the Optuna's root logger. Example: Get the default verbosity level. .. testsetup:: def objective(trial): x = trial.suggest_float("x", -100, 100) y = trial.suggest_categorical("y", [-1, 0, 1]) return x**2 + y .. testcode:: import optuna # The default verbosity level of Optuna is `optuna.logging.INFO`. print(optuna.logging.get_verbosity()) # 20 print(optuna.logging.INFO) # 20 # There are logs of the INFO level. study = optuna.create_study() study.optimize(objective, n_trials=5) # [I 2021-10-31 05:35:17,232] A new study created ... # [I 2021-10-31 05:35:17,238] Trial 0 finished with value: ... # [I 2021-10-31 05:35:17,245] Trial 1 finished with value: ... # ... .. testoutput:: :hide: 20 20 Returns: Logging level, e.g., ``optuna.logging.DEBUG`` and ``optuna.logging.INFO``. .. note:: Optuna has following logging levels: - ``optuna.logging.CRITICAL``, ``optuna.logging.FATAL`` - ``optuna.logging.ERROR`` - ``optuna.logging.WARNING``, ``optuna.logging.WARN`` - ``optuna.logging.INFO`` - ``optuna.logging.DEBUG`` )r2r)�getEffectiveLevelrrrr� get_verbosityjs2 r:� verbositycCst�t��|�dS)aaSet the level for the Optuna's root logger. Example: Set the logging level ``optuna.logging.WARNING``. .. testsetup:: def objective(trial): x = trial.suggest_int("x", -10, 10) return x**2 .. testcode:: import optuna # There are INFO level logs. study = optuna.create_study() study.optimize(objective, n_trials=10) # [I 2021-10-31 02:59:35,088] Trial 0 finished with value: 16.0 ... # [I 2021-10-31 02:59:35,091] Trial 1 finished with value: 1.0 ... # [I 2021-10-31 02:59:35,096] Trial 2 finished with value: 1.0 ... # Setting the logging level WARNING, the INFO logs are suppressed. optuna.logging.set_verbosity(optuna.logging.WARNING) study.optimize(objective, n_trials=10) .. testcleanup:: optuna.logging.set_verbosity(optuna.logging.INFO) Args: verbosity: Logging level, e.g., ``optuna.logging.DEBUG`` and ``optuna.logging.INFO``. .. note:: Optuna has following logging levels: - ``optuna.logging.CRITICAL``, ``optuna.logging.FATAL`` - ``optuna.logging.ERROR`` - ``optuna.logging.WARNING``, ``optuna.logging.WARN`` - ``optuna.logging.INFO`` - ``optuna.logging.DEBUG`` N)r2r)r.)r;rrr� set_verbosity�s/r<cC�"t�tdus J�t��t�dS)a�Disable the default handler of the Optuna's root logger. Example: Stop and then resume logging to :obj:`sys.stderr`. .. testsetup:: def objective(trial): x = trial.suggest_float("x", -100, 100) y = trial.suggest_categorical("y", [-1, 0, 1]) return x**2 + y .. testcode:: import optuna study = optuna.create_study() # There are no logs in sys.stderr. optuna.logging.disable_default_handler() study.optimize(objective, n_trials=10) # There are logs in sys.stderr. optuna.logging.enable_default_handler() study.optimize(objective, n_trials=10) # [I 2020-02-23 17:00:54,314] Trial 10 finished with value: ... # [I 2020-02-23 17:00:54,356] Trial 11 finished with value: ... # ... N)r2r r)r3rrrr�disable_default_handler�s! r>cCr=)z�Enable the default handler of the Optuna's root logger. Please refer to the example shown in :func:`~optuna.logging.disable_default_handler()`. N)r2r r)r-rrrr�enable_default_handler�s r?cC�t�dt�_dS)a�Disable propagation of the library log outputs. Note that log propagation is disabled by default. You only need to use this function to stop log propagation when you use :func:`~optuna.logging.enable_propagation()`. Example: Stop propagating logs to the root logger on the second optimize call. .. testsetup:: def objective(trial): x = trial.suggest_float("x", -100, 100) y = trial.suggest_categorical("y", [-1, 0, 1]) return x**2 + y .. testcode:: import optuna import logging optuna.logging.disable_default_handler() # Disable the default handler. logger = logging.getLogger() logger.setLevel(logging.INFO) # Setup the root logger. logger.addHandler(logging.FileHandler("foo.log", mode="w")) optuna.logging.enable_propagation() # Propagate logs to the root logger. study = optuna.create_study() logger.info("Logs from first optimize call") # The logs are saved in the logs file. study.optimize(objective, n_trials=10) optuna.logging.disable_propagation() # Stop propogating logs to the root logger. logger.info("Logs from second optimize call") # The new logs for second optimize call are not saved. study.optimize(objective, n_trials=10) with open("foo.log") as f: assert f.readline().startswith("A new study created") assert f.readline() == "Logs from first optimize call\n" # Check for logs after second optimize call. assert f.read().split("Logs from second optimize call\n")[-1] == "" FN�r2r)r/rrrr�disable_propagations1 rBcCr@)a�Enable propagation of the library log outputs. Please disable the Optuna's default handler to prevent double logging if the root logger has been configured. Example: Propagate all log output to the root logger in order to save them to the file. .. testsetup:: def objective(trial): x = trial.suggest_float("x", -100, 100) y = trial.suggest_categorical("y", [-1, 0, 1]) return x**2 + y .. testcode:: import optuna import logging logger = logging.getLogger() logger.setLevel(logging.INFO) # Setup the root logger. logger.addHandler(logging.FileHandler("foo.log", mode="w")) optuna.logging.enable_propagation() # Propagate logs to the root logger. optuna.logging.disable_default_handler() # Stop showing logs in sys.stderr. study = optuna.create_study() logger.info("Start optimization.") study.optimize(objective, n_trials=10) with open("foo.log") as f: assert f.readline().startswith("A new study created") assert f.readline() == "Start optimization.\n" TNrArrrr�enable_propagation;s) rC)r r )r r)r r!)r r&)r r*)r6r!r r&)r r8)r;r8r r*) � __future__rrrrrrrrr rr� threadingr�__all__�Lockr �__annotations__r rrr%r)r2r5r7r:r<r>r?rBrCrrrr�<module>s:              6 3 ' 5
Memory