U
    d&                     @   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
 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Optionalc                   @   s   e Zd ZdZdZdZdS )EventSourcez3
    Known identifiers of the event producers.
    AGENTWORKERN)__name__
__module____qualname____doc__r
   r    r   r   H/tmp/pip-unpacked-wheel-ua33x9lu/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 )Eventa{  
    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 occured.
        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 |S )Nr   )
isinstancer   strjsonloadsr	   r   Z	data_dictr   r   r   deserialize0   s    


zEvent.deserializer    c                 C   s   t t| S r   r#   dumpsr   r   r   r   r   r   9   s    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 )	NodeStatez6
    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 )	RdzvEventa  
    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 |S )Nr8   )r!   r4   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/   r:   r;   r   r<   r=   r   r.   r   r&   r   r   r   r   r   r4   H   s   
r4   )r#   Zdataclassesr   r   r   enumr   typingr   r   r   r"   r+   floatboolr-   r	   r   r/   r4   r   r   r   r   <module>	   s   	!