§
    ìóÉjç  ã                  ól   — 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
  G d„ d¦  «        Zd	S )
é    )Úannotations)ÚTYPE_CHECKING)Ú
TrialState)Ú	Container)ÚStudy)ÚFrozenTrialc                  ó2   — e Zd ZdZej        ffdd„Zdd„ZdS )ÚMaxTrialsCallbacka"  Set a maximum number of trials before ending the study.

    While the ``n_trials`` argument of :meth:`optuna.study.Study.optimize` sets the number of
    trials that will be run, you may want to continue running until you have a certain number of
    successfully completed trials or stop the study when you have a certain number of trials that
    fail. This ``MaxTrialsCallback`` class allows you to set a maximum number of trials for a
    particular :class:`~optuna.trial.TrialState` before stopping the study.

    Example:

        .. testcode::

            import optuna
            from optuna.study import MaxTrialsCallback
            from optuna.trial import TrialState


            def objective(trial):
                x = trial.suggest_float("x", -1, 1)
                return x**2


            study = optuna.create_study()
            study.optimize(
                objective,
                callbacks=[MaxTrialsCallback(10, states=(TrialState.COMPLETE,))],
            )

    Args:
        n_trials:
            The max number of trials. Must be set to an integer.
        states:
            Tuple of the :class:`~optuna.trial.TrialState` to be counted
            towards the max trials limit. Default value is ``(TrialState.COMPLETE,)``.
            If :obj:`None`, count all states.
    Ún_trialsÚintÚstatesúContainer[TrialState] | NoneÚreturnÚNonec                ó"   — || _         || _        d S )N)Ú	_n_trialsÚ_states)Úselfr   r   s      út/home/lighthouse/badge-speaker-benchmark/.benchmark-venv-community/lib/python3.11/site-packages/optuna/_callbacks.pyÚ__init__zMaxTrialsCallback.__init__5   s   € ð "ˆŒØˆŒˆˆó    Ústudyr   Útrialr   c                óž   — |                      d| j        ¬¦  «        }t          |¦  «        }|| j        k    r|                     ¦   «          d S d S )NF)Údeepcopyr   )Ú
get_trialsr   Úlenr   Ústop)r   r   r   ÚtrialsÚ
n_completes        r   Ú__call__zMaxTrialsCallback.__call__;   sM   € Ø×!Ò!¨5¸¼Ð!ÑFÔFˆÝ˜‘[”[ˆ
Ø˜œÒ'Ð'Ø�JŠJ‰LŒLˆLˆLˆLð (Ð'r   N)r   r   r   r   r   r   )r   r   r   r   r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚCOMPLETEr   r!   © r   r   r
   r
      sY   € € € € € ð#ð #ðL FPÔEXÐDZðð ð ð ð ðð ð ð ð ð r   r
   N)Ú
__future__r   Útypingr   Úoptuna.trialr   Úcollections.abcr   Úoptuna.studyr   r   r
   r'   r   r   ú<module>r-      s­   ðØ "Ð "Ð "Ð "Ð "Ð "à  Ð  Ð  Ð  Ð  Ð  à #Ð #Ð #Ð #Ð #Ð #ð ð )Ø)Ð)Ð)Ð)Ð)Ð)à"Ð"Ð"Ð"Ð"Ð"Ø(Ð(Ð(Ð(Ð(Ð(ð0ð 0ð 0ð 0ð 0ñ 0ô 0ð 0ð 0ð 0r   