
    -ji
                        S SK Jr  S SKJr  S SKJr  S SKJr  S SKJ	r	  \(       a  S SK
Jr  S SKJr  S SKJr  \" \5      r\" S	5       " S
 S5      5       rg)    )annotations)TYPE_CHECKING)experimental_class)
get_logger)
Terminator)Study)BaseTerminator)FrozenTrialz3.2.0c                  0    \ rS rSrSrSSS jjrS	S jrSrg)
TerminatorCallback   a  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                4    U=(       d
    [        5       U l        g N)r   _terminator)self
terminators     T/home/james-whalen/.local/lib/python3.13/site-packages/optuna/terminator/callback.py__init__TerminatorCallback.__init__F   s    %5    c                    U R                   R                  US9nU(       a&  [        R                  S5        UR	                  5         g g )N)studyz-The study has been stopped by the terminator.)r   should_terminate_loggerinfostop)r   r   trialr   s       r   __call__TerminatorCallback.__call__I   s:    ++<<5<ILLHIJJL r   )r   r   )r   zBaseTerminator | NonereturnNone)r   r   r   r
   r    r!   )__name__
__module____qualname____firstlineno____doc__r   r   __static_attributes__ 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>r0      sL    "   3 % 3 (;( X
 G: : :r   