o
    Zh                     @   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	 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)OptionalUnion)EventSourceEvent	NodeState	RdzvEventc                   @   s   e Zd ZdZdZdZdS )r   z)Known identifiers of the event producers.AGENTWORKERN)__name__
__module____qualname____doc__r   r    r   r   S/var/www/auris/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!   Z	data_dictr   r   r   deserialize2      


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   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
   z,The states that a node can be in rendezvous.INITRUNNING	SUCCEEDEDFAILEDN)r   r   r   r   r4   r5   r6   r7   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   Zrun_idmessagehostnamepid
node_state master_endpointNranklocal_iderror_tracec                 C   r   r   r   r   r   r   r   r   e   r    zRdzvEvent.__str__r!   r"   c                 C   r#   )Nr;   r   )r$   r   r%   r&   r'   r
   r(   r   r   r   r)   h   r*   zRdzvEvent.deserializec                 C   r+   r   r,   r   r   r   r   r   q   r.   zRdzvEvent.serialize)r   r   r   r   r%   r/   r0   r
   r=   r>   r   r?   r@   r   r3   r   r)   r   r   r   r   r   r   H   s    
 r   )r&   dataclassesr   r   r   enumr   typingr   r   __all__r%   r0   floatboolr2   r   r	   r
   r   r   r   r   r   <module>   s   	"	