
    &`i	                         d dl mZ d dlmZmZ d dlmZ d dlmZm	Z	 d dl
mZ d dlmZ d dlmZ e G d d	e                      Z eej        e           d
S )    )Any)AgentConnectorConnectorContext)register_connector)NoPreprocessorget_preprocessor)SampleBatch)OldAPIStack)AgentConnectorDataTypec                   d     e Zd ZdZdef fdZd ZdedefdZd Z	e
ded	efd
            Z xZS )ObsPreprocessorConnectora  A connector that wraps around existing RLlib observation preprocessors.

    This includes:
    - OneHotPreprocessor for Discrete and Multi-Discrete spaces.
    - GenericPixelPreprocessor and AtariRamPreprocessor for Atari spaces.
    - TupleFlatteningPreprocessor and DictFlatteningPreprocessor for flattening
      arbitrary nested input observations.
    - RepeatedValuesPreprocessor for padding observations from RLlib Repeated
      observation space.
    ctxc                 
   t                                          |           t          |j        d          r|j        j        }n|j        } t          |          ||j                            di                     | _        d S )Noriginal_spacemodel)	super__init__hasattrobservation_spacer   r   configget_preprocessor)selfr   	obs_space	__class__s      z/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/rllib/connectors/agent/obs_preproc.pyr   z!ObsPreprocessorConnector.__init__   s    3(*:;; 	. -<II-I8-i88sz~~gr22
 
    c                 6    t          | j        t                    S )zDReturns whether this preprocessor connector is a no-op preprocessor.)
isinstancer   r   r   s    r   is_identityz$ObsPreprocessorConnector.is_identity)   s    $,n===r   ac_datareturnc                    |j         }t          |          t          u s*J d                    t          |                                t          j        |v r7| j                            |t          j                           |t          j        <   t          j        |v r7| j                            |t          j                           |t          j        <   |S )NzOSingle agent data must be of type Dict[str, TensorStructType] but is of type {})	datatypedictformatr	   OBSr   	transformNEXT_OBS)r   r"   ds      r   r*   z"ObsPreprocessorConnector.transform-   s    LAww$fT!WWoo 
 ?a!%!3!=!=a>P!Q!QAko1$$&*&8&B&B+&'' 'Ak"# r   c                     t           j        d fS N)r   __name__r    s    r   to_statez!ObsPreprocessorConnector.to_state=   s    '0$66r   paramsc                      t          |           S r.   )r   )r   r1   s     r   
from_statez#ObsPreprocessorConnector.from_state@   s    ',,,r   )r/   
__module____qualname____doc__r   r   r!   r   r*   r0   staticmethodr   r3   __classcell__)r   s   @r   r   r      s        	 	
, 
 
 
 
 
 
> > >!7 <R     7 7 7 -( -# - - - \- - - - -r   r   N)typingr   ray.rllib.connectors.connectorr   r   ray.rllib.connectors.registryr   ray.rllib.models.preprocessorsr   r   ray.rllib.policy.sample_batchr	   ray.rllib.utils.annotationsr
   ray.rllib.utils.typingr   r   r/    r   r   <module>rA      s                 = < < < < < K K K K K K K K 5 5 5 5 5 5 3 3 3 3 3 3 9 9 9 9 9 9 3- 3- 3- 3- 3-~ 3- 3- 3-l  +46N O O O O Or   