
    &`iv                     Z    d dl mZmZ d dlmZ d dlmZ e G d de                      ZdS )    )CallableDict)Stopper)	PublicAPIc                   T    e Zd ZdZdeeegef         fdZd Z	d Z
ed             ZdS )FunctionStoppera}  Provide a custom function to check if trial should be stopped.

    The passed function will be called after each iteration. If it returns
    True, the trial will be stopped.

    Args:
        function: Function that checks if a trial
            should be stopped. Must accept the `trial_id` string  and `result`
            dictionary as arguments. Must return a boolean.

    functionc                     || _         d S N_fn)selfr	   s     u/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/tune/stopper/function_stopper.py__init__zFunctionStopper.__init__   s        c                 .    |                      ||          S r   r   )r   trial_idresults      r   __call__zFunctionStopper.__call__   s    xx&)))r   c                     dS )NF )r   s    r   stop_allzFunctionStopper.stop_all   s    ur   c                     t          |          o"t          t          |          t                     }|rt	          |d          rt          d          |S )Nr   zGStop object must be ray.tune.Stopper subclass to be detected correctly.)callable
issubclasstyper   hasattr
ValueError)clsfnis_functions      r   is_valid_functionz!FunctionStopper.is_valid_function   s]    rllH:d2hh+H+H'H 	72z22 	   r   N)__name__
__module____qualname____doc__r   strr   boolr   r   r   classmethodr"   r   r   r   r   r      s        
 
3+t*;!<    * * *     [  r   r   N)typingr   r   ray.tune.stopper.stopperr   ray.util.annotationsr   r   r   r   r   <module>r-      s    ! ! ! ! ! ! ! ! , , , , , , * * * * * *     g     r   