Ë
    Q‡-jÍ  ã                  óÂ   — 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	 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j&                  d
dd¬«      Z G d„ d«      Zy)é    )Úannotations)ÚTYPE_CHECKING)Ú_DEPRECATION_WARNING_TEMPLATE)Úoptuna_warn)Ú
get_logger)Ú
Terminator)ÚStudy)ÚBaseTerminator)ÚFrozenTrialz`optuna.terminator` modulez4.9.0z6.0.0)ÚnameÚd_verÚr_verc                  ó"   — 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                óR   — t        t        t        «       |xs
 t        «       | _        y ©N)r   Ú_DEPRECATION_WARNING_MESSAGEÚFutureWarningr   Ú_terminator)ÚselfÚ
terminators     úh/Users/jameslopez/projects/TradingBot25/.venv/lib/python3.12/site-packages/optuna/terminator/callback.pyÚ__init__zTerminatorCallback.__init__L   s   € ÜÔ0´-Ô@Ø%Ò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__P   s:   € Ø×+Ñ+×<Ñ<À5Ð<ÓIÐáÜL‰LÐHÔIØJ‰JLð 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._deprecatedr   Úoptuna._warningsr   Úoptuna.loggingr   Úoptuna.terminator.terminatorr   Úoptuna.study.studyr	   r
   Úoptuna.trialr   r%   r   Úformatr   r   r)   r   r   Ú<module>r3      sX   ðÝ "å  å <Ý (Ý %Ý 3ñ Ý(Ý;Ý(ñ XÓ
€àCÐ<×CÑCØ	%Ø
Ø
ô Ð ÷;ò ;r   