Ë
    ÿÿæiâ
  ã                  ó¢   — d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	 erd dl
mZ d dlmZ d dlmZ  ee«      Z ed	«       G d
„ d«      «       Zy)é    )Úannotations)ÚTYPE_CHECKING)Úexperimental_class)Ú
get_logger)Ú
Terminator)ÚStudy)ÚBaseTerminator)ÚFrozenTrialz3.2.0c                  ó"   — e Zd ZdZddd„Zdd„Zy)ÚTerminatorCallbackax  A callback that terminates the optimization using Terminator.

    This class implements a callback which wraps :class:`~optuna.terminator.Terminator`
    so that it can be used with the :func:`~optuna.study.Study.optimize` method.

    Args:
        terminator:
            A terminator object which determines whether to terminate the optimization by
            assessing the room for optimization and statistical error. Defaults to a
            :class:`~optuna.terminator.Terminator` object with default
            ``improvement_evaluator`` and ``error_evaluator``.

    Example:

        .. testcode::

            from sklearn.datasets import load_wine
            from sklearn.ensemble import RandomForestClassifier
            from sklearn.model_selection import cross_val_score
            from sklearn.model_selection import KFold

            import optuna
            from optuna.terminator import TerminatorCallback
            from optuna.terminator import report_cross_validation_scores


            def objective(trial):
                X, y = load_wine(return_X_y=True)

                clf = RandomForestClassifier(
                    max_depth=trial.suggest_int("max_depth", 2, 32),
                    min_samples_split=trial.suggest_float("min_samples_split", 0, 1),
                    criterion=trial.suggest_categorical("criterion", ("gini", "entropy")),
                )

                scores = cross_val_score(clf, X, y, cv=KFold(n_splits=5, shuffle=True))
                report_cross_validation_scores(trial, scores)
                return scores.mean()


            study = optuna.create_study(direction="maximize")
            terminator = TerminatorCallback()
            study.optimize(objective, n_trials=50, callbacks=[terminator])

    .. seealso::
        Please refer to :class:`~optuna.terminator.Terminator` for the details of
        the terminator mechanism.
    Nc                ó*   — |xs
 t        «       | _        y ©N)r   Ú_terminator)ÚselfÚ
terminators     úo/Volumes/fast/ai/experiments/voice-extract-mac/.venv/lib/python3.12/site-packages/optuna/terminator/callback.pyÚ__init__zTerminatorCallback.__init__F   s   € Ø%Ò5¬«ˆÕó    c                óŒ   — | j                   j                  |¬«      }|r&t        j                  d«       |j	                  «        y y )N)Ústudyz-The study has been stopped by the terminator.)r   Úshould_terminateÚ_loggerÚinfoÚstop)r   r   Útrialr   s       r   Ú__call__zTerminatorCallback.__call__I   s:   € Ø×+Ñ+×<Ñ<À5Ð<ÓIÐáÜ�L‰LÐHÔIØ�J‰J�Lð r   r   )r   zBaseTerminator | NoneÚreturnÚNone)r   r   r   r
   r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   © r   r   r   r      s   „ ñ/ôb6ôr   r   N)Ú
__future__r   Útypingr   Úoptuna._experimentalr   Úoptuna.loggingr   Úoptuna.terminator.terminatorr   Úoptuna.study.studyr   r	   Úoptuna.trialr
   r   r   r   r#   r   r   Ú<module>r+      sL   ðÝ "å  å 3Ý %Ý 3ñ Ý(Ý;Ý(ñ �XÓ
€ñ �GÓ÷:ð :ó ñ:r   