a
    h                     @   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   R/var/www/auris/lib/python3.9/site-packages/torch/distributed/elastic/events/api.pyr      s   r   c                   @   sz   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eed f d d
ddZed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   |   S N	serializeselfr   r   r   __str__/   s    zEvent.__str__datareturnc                 C   s@   t | tr| S t | tr"t| }t|d  |d< tf i |S )Nr   )
isinstancer	   strjsonloadsr   r    Z	data_dictr   r   r   deserialize2   s    


zEvent.deserializer!   c                 C   s   t t| S r   r$   dumpsr   r   r   r   r   r   ;   s    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   r0   r1   r2   r3   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eed f d dddZed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   s   |   S r   r   r   r   r   r   r   e   s    zRdzvEvent.__str__r   c                 C   s@   t | tr| S t | tr"t| }t|d  |d< tf i |S )Nr7   )r"   r   r#   r$   r%   r
   r&   r   r   r   r'   h   s    


zRdzvEvent.deserializer(   c                 C   s   t t| S r   r)   r   r   r   r   r   q   s    zRdzvEvent.serialize)r   r   r   r   r#   r+   r,   r
   r9   r:   r   r;   r<   r   r/   r   r'   r   r   r   r   r   r   H   s   
r   )r$   Zdataclassesr   r   r   enumr   typingr   r   __all__r#   r,   floatboolr.   r   r	   r
   r   r   r   r   r   <module>
   s   "	