o
    c²“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   úU/home/ubuntu/.local/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
    