
    &`i                         d dl Z d dlmZmZ d dlmZ e G d de j                              Ze G d de                      ZdS )    N)AnyDict)	PublicAPIc                   B    e Zd ZdZdedeeef         defdZdefdZ	dS )Stoppera  Base class for implementing a Tune experiment stopper.

    Allows users to implement experiment-level stopping via ``stop_all``. By
    default, this class does not stop any trials. Subclasses need to
    implement ``__call__`` and ``stop_all``.

    Examples:

        >>> import time
        >>> from ray import tune
        >>> from ray.tune import Stopper
        >>>
        >>> class TimeStopper(Stopper):
        ...     def __init__(self):
        ...         self._start = time.time()
        ...         self._deadline = 2  # Stop all trials after 2 seconds
        ...
        ...     def __call__(self, trial_id, result):
        ...         return False
        ...
        ...     def stop_all(self):
        ...         return time.time() - self._start > self._deadline
        ...
        >>> def train_fn(config):
        ...     for i in range(100):
        ...         time.sleep(1)
        ...         tune.report({"iter": i})
        ...
        >>> tuner = tune.Tuner(
        ...     train_fn,
        ...     tune_config=tune.TuneConfig(num_samples=2),
        ...     run_config=tune.RunConfig(stop=TimeStopper()),
        ... )
        >>> print("[ignore]"); result_grid = tuner.fit()  # doctest: +ELLIPSIS
        [ignore]...

    trial_idresultreturnc                     t           )z@Returns true if the trial should be terminated given the result.NotImplementedErrorselfr   r	   s      l/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/tune/stopper/stopper.py__call__zStopper.__call__/       !!    c                     t           )z4Returns true if the experiment should be terminated.r   r   s    r   stop_allzStopper.stop_all3   r   r   N)
__name__
__module____qualname____doc__strr   r   boolr   r    r   r   r   r      sk        $ $L" "d38n " " " " ""$ " " " " " "r   r   c                   N    e Zd ZdZdefdZdedeeef         de	fdZ
de	fdZd	S )
CombinedStoppera  Combine several stoppers via 'OR'.

    Args:
        *stoppers: Stoppers to be combined.

    Examples:

        >>> import numpy as np
        >>> from ray import tune
        >>> from ray.tune.stopper import (
        ...     CombinedStopper,
        ...     MaximumIterationStopper,
        ...     TrialPlateauStopper,
        ... )
        >>>
        >>> stopper = CombinedStopper(
        ...     MaximumIterationStopper(max_iter=10),
        ...     TrialPlateauStopper(metric="my_metric"),
        ... )
        >>> def train_fn(config):
        ...     for i in range(15):
        ...         tune.report({"my_metric": np.random.normal(0, 1 - i / 15)})
        ...
        >>> tuner = tune.Tuner(
        ...     train_fn,
        ...     run_config=tune.RunConfig(stop=stopper),
        ... )
        >>> print("[ignore]"); result_grid = tuner.fit()  # doctest: +ELLIPSIS
        [ignore]...
        >>> all(result.metrics["training_iteration"] <= 20 for result in result_grid)
        True

    stoppersc                     || _         d S N)	_stoppers)r   r    s     r   __init__zCombinedStopper.__init__\   s    !r   r   r	   r
   c                 H    t          fd| j        D                       S )Nc              3   0   K   | ]} |          V  d S r"   r   ).0sr	   r   s     r   	<genexpr>z+CombinedStopper.__call__.<locals>.<genexpr>`   s/      ??111Xv&&??????r   anyr#   r   s    ``r   r   zCombinedStopper.__call___   s,    ???????????r   c                 >    t          d | j        D                       S )Nc              3   >   K   | ]}|                                 V  d S r"   )r   )r'   r(   s     r   r)   z+CombinedStopper.stop_all.<locals>.<genexpr>c   s*      88A1::<<888888r   r*   r   s    r   r   zCombinedStopper.stop_allb   s!    88888888r   N)r   r   r   r   r   r$   r   r   r   r   r   r   r   r   r   r   r   8   s           D"' " " " "@ @d38n @ @ @ @ @9$ 9 9 9 9 9 9r   r   )	abctypingr   r   ray.util.annotationsr   ABCr   r   r   r   r   <module>r2      s    



         * * * * * * -" -" -" -" -"cg -" -" -"` *9 *9 *9 *9 *9g *9 *9 *9 *9 *9r   