o
    $i                     @   sX   d dl Z d dlZd dlmZ d dlmZ d dlmZ d dlm	Z	 e	G dd deZ
dS )    N)Union)logger)Stopper)	PublicAPIc                   @   sH   e Zd ZdZdeeeejf fddZ	dd Z
dd Zd	efd
dZdS )TimeoutStoppera  Stops all trials after a certain timeout.

    This stopper is automatically created when the `time_budget_s`
    argument is passed to `tune.RunConfig()`.

    Args:
        timeout: Either a number specifying the timeout in seconds, or
            a `datetime.timedelta` object.
    timeoutc                 C   s\   ddl m} t||r| | _nt|ttfr|| _n	tdt	|| j| _
d | _d S )Nr   )	timedeltazY`timeout` parameter has to be either a number or a `datetime.timedelta` object. Found: {})datetimer   
isinstancetotal_seconds_timeout_secondsintfloat
ValueErrorformattype_budget_last_check)selfr   r    r   U/home/ubuntu/veenaModal/venv/lib/python3.10/site-packages/ray/tune/stopper/timeout.py__init__   s   


zTimeoutStopper.__init__c                 C   s   dS )NFr   )r   trial_idresultr   r   r   __call__)   s   zTimeoutStopper.__call__c                 C   sR   t   }| jr|| j }|  j|8  _|| _| jdkr'td| j d dS dS )Nr   zReached timeout of z seconds. Stopping all trials.TF)timer   r   r   infor   )r   nowtakenr   r   r   stop_all,   s   

zTimeoutStopper.stop_allstatec                 C   s   d |d< | j | d S )Nr   )__dict__update)r   r    r   r   r   __setstate__>   s   zTimeoutStopper.__setstate__N)__name__
__module____qualname____doc__r   r   r   r	   r   r   r   r   dictr#   r   r   r   r   r   
   s    
r   )r	   r   typingr   rayr   ray.tune.stopper.stopperr   ray.util.annotationsr   r   r   r   r   r   <module>   s    