o
    wOi                     @   s   d dl Z d dlmZ d dlmZ dedefddZ	dd	ed
ededede	dee fddZ
	dd
ededede	ddf
ddZdS )    N)	timedelta)Listprefixsizec                 C   s2   g }t |D ]}| | | }|| q|S )a  
    Given a store and a prefix, the method goes through the array of keys
    of the following format: ``{prefix}{idx}``, where idx is in a range
    from 0 to size, and tries to retrieve the data.

    Usage

    ::

     values = get_all(store, 'torchelastic/data', 3)
     value1 = values[0] # retrieves the data for key torchelastic/data0
     value2 = values[1] # retrieves the data for key torchelastic/data1
     value3 = values[2] # retrieves the data for key torchelastic/data2

    )rangegetappend)storer   r   data_arridxdata r   L/home/ubuntu/.local/lib/python3.10/site-packages/torchelastic/utils/store.pyget_all   s
   r   ,  r   rank
world_size
key_prefixbarrier_timeoutreturnc                 C   s@   t dt | t|d | | | | t| ||}|S )a  
    Synchronizes ``world_size`` agents between each other using the underlying c10d store.
    The ``data`` will be available on each of the agents.

    Note: The data on the path is not deleted, as a result there can be stale data if
        you use the same key_prefix twice.
    :This is an experimental API and will be changed in future.)seconds)warningswarnFutureWarningset_timeoutr   setr   )r	   r   r   r   r   r   
agent_datar   r   r   synchronize%   s   r   c                 C   s0   t dt | jdd}t| ||||| dS )z
    A global lock between agents.

    Note: Since the data is not removed from the store, the barrier can be used
        once per unique ``key_prefix``.
    r   zUTF-8)encodingN)r   r   r   encoder   )r	   r   r   r   r   r   r   r   r   barrier=   s
   	r!   )r   )r   datetimer   typingr   strintr   bytesfloatr   r!   r   r   r   r   <module>   s<   
