ó
    ,Êžjç  ã                  ón   • 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
   " S S5      rg	)
é    )Úannotations)ÚTYPE_CHECKING)Ú
TrialState)Ú	Container)ÚStudy)ÚFrozenTrialc                  óR   • \ rS rSrSr\R                  44     SS jjrSS jrSr	g)	ÚMaxTrialsCallbacké   aº  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.
c                ó   • Xl         X l        g )N©Ú	_n_trialsÚ_states)ÚselfÚn_trialsÚstatess      ÚŸC:\Users\johnn\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\optuna/_callbacks.pyÚ__init__ÚMaxTrialsCallback.__init__5   s   € ð "ŒØ�ó    c                óŽ   • UR                  SU R                  S9n[        U5      nX@R                  :¼  a  UR	                  5         g g )NF)Údeepcopyr   )Ú
get_trialsr   Úlenr   Ústop)r   ÚstudyÚtrialÚtrialsÚ
n_completes        r   Ú__call__ÚMaxTrialsCallback.__call__;   s<   € Ø×!Ñ!¨5¸¿¹Ð!ÐFˆÜ˜“[ˆ
ØŸ™Ó'Ø�J‰J�Lð (r   r   N)r   Úintr   zContainer[TrialState] | NoneÚreturnÚNone)r   r   r   r   r#   r$   )
Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   ÚCOMPLETEr   r    Ú__static_attributes__© r   r   r
   r
      s:   † ñ#ðL FP×EXÑEXÐDZðØðØ%Aðà	õ÷r   r
   N)Ú
__future__r   Útypingr   Úoptuna.trialr   Úcollections.abcr   Úoptuna.studyr   r   r
   r,   r   r   Ú<module>r2      s&   ðÝ "å  å #ö Ý)å"Ý(÷0ò 0r   