o
    $iv                     @   s@   d dl mZmZ d dlmZ d dlmZ eG dd deZdS )    )CallableDict)Stopper)	PublicAPIc                   @   sF   e Zd ZdZdeeegef fddZdd Z	dd Z
ed	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                 C   s
   || _ d S N_fn)selfr    r   ^/home/ubuntu/veenaModal/venv/lib/python3.10/site-packages/ray/tune/stopper/function_stopper.py__init__   s   
zFunctionStopper.__init__c                 C   s   |  ||S r   r	   )r   trial_idresultr   r   r   __call__   s   zFunctionStopper.__call__c                 C   s   dS )NFr   )r   r   r   r   stop_all   s   zFunctionStopper.stop_allc                 C   s2   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_functionr   r   r   is_valid_function   s   z!FunctionStopper.is_valid_functionN)__name__
__module____qualname____doc__r   strr   boolr   r   r   classmethodr   r   r   r   r   r      s    r   N)typingr   r   ray.tune.stopper.stopperr   ray.util.annotationsr   r   r   r   r   r   <module>   s
    