
    &`i                      T   d Z ddlZddlmZ ddlmZmZmZmZ ddl	Z	ddl
Z
ddlmZ ddlmZ ed             Z G d d          Ze G d	 d
                      Zd Zd Ze	 	 	 ddedee         dedee         deeee         f         f
d            Zdeeee         f         fdZdS )z-A utility for debugging serialization issues.    N)contextmanager)AnyOptionalSetTuple)DeveloperAPIc              #   R   K   | xj         dz  c_         d V  | xj         dz  c_         d S )N   )level)printers    l/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/util/check_serialize.py_indentr      s3      MMQMM	EEEMMQMMMM    c                        e Zd Zd Zd Zd ZdS )_Printerc                 "    d| _         || _        d S )Nr   )r   
print_file)selfr   s     r   __init__z_Printer.__init__   s    
$r   c                      t          |           S N)r   r   s    r   indentz_Printer.indent   s    t}}r   c                 L    d| j         z  }t          ||z   | j                   d S )Nz    )file)r   printr   )r   msgr   s      r   r   z_Printer.print   s-    $*$fsl111111r   N)__name__
__module____qualname__r   r   r    r   r   r   r      sA        % % %  2 2 2 2 2r   r   c                   ,    e Zd ZdZdededefdZd ZdS )FailureTuplezRepresents the serialization 'frame'.

    Attributes:
        obj: The object that fails serialization.
        name: The variable name of the object.
        parent: The object that references the `obj`.
    objnameparentc                 0    || _         || _        || _        d S r   )r$   r%   r&   )r   r$   r%   r&   s       r   r   zFailureTuple.__init__,   s    	r   c                 8    d| j          d| j         d| j         dS )Nz
FailTuple(z [obj=z	, parent=z]))r%   r$   r&   r   s    r   __repr__zFailureTuple.__repr__1   s)    ODIOOTXOOOOOOr   N)r   r   r    __doc__r   strr   r)   r!   r   r   r#   r#   "   s[         C s C    
P P P P Pr   r#   c           
         t          j        |           sJ t          j        |           }d}|j        r|                    dt          |j                   d           |                                5  |j                                        D ])\  }}t          |||dz
  |||          \  }	}
|p|	 }|r n*ddd           n# 1 swxY w Y   |j	        r|                    dt          |j	                   d           |                                5  |j	                                        D ])\  }}t          |||dz
  |||          \  }	}
|p|	 }|r n*ddd           n# 1 swxY w Y   |s|                    d|  d	           |S )
AAdds the first-found non-serializable element to the failure_set.Fz	Detected z. global variables. Checking serializability...r
   r%   depthr&   failure_setr   Nz0 nonlocal variables. Checking serializability...1WARNING: Did not find non-serializable object in . This may be an oversight.)
inspect
isfunctiongetclosurevarsglobalsr   lenr   items_inspect_serializability	nonlocals)base_objr/   r&   r0   r   closurefoundr%   r$   serializable_s              r   _inspect_func_serializationr@   5   s   h'''''$X..GE *GO,, * * *	
 	
 	

 ^^ 	 	$_2244  	c":!)! +## # #a 1\!1 E	 	 	 	 	 	 	 	 	 	 	 	 	 	 	  *G-.. * * *	
 	
 	
 ^^ 	 	$.4466  	c":!)! +## # #a 1\!1 E	 	 	 	 	 	 	 	 	 	 	 	 	 	 	  
( ( ( (	
 	
 	
 Ls&   3ACC
CAE$$E(+E(c           
         t          j        |           rJ t          j        | t           j                  }d}|                                5  |D ])\  }}t	          |||dz
  |||          \  }	}
|p|	 }|r n*ddd           n# 1 swxY w Y   |                                5  t          j        |           }|D ]h\  }}|                    d          r|                    d          st          j        |          rDt	          |||dz
  |||          \  }	}
|p|	 }|r niddd           n# 1 swxY w Y   |s|                    d|  d           |S )	r-   )	predicateFr
   r.   N__r1   r2   )	r3   r4   
getmembersr   r9   
startswithendswith	isbuiltinr   )r;   r/   r&   r0   r   	functionsr=   r%   r$   r>   r?   memberss               r   _inspect_generic_serializationrJ   h   sP   !(+++++"8w7IJJJIE			  " 	 	ID#6ai'  OL! --E                
		  $X..  	 	ID#t$$ t)<)< @QRU@V@V 6ai'  OL! --E                  
( ( ( (	
 	
 	
 Ls%   -BB
B
%B D11D58D5   r;   r%   r/   r   returnc                 H    t          |          }t          | ||dd|          S )a  Identifies what objects are preventing serialization.

    Args:
        base_obj: Object to be serialized.
        name: Optional name of string.
        depth: Depth of the scope stack to walk through. Defaults to 3.
        print_file: file argument that will be passed to print().

    Returns:
        bool: True if serializable.
        set[FailureTuple]: Set of unserializable objects.

    .. versionadded:: 1.1.0

    N)r   r9   )r;   r%   r/   r   r   s        r   inspect_serializabilityrN      s)    , z""G#HdE4wOOOr   c                    t          j                     d}d}d}|d}t                      }d|  }|                    dt	          t          |          d          z             |                    |           |                    dt	          t          |          d          z             |t          |           }n|                    d| d|  d	           	 t          j        |            d|fS # t          $ r}	|                    t           j
        j         d
t           j
        j         d|	            d}	 |dk    r$|                    t          | ||                     n# t          $ r Y nw xY wY d }	~	nd }	~	ww xY w|dk    rd|fS t          j        |           rt#          | || ||           nt%          | || ||           |s$|                    t          | ||                     |rR|                    dt	          t          |          d          z             |s|                    d           nwdt           j        j         d                    d |D                       z   t           j        j         dz   }
|                    d|
 d           |                    d           |                    dt	          t          |          d          z             |                    d           |                    d           |                    dt	          t          |          d          z             | |fS )NF TzChecking Serializability of =P   zSerializing 'z' z...z!!! FAILz serialization: r   )r/   r&   r0   r   zTNothing failed the inspect_serialization test, though serialization did not succeed.z

	
c              3   4   K   | ]}t          |          V  d S r   )r+   ).0ks     r   	<genexpr>z+_inspect_serializability.<locals>.<genexpr>   s(      88qCFF888888r   z

z
Variable: zowas found to be non-serializable. There may be multiple other undetected variables that were non-serializable. zConsider either removing the instantiation/imports of these variables or moving the instantiation into the scope of the function/class. zmCheck https://docs.ray.io/en/master/ray-core/objects/serialization.html#troubleshooting for more information.zIf you have any suggestions on how to improve this error message, please reach out to the Ray developers on github.com/ray-project/ray/issues/)coloramainitsetr   minr7   r+   cpdumps	ExceptionForeREDRESETaddr#   r3   r4   r@   rJ   StyleBRIGHTjoin	RESET_ALL)r;   r%   r/   r&   r0   r   	top_leveldeclarationr=   e	fail_varss              r   r9   r9      s    MOOOIKE	ee?X??cCK 0 0"555666k"""cCK 0 0"555666<x==D;d;;h;;;<<<
[   
 
 
} VV(-*=VVSTVV	
 	
 	
 	zzXtV D DEEE 	 	 	D	
 zzk!!
 (## 
##	
 	
 	
 	
 	
 	'#	
 	
 	
 	
  >XtV<<===  7cCK 0 0"555666 	MM1    1.00))88K888889^-3334 
 MM%Y % % %  
 MMG  
 	cCK 0 0"555666{	
 	
 	
 	C	
 	
 	

 	cCK 0 0"5556669k!!s<   C3 3
F ==E;;*E&%E;&
E30E;2E33E;;F )NrK   N)r*   r3   
contextlibr   typingr   r   r   r   rX   rayray.cloudpicklecloudpickler\   ray.util.annotationsr   r   r   r#   r@   rJ   r+   intboolrN   r9   r!   r   r   <module>rs      s   3 3  % % % % % % , , , , , , , , , , , ,  


       - - - - - -   
2 
2 
2 
2 
2 
2 
2 
2 P P P P P P P P$0 0 0f( ( (V   $	P PP
3-P P 	P
 4\""#P P P P2]"
4\""#]" ]" ]" ]" ]" ]"r   