o
    hd                     @   s   d dl Z d dlmZmZmZ d dlmZ d dlmZm	Z	m
Z
 g dZe	eeeedf ZG dd deeZeG dd	 d	ZG d
d deeZeG dd dZdS )    N)asdict	dataclassfield)Enum)DictUnionOptional)EventSourceEvent	NodeState	RdzvEventc                   @   s   e Zd ZdZdZdZdS )r	   z3
    Known identifiers of the event producers.
    AGENTWORKERN)__name__
__module____qualname____doc__r   r    r   r   Z/var/www/html/ai/venv/lib/python3.10/site-packages/torch/distributed/elastic/events/api.pyr	      s    r	   c                   @   s|   e Zd ZU dZeed< eed< dZeed< e	e
dZeeef ed< dd	 Zed
eed f dd fddZdefddZdS )r
   a|  
    The class represents the generic event that occurs during the torchelastic
    job execution. The event can be any kind of meaningful action.

    Args:
        name: event name.
        source: the event producer, e.g. agent or worker
        timestamp: timestamp in milliseconds when event occurred.
        metadata: additional data that is associated with the event.
    namesourcer   	timestamp)default_factorymetadatac                 C      |   S N	serializeselfr   r   r   __str__.      zEvent.__str__datareturnc                 C   @   t | tr| S t | trt| }t|d  |d< tdi |S )Nr   r   )
isinstancer
   strjsonloadsr	   r"   	data_dictr   r   r   deserialize1      


zEvent.deserializec                 C      t t| S r   r'   dumpsr   r   r   r   r   r   :      zEvent.serializeN)r   r   r   r   r&   __annotations__r	   r   intr   dictr   r   EventMetadataValuer    staticmethodr   r+   r   r   r   r   r   r
      s   
 r
   c                   @   s    e Zd ZdZdZdZdZdZdS )r   z6
    The states that a node can be in rendezvous.
    INITRUNNING	SUCCEEDEDFAILEDN)r   r   r   r   r6   r7   r8   r9   r   r   r   r   r   >   s    r   c                   @   s   e Zd ZU dZeed< eed< eed< eed< eed< eed< dZeed	< d
Z	e
e ed< d
Ze
e ed< dZeed< dd Zedeed f dd fddZdefddZd
S )r   a  
    Dataclass to represent any rendezvous event.

    Args:
        name: Event name. (E.g. Current action being performed)
        run_id: The run id of the rendezvous
        message: The message describing the event
        hostname: Hostname of the node
        pid: The process id of the node
        node_state: The state of the node (INIT, RUNNING, SUCCEEDED, FAILED)
        master_endpoint: The master endpoint for the rendezvous store, if known
        rank: The rank of the node, if known
        local_id: The local_id of the node, if defined in dynamic_rendezvous.py
        error_trace: Error stack trace, if this is an error event.
    r   run_idmessagehostnamepid
node_state master_endpointNranklocal_iderror_tracec                 C   r   r   r   r   r   r   r   r    f   r!   zRdzvEvent.__str__r"   r#   c                 C   r$   )Nr>   r   )r%   r   r&   r'   r(   r   r)   r   r   r   r+   i   r,   zRdzvEvent.deserializec                 C   r-   r   r.   r   r   r   r   r   r   r0   zRdzvEvent.serialize)r   r   r   r   r&   r1   r2   r   r@   rA   r   rB   rC   r    r5   r   r+   r   r   r   r   r   r   I   s    
 r   )r'   dataclassesr   r   r   enumr   typingr   r   r   __all__r&   r2   floatboolr4   r	   r
   r   r   r   r   r   r   <module>   s   	!