o
    c²“iØ	  ã                   @   s€   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	„ d	eƒƒZeejeƒ d
S )é    )ÚAny)ÚAgentConnectorÚConnectorContext)Úregister_connector)Úget_preprocessorÚNoPreprocessor)ÚSampleBatch)ÚAgentConnectorDataType)ÚOldAPIStackc                       s^   e Zd ZdZdef‡ fdd„Zdd„ Zdedefd	d
„Zdd„ Z	e
dedefdd„ƒZ‡  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                    sF   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__© úZ/home/ubuntu/.local/lib/python3.10/site-packages/ray/rllib/connectors/agent/obs_preproc.pyr      s   

ÿz!ObsPreprocessorConnector.__init__c                 C   s   t | jtƒS )zDReturns whether this preprocessor connector is a no-op preprocessor.)Ú
isinstancer   r   ©r   r   r   r   Úis_identity)   s   z$ObsPreprocessorConnector.is_identityÚac_dataÚreturnc                 C   sl   |j }t|ƒtu sJ d t|ƒ¡ƒ‚tj|v r#| j |tj ¡|tj< tj|v r4| 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   Údr   r   r   r&   -   s   
þ


ÿz"ObsPreprocessorConnector.transformc                 C   s
   t jd fS ©N)r   Ú__name__r   r   r   r   Úto_state=   s   
z!ObsPreprocessorConnector.to_stateÚparamsc                 C   s   t | ƒS r)   )r   )r   r,   r   r   r   Ú
from_state@   s   z#ObsPreprocessorConnector.from_state)r*   Ú
__module__Ú__qualname__Ú__doc__r   r   r   r	   r&   r+   Ústaticmethodr   r-   Ú__classcell__r   r   r   r   r      s    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.typingr	   Úray.rllib.utils.annotationsr
   r   r*   r   r   r   r   Ú<module>   s    6