L i ddlmZddlmZddlmZddlmZddlm Z ddlm Z ddl m Z ee ZedGd d Zy ) ) annotations)experimental_class) get_logger)Study)BaseTerminator) Terminator) FrozenTrialz3.2.0c"eZdZdZdddZddZy)TerminatorCallbackaxA 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*|xs t|_yN)r _terminator)self terminators `/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/optuna/terminator/callback.py__init__zTerminatorCallback.__init__As%5c|jj|}|r&tjd|j yy)N)studyz-The study has been stopped by the terminator.)rshould_terminate_loggerinfostop)rrtrialrs r__call__zTerminatorCallback.__call__Ds:++<<5<I  LLH I JJL rr )rzBaseTerminator | NonereturnNone)rrrr rr)__name__ __module__ __qualname____doc__rrrrr r s/b6rr N) __future__roptuna._experimentalroptuna.loggingroptuna.study.studyroptuna.terminator.terminatorrr optuna.trialr rrr r"rrr)sD"3%$73$ X G:::r