
    ,YHh                    d    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y	)
    )annotations)TYPE_CHECKING)
TrialState)	Container)Study)FrozenTrialc                  D    e Zd ZdZej
                  ff	 	 	 	 	 ddZddZy)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.
    c                     || _         || _        y )N)	_n_trials_states)selfn_trialsstatess      J/var/www/html/planif/env/lib/python3.12/site-packages/optuna/_callbacks.py__init__zMaxTrialsCallback.__init__5   s     "    c                    |j                  d| j                        }t        |      }|| j                  k\  r|j	                          y y )NF)deepcopyr   )
get_trialsr   lenr   stop)r   studytrialtrials
n_completes        r   __call__zMaxTrialsCallback.__call__;   s>    !!5!F[
'JJL (r   N)r   intr   zContainer[TrialState] | NonereturnNone)r   r   r   r   r   r    )__name__
__module____qualname____doc__r   COMPLETEr   r    r   r   r
   r
      s:    #L FPEXEXDZ%A	r   r
   N)
__future__r   typingr   optuna.trialr   collections.abcr   optuna.studyr   r   r
   r&   r   r   <module>r,      s&    "   # )"(0 0r   