U
    9%ed                     @   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
 ddddg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   c/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/torch/distributed/elastic/events/api.pyr	      s   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 |S )Nr   )
isinstancer
   strjsonloadsr	   r!   Z	data_dictr   r   r   deserialize1   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   r   EventMetadataValuer   staticmethodr   r(   r   r   r   r   r   r
      s   
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   r1   r2   r3   r4   r   r   r   r   r   >   s
   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   f   s    zRdzvEvent.__str__r    c                 C   s<   t | tr| S t | tr"t| }t|d  |d< tf |S )Nr8   )r#   r   r$   r%   r&   r   r'   r   r   r   r(   i   s    


zRdzvEvent.deserializer)   c                 C   s   t t| S r   r*   r   r   r   r   r   r   s    zRdzvEvent.serialize)r   r   r   r   r$   r,   r-   r   r:   r;   r   r<   r=   r   r0   r   r(   r   r   r   r   r   r   I   s   
)r%   dataclassesr   r   r   enumr   typingr   r   r   __all__r$   r-   floatboolr/   r	   r
   r   r   r   r   r   r   <module>	   s   	!