
    sg                         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ee      Ze G d d	             Z G d
 dee      Ze G d d             Zy)    N)asdict	dataclassfield)Enum)DictOptionalUnion)EventSourceEvent	NodeState	RdzvEventc                       e Zd ZdZdZdZy)r
   z)Known identifiers of the event producers.AGENTWORKERN)__name__
__module____qualname____doc__r   r        W/var/www/html/venv/lib/python3.12/site-packages/torch/distributed/elastic/events/api.pyr
   r
      s    3EFr   r
   c                       e Zd ZU dZeed<   eed<   dZeed<    e	e
      Zeeef   ed<   d Zed	eed f   d
d fd       Zd
efdZy)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                 "    | j                         S N	serializeselfs    r   __str__zEvent.__str__/       ~~r   datareturnc                     t        | t              r| S t        | t              rt        j                  |       }t
        d      |d<   t        di |S )Nr   r   )
isinstancer   strjsonloadsr
   r&   	data_dicts     r   deserializezEvent.deserialize2   sK    dE"KdC 

4(I))H*=>	(!y!!r   c                 >    t        j                  t        |             S r   r+   dumpsr   r"   s    r   r!   zEvent.serialize;       zz&,''r   N)r   r   r   r   r*   __annotations__r
   r   intr   dictr   r   EventMetadataValuer$   staticmethodr	   r/   r!   r   r   r   r   r      st    
 IIs.3D.IHd3**+I  "%W- "' " "(3 (r   r   c                        e Zd ZdZdZdZdZdZy)r   z,The states that a node can be in rendezvous.INITRUNNING	SUCCEEDEDFAILEDN)r   r   r   r   r:   r;   r<   r=   r   r   r   r   r   ?   s    6DGIFr   r   c                       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 Zedeed f   dd fd       ZdefdZy
)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                 "    | j                         S r   r    r"   s    r   r$   zRdzvEvent.__str__e   r%   r   r&   r'   c                     t        | t              r| S t        | t              rt        j                  |       }t
        d      |d<   t        di |S )NrC   r   )r)   r   r*   r+   r,   r   r-   s     r   r/   zRdzvEvent.deserializeh   sK    dI&KdC 

4(I"+Il,C"D	,%9%%r   c                 >    t        j                  t        |             S r   r1   r"   s    r   r!   zRdzvEvent.serializeq   r3   r   )r   r   r   r   r*   r4   r5   r   rE   rF   r   rG   rH   r$   r8   r	   r/   r!   r   r   r   r   r   H   s      IKLM	HOSD(3-"Hhsm"K  &%[ 01 &k & &(3 (r   r   )r+   dataclassesr   r   r   enumr   typingr   r   r	   __all__r*   r5   floatboolr7   r
   r   r   r   r   r   r   <module>rR      s     0 0  ( ( =3UD$67 #t  ( ( (DT  )( )( )(r   