
    &`i<              
       F   d dl Z d dlmZ d dlmZ d dlmZmZmZm	Z	m
Z
mZ d dlZd dlmZ d dlmZmZmZ d dlmZ d dlmZ d d	lmZmZmZmZ d d
lmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z& d dl'm(Z(m)Z)m*Z*m+Z+m,Z, d dl-m.Z.m/Z/m0Z0 d dl1m2Z2m3Z3 edd            Z4e	 dde	e         de5deee
f         fd            Z6ed dee7ef         dee7ef         fd            Z8ed!dee7ef         dee7ef         fd            Z9e G d de j:                              Z; ee6d          Z<g dZ=dS )"    N)deque)partial)AnyDictListOptionalTupleUnion)deprecation_warning)DeveloperAPI	PublicAPIoverride)Filter)FilterManager)try_import_jaxtry_import_tftry_import_tfptry_import_torch)
LARGE_INTEGERMAX_LOG_NN_OUTPUTMIN_LOG_NN_OUTPUTSMALL_NUMBERfclstmone_hotrelusigmoidsoftmax)ConstantScheduleExponentialScheduleLinearSchedulePiecewiseSchedulePolynomialSchedule)checkcheck_compute_single_actioncheck_train_results)deep_updatemerge_dictsFc                     t          |pg           }|rI|r" G d d| |                                          }n! G d d|                                |           }|} |I| S )z:Returns a new class with mixins applied in priority order.c                       e Zd ZdS add_mixins.<locals>.new_baseN__name__
__module____qualname__     l/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/rllib/utils/__init__.pynew_baser,   6           r2   r4   c                       e Zd ZdS r+   r-   r1   r2   r3   r4   zadd_mixins.<locals>.new_base;   r5   r2   )listpop)basemixinsreversedr4   s       r3   
add_mixinsr<   -   s     &,BF
  	    4    
    6::<<       Kr2   elementsto_tuplereturnc                     t           }|du rt          }| 
 |            n?t          |           t           t          t          t          fv r ||           n || g          S )a;  
    Makes sure `elements` is returned as a list, whether `elements` is a single
    item, already a list, or a tuple.

    Args:
        elements: The inputs as a single item, a list/tuple/deque of items, or None,
            to be converted to a list/tuple. If None, returns empty list/tuple.
        to_tuple: Whether to use tuple (instead of list).

    Returns:
        The provided item in a list of size 1, or the provided items as a
        list. If `elements` is None, returns an empty list. If `to_tuple` is True,
        returns a tuple instead of a list.
    T)r7   tupletypesetr   )r=   r>   ctors      r3   
force_listrE   C   sm    $ D4  	 >>dC666 T(^^^T8*r2   /nestedc                     i }t          j        |           D ]2\  }}|                    t          t          |                    }|||<   3|S )a   
    Flattens a nested dict into a flat dict with joined keys.

    Note, this is used for better serialization of nested dictionaries
    in `OfflinePreLearner.__call__` when called inside
    `ray.data.Dataset.map_batches`.

    Note, this is used to return a `Dict[str, numpy.ndarray] from the
    `__call__` method which is expected by Ray Data.

    Args:
        nested: A nested dictionary.
        sep: Separator to use when joining keys.

    Returns:
        A flat dictionary where each key is a path of keys in the nested dict.
    )treeflatten_with_pathjoinmapstr)rG   sep	env_stepsflatpathleafkeys          r3   flatten_dictrT   a   sP    & D,V44  
dhhs3~~&&S		Kr2   rP   c                     i }|                                  D ]E\  }}|                    |          }|}|dd         D ]}||vri ||<   ||         }|||d         <   F|S )a  
    Reconstructs a nested dict from a flat dict with joined keys.

    Note, this is used for better deserialization ofr nested dictionaries
    in `Learner.update' calls in which a `ray.data.DataIterator` is used.

    Args:
        flat: A flat dictionary with keys that are paths joined by `sep`.
        sep: The separator used in the flat dictionary keys.

    Returns:
        A nested dictionary.
    N)itemssplit)rP   rN   rG   compound_keyvaluekeyscurrentrS   s           r3   unflatten_dictr]   ~   s     F#zz|| 	" 	"e!!#&&9 	# 	#C'!!!clGG!RMr2   c                   $    e Zd ZdZd Zd Zd ZdS )NullContextManagerzNo-op context managerc                     d S Nr1   selfs    r3   __init__zNullContextManager.__init__       r2   c                     d S ra   r1   rb   s    r3   	__enter__zNullContextManager.__enter__   re   r2   c                     d S ra   r1   )rc   argss     r3   __exit__zNullContextManager.__exit__   re   r2   N)r.   r/   r0   __doc__rd   rg   rj   r1   r2   r3   r_   r_      sG                r2   r_   T)r>   )#r<   r$   r%   r&   r'   r   r   rE   force_tuplerT   r]   r   r(   r   r   r   r   r   r   r   r   r   r   r   r    r   r   r   r!   r   r   r"   r#   r   r   )F)NF)rF   r   )rF   )>
contextlibcollectionsr   	functoolsr   typingr   r   r   r   r	   r
   rI   ray._common.deprecationr   ray.rllib.utils.annotationsr   r   r   ray.rllib.utils.filterr   ray.rllib.utils.filter_managerr   ray.rllib.utils.frameworkr   r   r   r   ray.rllib.utils.numpyr   r   r   r   r   r   r   r   r   r   ray.rllib.utils.schedulesr   r    r!   r"   r#   ray.rllib.utils.test_utilsr$   r%   r&   ray.tune.utilsr'   r(   r<   boolrE   rM   rT   r]   AbstractContextManagerr_   rl   __all__r1   r2   r3   <module>r}      s_                   : : : : : : : : : : : : : : : :  7 7 7 7 7 7 I I I I I I I I I I ) ) ) ) ) ) 8 8 8 8 8 8                                                        
 4 3 3 3 3 3 3 3    * 5: sm.2
4;   :  c3h $sCx.    8  c3h T#s(^    : 
 
 
 
 
: 
 
 
 gj4000$ $ $r2   