o
    $i?                     @   s   d dl Z d dlZd dlZd dlmZ d dlmZmZ d dlm	Z	 d dl
mZ eeZe	G dd de jZe	G dd	 d	e jZdS )
    N)cloudpickle)binary_to_hexhex_to_binary)DeveloperAPI)log_oncec                       s$   e Zd Z fddZdd Z  ZS )TuneFunctionEncoderc                    sb   t |tjr| |S z	tt| |W S  ty0   tdt	| r)t
d | | Y S w )Nztune_func_encode:z.Unable to encode. Falling back to cloudpickle.)
isinstancetypesFunctionType_to_cloudpicklesuperr   default	Exceptionr   strloggerdebugselfobj	__class__ Y/home/ubuntu/veenaModal/venv/lib/python3.10/site-packages/ray/tune/utils/serialization.pyr      s   

zTuneFunctionEncoder.defaultc                 C   s   dt t|dS )NCLOUDPICKLE_FALLBACK)_typevalue)r   r   dumpsr   r   r   r   r      s   z#TuneFunctionEncoder._to_cloudpickle)__name__
__module____qualname__r   r   __classcell__r   r   r   r   r      s    
r   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )TuneFunctionDecoderc                 O   s$   t jj| g|R d| ji| d S )Nobject_hook)jsonJSONDecoder__init__r"   )r   argskwargsr   r   r   r%   "   s   $zTuneFunctionDecoder.__init__c                 C   s   | ddkr| |S |S )Nr   r   )get_from_cloudpickler   r   r   r   r"   %   s   
zTuneFunctionDecoder.object_hookc                 C   s   t t|d S )Nr   )r   loadsr   r   r   r   r   r)   *   s   z%TuneFunctionDecoder._from_cloudpickleN)r   r   r   r%   r"   r)   r   r   r   r   r!       s    r!   )r#   loggingr	   rayr   ray._common.utilsr   r   ray.util.annotationsr   ray.util.debugr   	getLoggerr   r   JSONEncoderr   r$   r!   r   r   r   r   <module>   s    
