
    %`i                    R   d dl Z d dlZd dlmZmZ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 n# e$ r d dlmZmZ Y nw xY wd dlmc mZ d dlmc mZ d dlZd dlmZmZmZmZ d dlm Z  d dl!m"Z" d dl#m$Z$ d dl%m&Z& d d	l'm(Z( d d
l)m*Z*m+Z+m,Z, d dl-m.Z. d dl/m0Z0m1Z1m2Z2 d dl3m4Z4m5Z5 d dlm6Z6m7Z7m8Z8m9Z9 d dl:m;Z;m<Z< d dl=m>Z>m?Z? d dl@mAZA d dlBmCZCmDZD d dlEmFZFmGZGmHZH er	  ejI        eJ          ZKdZL ed          ZMedeNeM         f         ZO ed          ZP ed          ZQ ed          ZR ed          ZS ed          ZT ed          ZU ed          ZV ed          ZW ed          ZX ed          ZY ed           ZZ ed!          Z[ G d" d#eeP                   Z\ G d$ d%eePeRf                   Z] G d& d'eePeReSf                   Z^ G d( d)eePeReSeTf                   Z_ G d* d+eePeReSeTeUf                   Z` G d, d-eePeReSeTeUeVf                   Za G d. d/eePeReSeTeUeVeWf                   Zb G d0 d1eePeReSeTeUeVeWeXf                   Zc G d2 d3eePeReSeTeUeVeWeXeYf	                   Zd G d4 d5eePeReSeTeUeVeWeXeYeZf
                   Ze G d6 d7eePeReSeTeUeVeWeXeYeZe[f                   Zfed8eeeRgePf         d9e]ePeRf         fd:            Zged8eeeReSgePf         d9e^ePeReSf         fd;            Zged8eeeReSeTgePf         d9e_ePeReSeTf         fd<            Zged8eeeReSeTeUgePf         d9e`ePeReSeTeUf         fd=            Zged8eeeReSeTeUeVgePf         d9eaePeReSeTeUeVf         fd>            Zged8eeeReSeTeUeVeWgePf         d9ebePeReSeTeUeVeWf         fd?            Zged8eeeReSeTeUeVeWeXgePf         d9ecePeReSeTeUeVeWeXf         fd@            Zged8eeeReSeTeUeVeWeXeYg	ePf         d9edePeReSeTeUeVeWeXeYf	         fdA            Zged8eeeReSeTeUeVeWeXeYeZg
ePf         d9eeePeReSeTeUeVeWeXeYeZf
         fdB            Zged8eeeReSeTeUeVeWeXeYeZe[gePf         d9efePeReSeTeUeVeWeXeYeZe[f         fdC            Zged8eegePf         d9e\eP         fdD            ZgeddddddddEdFe
eehe	dG         f                  dHe
ei         dIe
eh         dJe
eejekelf                  dKe
eh         dLe
ej         dMe
e.         d9eeeeeQf         ePf         gef         fdN            Zge?e+dO                         Zg G dP dQ          Zme? G dR dS                      Zn G dT dUeo          Zp G dV dW          Zqe? G dX dYer                      ZsdZ Zte? G d[ d\eeM                               Zue? G d] d^eeM                               Zvd_ Zwd` Zxe?da             ZydS )b    N)TYPE_CHECKINGAnyCallableDictGenericListLiteralOptionalTupleTypeVarUnionoverload)Concatenate	ParamSpec)ActorClassIDLanguage	ObjectRefcross_language)ray_option_utils)DEFAULT_MAX_CONCURRENCY_ASYNC))_warn_if_using_deprecated_placement_group)has_async_methods)wrap_auto_init)client_mode_convert_actorclient_mode_hookclient_mode_should_convert)TensorTransportEnum)is_class_methodis_function_or_methodis_static_method)get_runtime_env_info#parse_runtime_env_for_task_or_actor)STREAMING_GENERATOR_RETURNObjectRefGeneratorPythonFunctionDescriptor(raise_sys_exit_with_custom_error_message)ActorAlreadyExistsErrorAsyncioActorExit)DeveloperAPI	PublicAPI)+_configure_placement_group_based_on_context) PlacementGroupSchedulingStrategySchedulingStrategyT)_inject_tracing_into_class_tracing_actor_creation _tracing_actor_method_invocationTzActorHandle[T]_Ret_P_T0_T1_T2_T3_T4_T5_T6_T7_T8_T9c                   "    e Zd ZddZdefdZdS )_RemoteMethodNoArgsreturnObjectRef[_Ret]c                     d S N selfs    ]/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/actor.pyremotez_RemoteMethodNoArgs.remote^           c                     d S rC   rD   rE   s    rG   bindz_RemoteMethodNoArgs.binda   rI   rJ   N)r@   rA   )__name__
__module____qualname__rH   r   rL   rD   rJ   rG   r?   r?   ]   sC           c      rJ   r?   c                   &    e Zd ZddZdedefdZdS )	_RemoteMethod0_RemoteMethod0__arg0Union[_T0, ObjectRef[_T0]]r@   rA   c                     d S rC   rD   rF   rR   s     rG   rH   z_RemoteMethod0.remotef   rI   rJ   c                     d S rC   rD   rU   s     rG   rL   z_RemoteMethod0.bindi   rI   rJ   N)rR   rS   r@   rA   )rM   rN   rO   rH   r4   r   rL   rD   rJ   rG   rQ   rQ   e   sJ           3 3      rJ   rQ   c                   6    e Zd Z	 	 	 	 	 	 d
dZdededefdZd	S )_RemoteMethod1_RemoteMethod1__arg0rS   _RemoteMethod1__arg1Union[_T1, ObjectRef[_T1]]r@   rA   c                     d S rC   rD   rF   rY   rZ   s      rG   rH   z_RemoteMethod1.remoten   	     	rJ   c                     d S rC   rD   r]   s      rG   rL   z_RemoteMethod1.binds   rI   rJ   N)rY   rS   rZ   r[   r@   rA   )rM   rN   rO   rH   r4   r5   r   rL   rD   rJ   rG   rX   rX   m   si        2<X	   
3        rJ   rX   c                   >    e Zd Z	 	 	 	 	 	 	 	 dd	Zdedededefd
ZdS )_RemoteMethod2_RemoteMethod2__arg0rS   _RemoteMethod2__arg1r[   _RemoteMethod2__arg2Union[_T2, ObjectRef[_T2]]r@   rA   c                     d S rC   rD   rF   rb   rc   rd   s       rG   rH   z_RemoteMethod2.remotex   s	     	rJ   c                     d S rC   rD   rg   s       rG   rL   z_RemoteMethod2.bind   rI   rJ   N)rb   rS   rc   r[   rd   re   r@   rA   )	rM   rN   rO   rH   r4   r5   r6   r   rL   rD   rJ   rG   ra   ra   w   s~        , - -	
 
   3  S S      rJ   ra   c            
       F    e Zd Z	 	 	 	 	 	 	 	 	 	 ddZdedededed	ef
dZ	dS )_RemoteMethod3_RemoteMethod3__arg0rS   _RemoteMethod3__arg1r[   _RemoteMethod3__arg2re   _RemoteMethod3__arg3Union[_T3, ObjectRef[_T3]]r@   rA   c                     d S rC   rD   rF   rk   rl   rm   rn   s        rG   rH   z_RemoteMethod3.remote   s	     	rJ   c                     d S rC   rD   rq   s        rG   rL   z_RemoteMethod3.bind   rI   rJ   N)
rk   rS   rl   r[   rm   re   rn   ro   r@   rA   )
rM   rN   rO   rH   r4   r5   r6   r7   r   rL   rD   rJ   rG   rj   rj      s        , - -	
 - 
   3  S # #      rJ   rj   c                   N    e Zd Z	 	 	 	 	 	 	 	 	 	 	 	 ddZdedededed	ede	fdZ
dS )_RemoteMethod4_RemoteMethod4__arg0rS   _RemoteMethod4__arg1r[   _RemoteMethod4__arg2re   _RemoteMethod4__arg3ro   _RemoteMethod4__arg4Union[_T4, ObjectRef[_T4]]r@   rA   c                     d S rC   rD   rF   ru   rv   rw   rx   ry   s         rG   rH   z_RemoteMethod4.remote   s	     	rJ   c                     d S rC   rD   r|   s         rG   rL   z_RemoteMethod4.bind   r^   rJ   N)ru   rS   rv   r[   rw   re   rx   ro   ry   rz   r@   rA   )rM   rN   rO   rH   r4   r5   r6   r7   r8   r   rL   rD   rJ   rG   rt   rt      s        , - -	
 - - 
   #&03=@JM	     rJ   rt   c                   V    e Zd Z	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZdedededed	ede	de
fdZdS )_RemoteMethod5_RemoteMethod5__arg0rS   _RemoteMethod5__arg1r[   _RemoteMethod5__arg2re   _RemoteMethod5__arg3ro   _RemoteMethod5__arg4rz   _RemoteMethod5__arg5Union[_T5, ObjectRef[_T5]]r@   rA   c                     d S rC   rD   rF   r   r   r   r   r   r   s          rG   rH   z_RemoteMethod5.remote   	     	rJ   c                     d S rC   rD   r   s          rG   rL   z_RemoteMethod5.bind   r   rJ   N)r   rS   r   r[   r   re   r   ro   r   rz   r   r   r@   rA   )rM   rN   rO   rH   r4   r5   r6   r7   r8   r9   r   rL   rD   rJ   rG   r   r      s        	,	 -	 -		
 -	 -	 -	 
	 	 	 			 	 		
 	 	 	 
	 	 	 	 	 	rJ   r   c                   ^    e Zd Z	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZdedededed	ede	de
defdZdS )_RemoteMethod6_RemoteMethod6__arg0rS   _RemoteMethod6__arg1r[   _RemoteMethod6__arg2re   _RemoteMethod6__arg3ro   _RemoteMethod6__arg4rz   _RemoteMethod6__arg5r   _RemoteMethod6__arg6Union[_T6, ObjectRef[_T6]]r@   rA   c                     d S rC   rD   rF   r   r   r   r   r   r   r   s           rG   rH   z_RemoteMethod6.remote   	     	rJ   c                     d S rC   rD   r   s           rG   rL   z_RemoteMethod6.bind   r   rJ   N)r   rS   r   r[   r   re   r   ro   r   rz   r   r   r   r   r@   rA   )rM   rN   rO   rH   r4   r5   r6   r7   r8   r9   r:   r   rL   rD   rJ   rG   r   r      s        
,
 -
 -	

 -
 -
 -
 -
 

 
 
 


 
 	

 
 
 
 
 

 
 
 
 
 
rJ   r   c                   f    e Zd Z	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZdedededed	ede	de
dedefdZdS )_RemoteMethod7_RemoteMethod7__arg0rS   _RemoteMethod7__arg1r[   _RemoteMethod7__arg2re   _RemoteMethod7__arg3ro   _RemoteMethod7__arg4rz   _RemoteMethod7__arg5r   _RemoteMethod7__arg6r   _RemoteMethod7__arg7Union[_T7, ObjectRef[_T7]]r@   rA   c	                     d S rC   rD   	rF   r   r   r   r   r   r   r   r   s	            rG   rH   z_RemoteMethod7.remote   	     	rJ   c	                     d S rC   rD   r   s	            rG   rL   z_RemoteMethod7.bind   r   rJ   N)r   rS   r   r[   r   re   r   ro   r   rz   r   r   r   r   r   r   r@   rA   )rM   rN   rO   rH   r4   r5   r6   r7   r8   r9   r:   r;   r   rL   rD   rJ   rG   r   r      s        , - -	
 - - - - - 
     	
      
     rJ   r   c                   n    e Zd Z	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZdedededed	ede	de
dededefdZdS )_RemoteMethod8_RemoteMethod8__arg0rS   _RemoteMethod8__arg1r[   _RemoteMethod8__arg2re   _RemoteMethod8__arg3ro   _RemoteMethod8__arg4rz   _RemoteMethod8__arg5r   _RemoteMethod8__arg6r   _RemoteMethod8__arg7r   _RemoteMethod8__arg8Union[_T8, ObjectRef[_T8]]r@   rA   c
                     d S rC   rD   
rF   r   r   r   r   r   r   r   r   r   s
             rG   rH   z_RemoteMethod8.remote   	     	rJ   c
                     d S rC   rD   r   s
             rG   rL   z_RemoteMethod8.bind   r   rJ   N)r   rS   r   r[   r   re   r   ro   r   rz   r   r   r   r   r   r   r   r   r@   rA   )rM   rN   rO   rH   r4   r5   r6   r7   r8   r9   r:   r;   r<   r   rL   rD   rJ   rG   r   r      s        , - -	
 - - - - - - 
     	
       
     rJ   r   c                   v    e Zd Z	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZdedededed	ede	de
dedededefdZdS )_RemoteMethod9_RemoteMethod9__arg0rS   _RemoteMethod9__arg1r[   _RemoteMethod9__arg2re   _RemoteMethod9__arg3ro   _RemoteMethod9__arg4rz   _RemoteMethod9__arg5r   _RemoteMethod9__arg6r   _RemoteMethod9__arg7r   _RemoteMethod9__arg8r   _RemoteMethod9__arg9Union[_T9, ObjectRef[_T9]]r@   rA   c                     d S rC   rD   rF   r   r   r   r   r   r   r   r   r   r   s              rG   rH   z_RemoteMethod9.remote  	     	rJ   c                     d S rC   rD   r   s              rG   rL   z_RemoteMethod9.bind  r   rJ   N)r   rS   r   r[   r   re   r   ro   r   rz   r   r   r   r   r   r   r   r   r   r   r@   rA   )rM   rN   rO   rH   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r   rL   rD   rJ   rG   r   r     s       , - -	
 - - - - - - - 
     	
        
     rJ   r   __methodr@   c                     d S rC   rD   r   s    rG   methodr   /  	     CrJ   c                     d S rC   rD   r   s    rG   r   r   6  r   rJ   c                     d S rC   rD   r   s    rG   r   r   =  r   rJ   c                     d S rC   rD   r   s    rG   r   r   D  r   rJ   c                     d S rC   rD   r   s    rG   r   r   K  r   rJ   c                     d S rC   rD   r   s    rG   r   r   R  r   rJ   c                     d S rC   rD   r   s    rG   r   r   Y  r   rJ   c                     d S rC   rD   r   s    rG   r   r   `  r   rJ   c                     d S rC   rD   r   s    rG   r   r   g  r   rJ   c                     d S rC   rD   r   s    rG   r   r   n  r   rJ   c                     d S rC   rD   r   s    rG   r   r   u  r   rJ   num_returnsconcurrency_groupmax_task_retriesretry_exceptions#_generator_backpressure_num_objectsenable_task_eventstensor_transportr   	streamingr   r   r   r   r   r   c                     d S rC   rD   r   s          rG   r   r   |  s	     CrJ   c                  b   g d}dt           t          t          f         ffd}t          |           dk    r9t	          | d                   r$t                    dk    r || d                   S d| d}t          |           dk    s
J |            D ]}d| d	| }||v s
J |            |S )
a
  Annotate an actor method.

    .. code-block:: python

        @ray.remote
        class Foo:
            @ray.method(num_returns=2)
            def bar(self):
                return 1, 2

        f = Foo.remote()

        _, _ = f.bar.remote()

    Args:
        num_returns: The number of object refs that should be returned by
            invocations of this actor method. The default value is 1 for a
            normal actor task and "streaming" for an actor generator task (a
            function that yields objects instead of returning them).
        max_task_retries: How many times to retry an actor task if the task
            fails due to a runtime error, e.g., the actor has died. The
            default value is 0. If set to -1, the system will retry the
            failed task until the task succeeds, or the actor has reached
            its max_restarts limit. If set to `n > 0`, the system will retry
            the failed task up to n times, after which the task will throw a
            `RayActorError` exception upon :obj:`ray.get`.  Note that Python
            exceptions may trigger retries
            *only if* `retry_exceptions` is set for the method, in that case
            when `max_task_retries` runs out the task will rethrow the
            exception from the task. You can override this number with the
            method's `max_task_retries` option in `@ray.method` decorator or
            in `.option()`.
        retry_exceptions: Boolean of whether to retry all Python
            exceptions, or a list of allowlist exceptions to retry. The default
            value is False (only retry tasks upon system failures and if
            max_task_retries is set)
        concurrency_group: The name of the concurrency group
            to use for the actor method. By default, the actor is
            single-threaded and runs all actor tasks on the same thread.
            See :ref:`Defining Concurrency Groups <defining-concurrency-groups>`.
        tensor_transport: [Alpha] The tensor transport protocol to
            use for the actor method. The valid values are "OBJECT_STORE"
            (default), "NCCL", "GLOO", or "NIXL" (case-insensitive). If a
            non-object store transport is specified, Ray will store a
            *reference* instead of a copy of any torch.Tensors found inside
            values returned by this task, and the tensors will be sent directly
            to other tasks using the specified transport. NCCL and GLOO
            transports require first creating a collective with the involved
            actors using
            :func:`ray.experimental.collective.create_collective_group`.
            See :ref:`Ray Direct Transport (RDT) <direct-transport>` for more
            details.
    r   r   c                 ,   dv rd         | _         dv rd         | _        dv rd         | _        dv rd         | _        dv rd         | _        dv rd         d         | _        dv r d         }dd	lm}  ||          }|| _        | S )
Nr   r   r   r   r   r   r   r   'normalize_and_validate_tensor_transport)	__ray_num_returns____ray_max_task_retries____ray_retry_exceptions____ray_concurrency_group__*__ray_generator_backpressure_num_objects____ray_enable_task_events__(ray.experimental.gpu_object_manager.utilr   __ray_tensor_transport__)r   r   r   kwargss      rG   annotate_methodzmethod.<locals>.annotate_method  s    F"")/)>F&''.45G.HF+''.45G.HF+&((/56I/JF,0F::@F5AF=  6))f5I.J.V067K0LF-''%&89       GFGWXX.>F+rJ      r   zjThe @ray.method decorator must be applied using no arguments or at least one of the arguments in the list z+, for example '@ray.method(num_returns=2)'.z-Unexpected keyword argument to @ray.method: 'z''. The supported keyword arguments are )r   r3   r2   lencallable)argsr   valid_kwargsr   error_stringkeykey_error_strings    `     rG   r   r     s   p  LT 2      6 4yyA~~(47++~Fq0@0@tAw'''	(2>	( 	( 	( 
 t99>>><>>> 5 5>C > >/;> > 	 l"""$4""""rJ   c                       e Zd ZdZ	 	 	 ddedeeeed         f                  dedee	e
ef         de	d	ed
e	dee         deeej                          dee         fdZddZdS )_ActorMethodMetadataa  A container for the metadata required to invoke an actor method.

    This class intentionally does *not* hold a reference to the `ActorHandle`, as that causes
    a circular reference that delays `ActorHandle` destruction until the Python GC runs.

    Instead, it can be used as a factory to lazily generate `ActorMethod` instances that can
    be used to submit actor tasks for this method.
    Nmethod_namer   r   r   r   is_generator"generator_backpressure_num_objectsr   	decorator	signaturer   c                     || _         ||rd}nt          j        }|| _        || _        || _        || _        || _        || _        || _	        |	| _
        |
| _        dS )a  Initialize an _ActorMethodMetadata.

        Args:
            method_name: The name of the actor method.
            num_returns: The default number of return values that the method
                invocation should return. If None is given, it uses
                DEFAULT_ACTOR_METHOD_NUM_RETURN_VALS for a normal actor task
                and "streaming" for a generator task (when `is_generator` is True).
            max_task_retries: Number of retries on method failure.
            retry_exceptions: Boolean or list/tuple of exceptions to retry.
            is_generator: True if the method is a generator.
            generator_backpressure_num_objects: Generator-only config for backpressure.
            enable_task_events: True if task events are enabled for this method.
            decorator: Optional decorator for the method invocation.
            signature: The signature of the actor method.
            tensor_transport: The tensor transport protocol to use for the actor method.
        Nr   )_method_nameray_constants$DEFAULT_ACTOR_METHOD_NUM_RETURN_VALS_num_returns_max_task_retries_retry_exceptions_is_generatorr   _enable_task_events
_decorator
_signature_tensor_transport)rF   r   r   r   r   r   r   r   r   r   r   s              rG   __init__z_ActorMethodMetadata.__init__  sx    < (  Q)+P'!1!1)3U0#5 ##!1rJ   actor_handleActorHandler@   ActorMethodc                     t          || j        | j        | j        | j        | j        | j        | j        | j        | j	        | j
                  S )z\
        Produce a bound ActorMethod that holds a strong reference to actor_handle.
        )r   r   r   )r  r   r  r  r  r  r   r  r  r	  r
  )rF   r  s     rG   rL   z_ActorMethodMetadata.bind6  sX     ""4$oo!3
 
 
 	
rJ   NNN)r  r  r@   r  )rM   rN   rO   __doc__strr
   r   intr	   boollisttupler   r   inspect	Parameterr  rL   rD   rJ   rG   r   r     s         $ $(7;*..2 .2.2 eC)=$=>?.2 	.2
  dE 12.2 .2 -0.2 !.2 C=.2 D!234.2 #3-.2 .2 .2 .2`
 
 
 
 
 
rJ   r   c                      e Zd ZdZ	 	 	 ddeeeed         f                  dedeee	e
f         deded	ed
eeej                          dee         fdZd Zed             Zd Zd Zee	 	 	 	 	 	 ddeded         f         fd                        Zee	 	 	 	 	 	 	 	 	 	 ddee         fd                        Zd Zd ZdS )r  zA class used to invoke an actor method.

    Note: This class should not be instantiated directly. Instead, it should
    only be used as a return value from the `@ray.method` decorator.
    Nr   r   r   r   r   r   r   r   r   c                 
   || _         || _        || _        | j        |rd| _        nt          j        | _        || _        || _        || _        || _        || _	        |
| _
        |	| _        |t          j        j        }|| _        dS )a  Initialize an ActorMethod.

        Args:
            actor: The actor instance this method belongs to.
            method_name: The name of the actor method.
            num_returns: The default number of return values that the method
                invocation should return. If None is given, it uses
                DEFAULT_ACTOR_METHOD_NUM_RETURN_VALS for a normal actor task
                and "streaming" for a generator task (when `is_generator` is True).
            max_task_retries: Number of retries on method failure.
            retry_exceptions: Boolean of whether you want to retry all user-raised
                exceptions, or a list of allowlist exceptions to retry.
            is_generator: True if a given method is a Python generator.
            generator_backpressure_num_objects: Generator-only config.
                If a number of unconsumed objects reach this threshold,
                a actor task stop pausing.
            enable_task_events: True if task events is enabled, i.e., task events from
                the actor should be reported. Defaults to True.
            decorator: An optional decorator that should be applied to the actor
                method invocation.
            signature: The signature of the actor method. It is None only when cross
                language feature is used.
            tensor_transport: The tensor transport protocol to use for the actor method.
        Nr   )_actorr   r  r  r  r  r  r  r   r  r	  r  r   OBJECT_STOREnamer
  )rF   actorr   r   r   r   r   r   r   r   r   r   s               rG   r  zActorMethod.__init__S  s    L '' $ W$/!!$1$V!!1!1)3U0#5 # $ #2?D!1rJ   c                 B    t          d| j         d| j         d          )NzDActor methods cannot be called directly. Instead of running 'object.z()', try 'object..remote()'.)	TypeErrorr   rF   r   r   s      rG   __call__zActorMethod.__call__  s>    6"&"36 6(6 6 6
 
 	
rJ   c                 .    |                      ||          S )a  
        Bind arguments to the actor method for Ray DAG building.

        This method generates and returns an intermediate representation (IR)
        node that indicates the actor method will be called with the given
        arguments at execution time.

        This method is used in both :ref:`Ray DAG <ray-dag-guide>` and
        :ref:`Ray Compiled Graph <ray-compiled-graph>` for building a DAG.
        _bindr"  s      rG   rL   zActorMethod.bind  s     zz$'''rJ   c                 .    |                      ||          S rC   _remoter"  s      rG   rH   zActorMethod.remote  s    ||D&)))rJ   c                     |                      dd          }|ddlm}  ||          }|d<    G fdd          } |            S )a  Convenience method for executing an actor method call with options.

        Same arguments as func._remote(), but returns a wrapped function
        that a non-underscore .remote() can be called on.

        Examples:
            # The following two calls are equivalent.
            >>> actor.my_method._remote(args=[x, y], name="foo", num_returns=2)
            >>> actor.my_method.options(name="foo", num_returns=2).remote(x, y)
        r   Nr   r   c                   8    e Zd Z fdZe fd            ZdS )(ActorMethod.options.<locals>.FuncWrapperc                 $     j         d||dS Nr   r   rD   r(  rF   r   r   func_clsoptionss      rG   rH   z/ActorMethod.options.<locals>.FuncWrapper.remote  s#    'x'LT&LLGLLLrJ   c                 $     j         d||dS r.  r%  r0  s      rG   rL   z-ActorMethod.options.<locals>.FuncWrapper.bind  s"    %x~J4JJ'JJJrJ   NrM   rN   rO   rH   r)   rL   )r1  r2  s   rG   FuncWrapperr,    sk        M M M M M M K K K K K \K K KrJ   r5  )getr   r   )rF   r2  r   r   r5  r1  s    `   @rG   r2  zActorMethod.options  s     ";;'94@@'       GFGWXX*:G&'	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K {}}rJ    r@   ray.dag.ClassMethodNode)r8  .c                 d   ddl m}m}m}	m}
m} ||||d}| j        }|t          d          |	||
d ||j        i}|xj        dz  c_        | j	        
J d            	 t          j        | j	        ||           n# t          $ r}| j	                                        }t          |          dk    r&|d         j        dk    r|                    d           t#          j        |	          }t          t'          |           d
| j         d| d| d| d
          d d }~ww xY w || j        ||||          }|j        dk    rmg }t-          |j                  D ]G} |d| ||ft/                      t/                      |d|	|i          }|                    |           Ht3          |          S |S )Nr   )BIND_INDEX_KEYIS_CLASS_METHOD_OUTPUT_KEYPARENT_CLASS_NODE_KEYPREV_CLASS_METHOD_CALL_KEYClassMethodNode)r  r   r   r   zLost reference to actorr   z,self._signature should be set for .bind API._ray_trace_ctx)
parametersz. The function `z` has a signature `z:`, but the given arguments to `bind` doesn't match. args: z
. kwargs: .)other_args_to_resolvereturn_idx_T)ray.dag.class_noder:  r;  r<  r=  r>  r  RuntimeError_ray_dag_bind_indexr	  r   validate_argsr!  copyr   r  popr  	Signaturer  r   r   rangedictappendr  )rF   r   r   r  r   r   r   r:  r;  r<  r=  r>  r2  r  rC  esignature_copynodeoutput_nodesioutput_nodes                        rG   r&  zActorMethod._bind  s   	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 &!23V	
 
 = 8999 "5&E5!

 	!!Q&!! O''9 (''	#DOT6BBBB 
	 
	 
	!_1133N>""Q&&>"+=+BFV+V+V""2&&&$..IIINq66 : :4+< : :": : $: :06: : :  	
	 "7
 
 
 a24L4+,, 1 1-o%!%%1IFFFF/7LeT  ##K0000&&&Ks   A9 9
D BDD c           	      
   	
  j          j        d j        	 j        	 j        
 j        

t          j        j        k    rdk    rt          d
 d           j
        j        st          d
 d          t          j        j        j        j        }|                     j
        
          st           j
         d
 d          |pg }|pi }	 
f	d	} j                             |          } |||          }
t          j        j        k    rPt'          |t(                    sJ |}t          j        j        j        j        }|                    | j
        
           |S )
Nr   r   z)Currently, methods with tensor_transport=z} only support 1 return value. Please make sure the actor method is decorated with `@ray.method(num_returns=1)` (the default).z3Currently, methods with .options(tensor_transport="z") are not supported when enable_tensor_transport=False. Please set @ray.remote(enable_tensor_transport=True) on the actor class definition.z  does not have tensor transport z available. If using a collective-based transport ("nccl" or "gloo"), please create a communicator with `ray.experimental.collective.create_collective_group` before calling actor tasks with non-default tensor_transport.c                    	 j         }|t          d          t          j        j        j        j        }|                    ||            |                    j	        | |	
          S )Nz{Lost reference to actor. Actor handles must be stored as variables, e.g. `actor = MyActor.remote()` before calling methods.)
r   r   r  r   r   r   concurrency_group_namer   r   r   )
r  rF  ray_privateworkerglobal_workergpu_object_manager#trigger_out_of_band_tensor_transfer_actor_method_callr   )r   r   	dst_actorr\  r   r   r   r   r  r   r   rF   r   s       rG   
invocationz'ActorMethod._remote.<locals>.invocationY  s    I " R   "%!4!B!UBB9dSSS//!'!1!1'87#5!1 0   rJ   )r  r  r  r  r   r
  r   r  r  
ValueErrorr  _ray_enable_tensor_transportrX  rY  rZ  r[  r\  actor_has_tensor_transportr  
isinstancer   add_gpu_object_ref)rF   r   r   r  r   r   r   r   r   r   r   r\  r`  object_refs
object_refs   `  ````````    rG   r)  zActorMethod._remote   sT    +K##5# ##5%!%!9.68 0 ##52?DDDa v@P v v v   ;;  jJZ j j j   "%!4!B!U%@@-   !{ T TDT T T T   zr2	 	 	 	 	 	 	 	 	 	 	 	 	8 ?&44J jv..2?DDD k955555$J!$!4!B!U11DK)9   rJ   c                     | j         | j        | j        | j        | j        | j        | j        | j        | j        | j	        d
S )N)
r  r   r   r   r   r   r   r   r   r
  )
r  r   r  r  r  r  r  r   r  r
  rE   s    rG   __getstate__zActorMethod.__getstate__  sK    [,, $ 6 $ 6 .262Z"&":!%!7
 
 	
rJ   c                     |                      |d         |d         |d         |d         |d         |d         |d         |d         |d	         |d
         
  
         d S )Nr  r   r   r   r   r   r   r   r   r
  )r  )rF   states     rG   __setstate__zActorMethod.__setstate__  sv    'N- - $%$%.!67&'+%&	
 	
 	
 	
 	
rJ   r  )NNr7  NNN
NNr7  NNNNNNN)rM   rN   rO   r  r
   r   r  r	   r  r  r  r   r  r  r  r  r#  r)   rL   rH   r2  r   r0   r   r&  r)  ri  rl  rD   rJ   rG   r  r  K  s          7;*.B2 B2 eC)=$=>?	B2
 B2  dE 12B2 B2 -0B2 !B2 D!234B2 #3-B2 B2 B2 B2H
 
 
 ( ( \(* * *  B % ,0L L 
(%0N*OO	PL L L &% ^L\ % ,0*.a a #3-a a a &% ^aF
 
 

 
 
 
 
rJ   r  c                   H    e Zd ZdZi Zd Zed             Zed             ZdS )_ActorClassMethodMetadataa  Metadata for all methods in an actor class. This data can be cached.

    Attributes:
        methods: The actor methods.
        decorators: Optional decorators that should be applied to the
            method invocation function before invoking the actor methods. These
            can be set by attaching the attribute
            "__ray_invocation_decorator__" to the actor method.
        signatures: The signatures of the methods.
        num_returns: The default number of return values for
            each actor method.
        max_task_retries: Number of retries on method failure.
        retry_exceptions: Boolean of whether you want to retry all user-raised
            exceptions, or a list of allowlist exceptions to retry, for each method.
        enable_task_events: True if tracing is enabled, i.e., task events from
            the actor should be reported. Defaults to True.
    c                 Z    t          |           j        }t          | d| d| d          )Nz6 can not be constructed directly, instead of running 'z
()', try 'z
.create()')typerM   r!  )rF   
class_names     rG   r  z"_ActorClassMethodMetadata.__init__  sN    $ZZ(
 + +#-+ ++ + +
 
 	
rJ   c                 8    | j                                          d S rC   )_cacheclearclss    rG   reset_cachez%_ActorClassMethodMetadata.reset_cache  s    
rJ   c                    | j                             |          }||S |                     |           }t          j        |t
                    }t          |          |_        i |_        i |_	        i |_
        i |_        i |_        i |_        i |_        i |_        i |_        i |_        t%          d |D                       |_        |D ]\  }}t          j        |          }t+          |          pt-          ||          }t/          j        ||           |j	        |<   t3          |d          r|j        |j
        |<   n
d |j
        |<   t3          |d          r|j        |j        |<   t3          |d          r|j        |j        |<   t3          |d          r|j        |j        |<   t3          |d          r|j        |j        |<   t3          |d          r|j        |j        |<   t          j         |          pt          j!        |          }	|	|j        |<   t3          |d	          r|j"        |j        |<   t3          |d
          r|j#        |j        |<   || j         |<   |S )Nc              3      K   | ]:\  }}t          |d t          j        j                  t          j        j        k    V  ;dS )r   N)getattrr   r  r  ).0_r   s      rG   	<genexpr>z3_ActorClassMethodMetadata.create.<locals>.<genexpr>  se       0
 0
 6 *#05 
 #/450
 0
 0
 0
 0
 0
rJ   )ignore_firstr   r   r   __ray_invocation_decorator__r   r   r   r   )$rt  r6  __new__r  
getmembersr   rM  methods
decorators
signaturesr   r   r   method_is_generatorr   r   concurrency_group_for_methodsmethod_name_to_tensor_transportanyhas_tensor_transport_methodsunwrapr   r    r   extract_signaturehasattrr   r   r   r  r   r   isgeneratorfunctionisasyncgenfunctionr   r   )
rw  modified_class"actor_creation_function_descriptorcached_metarF   actor_methodsr   r   is_boundr   s
             rG   createz _ActorClassMethodMetadata.create  s    jnn%GHH" {{3*>;PQQM**
  " "#% "$24/-/*?A, -0 0
 0
 +0
 0
 0
 -
 -
) $1 9	4 9	4K ^F++F&v.. 2B3 3H ,5+F\, , ,DOK( v455 5060J --04 - v9:: U5;5T%k2v9:: U5;5T%k2v=>> S/5/R,v:;; 5 4 2 v;<< Y7=7X'4"6  4+F33  5AD$[1vKLL F E 7 v9:: 4 3 4
 :>
56rJ   N)	rM   rN   rO   r  rt  r  classmethodrx  r  rD   rJ   rG   ro  ro    so         $ F
 
 
   [ f f [f f frJ   ro  c                   "    e Zd ZdZdedefdZdS )_ActorClassMetadataa	  Metadata for an actor class.

    Attributes:
        language: The actor language, e.g. Python, Java.
        modified_class: The original class that was decorated (with some
            additional methods added like __ray_terminate__).
        actor_creation_function_descriptor: The function descriptor for
            the actor creation task.
        class_id: The ID of this actor class.
        method_meta: The actor method metadata.
        class_name: The name of this class.
        num_cpus: The default number of CPUs required by the actor creation
            task.
        num_gpus: The default number of GPUs required by the actor creation
            task.
        memory: The heap memory quota for this actor.
        resources: The default resources required by the actor creation task.
        label_selector: The labels required for the node on which this actor
            can be scheduled on. The label selector consist of key-value pairs, where the keys
            are label names and the value are expressions consisting of an operator with label
            values or just a value to indicate equality.
        fallback_strategy: If specified, expresses soft constraints through a list of decorator
            options to fall back on when scheduling on a node. Decorator options are evaluated
            together during scheduling. The first satisfied dict of options is used. Currently
            only `label_selector` is a supported option.
        accelerator_type: The specified type of accelerator required for the
            node on which this actor runs.
            See :ref:`accelerator types <accelerator_types>`.
        runtime_env: The runtime environment for this actor.
        scheduling_strategy: Strategy about how to schedule this actor.
        last_export_cluster_and_job: A pair of the last exported cluster
            and job to help us to know whether this function was exported.
            This is an imperfect mechanism used to determine if we need to
            export the remote function again. It is imperfect in the sense that
            the actor class definition could be exported multiple times by
            different workers.
        enable_tensor_transport: Whether to enable out-of-band tensor transport
            for this actor.
    scheduling_strategyenable_tensor_transportc                 `   || _         || _        || _        || _        |j        | _        |t
          j        k    | _        || _        || _	        || _
        || _        |	| _        |
| _        || _        || _        || _        || _        || _        || _        || _        || _        d | _        || _        d S rC   )languager  r  method_metarr  r   PYTHONis_cross_languageclass_idmax_restartsr   num_cpusnum_gpusmemoryobject_store_memory	resourceslabel_selectorfallback_strategyaccelerator_typeruntime_envconcurrency_groupsr  last_export_cluster_and_jobr  )rF   r  r  r  r  r  r  r   r  r  r  r  r  r  r  r  r  r  r  r  s                       rG   r  z_ActorClassMetadata.__init__V  s    , !,2T/&<G!)X_!< ( 0  #6 ",!2 0&"4#6 +/('>$$$rJ   N)rM   rN   rO   r  r-   r  r  rD   rJ   rG   r  r  -  sG        & &P+?& 1'+?( "&)+? +? +? +? +? +?rJ   r  c                       e Zd ZdS )ActorClassInheritanceExceptionN)rM   rN   rO   rD   rJ   rG   r  r    s        DrJ   r  c                    i }t          t          j        t          j                  d                   }t
          j                                        D ]'\  }}||v r|                     ||j	                  ||<   (t          |d                   |d<   |r|d         du rt          d          d|d<   |                    dd          }|r1|                    dd           i |d<   d|d         d	<   d|d         d
<   |S )Nr   r  r  FzActor class has methods with @ray.method(tensor_transport=...) decorator but @ray.remote(enable_tensor_transport=False). Either set enable_tensor_transport=True or remove the @ray.method(tensor_transport=...) decorator from the methods.Tr  r   _ray_system_ray_system_error)setr  getfullargspecr  r  r   actor_optionsitemsr6  default_valuer"   ra  )r  r  _filled_options	arg_nameskvr  s          rG   _process_option_dictr    s9   OG*+>+GHHKLLI .4466 G G1	>>!.!2!21ao!F!FOA%H&& &OM" $ :45>>F   6:12 .112KUSS G3T::B46O01?@,-m<EF,-.ABrJ   c                       e Zd ZdZd Zd Zed             Zed             Zde	e
         fdZdd	Zeedde	e
         fd                        Zed             Zd
S )
ActorClasszAn actor class.

    This is a decorated class. It can be used to create actors.

    Attributes:
        __ray_metadata__: Contains metadata for the actor.
    c                     |D ]7}t          |t                    r t          d| d|j        j         d          8J d            )am  Prevents users from directly inheriting from an ActorClass.

        This will be called when a class is defined with an ActorClass object
        as one of its base classes. To intentionally construct an ActorClass,
        use the '_ray_from_modified_class' classmethod.

        Raises:
            ActorClassInheritanceException: When ActorClass is inherited.
            AssertionError: If ActorClassInheritanceException is not raised i.e.,
                            conditions for raising it are not met in any
                            iteration of the loop.
            TypeError: In all other cases.
        zAttempted to define subclass 'z' of actor class 'z'. Inheriting from actor classes is not currently supported. You can instead inherit from a non-actor base class and make the derived class an actor class (with @ray.remote).FzWActorClass.__init__ should not be called. Please use the @ray.remote decorator instead.)rd  r  r  __ray_metadata__rr  )rw  r  basesattrbases        rG   r  zActorClass.__init__  s{      
	 
	D$
++ 	4$T $ $"3>$ $ $  		
1	
 	
urJ   c                 V    t          d| j        j         d| j        j         d          )aI  Prevents users from directly instantiating an ActorClass.

        This will be called instead of __init__ when 'ActorClass()' is executed
        because an is an object rather than a metaobject. To properly
        instantiated a remote actor, use 'ActorClass.remote()'.

        Raises:
            Exception: Always.
        z4Actors cannot be instantiated directly. Instead of 'z
()', use 'r   )r!  r  rr  r"  s      rG   r#  zActorClass.__call__  sL     B0;B B)4B B B
 
 	
rJ   c                 .    dD ]8}t          |          r&t                              dj         d| d           9 G  fdd           }dj         d}j        |_        ||_        ||_        |                    |          }t          j        j	                  }t                              |          }	t          t          j        |||	fi t          ||	j                  |_        ||_        d	|j        v r|j        j        |j        d	<   |S )
N)rH   r)  _ray_from_modified_class_ray_from_function_descriptorzCreating an actor from class z overwrites attribute z of that classc                       e Zd Z fdZdS )>ActorClass._ray_from_modified_class.<locals>.DerivedActorClassc                     	  j         | g|R i | d S # t          $ rI}t          |t                    r't          |t                    s j         | g|R i | n|Y d }~d S d }~ww xY wrC   )r  	Exceptionrd  r!  r  )rF   r   r   rO  rw  r  s       rG   r  zGActorClass._ray_from_modified_class.<locals>.DerivedActorClass.__init__  s      CL777777777  
  
  
 
 "!Y//  
99 9   0/FtFFFvFFFF GFFFFF
 s    
A)>A$$A)N)rM   rN   rO   r  )rw  r  s   rG   DerivedActorClassr    s3                       rJ   r  zActorClass()r  )r  loggerwarningrM   rN   rO   r  r%   
from_class__ray_actor_class__ro  r  r  r   r  r  r  r  _default_optionsr  )
rw  r  r  r  	attributer  r  rF   r  actor_method_metas
   ``        rG   r  z#ActorClass._ray_from_modified_class  s   
 	 	I ~y11 ;%.; ;!*; ; ;  	  	  	  	  	  	  	  	 ^ 	  	  	   8^4777'5'@$%)")-& (():;;-E-P..
 .
* 6<<.
 
 !4O.	!
 	!
 #0M 	!
 	!
 !.D111373H3TD!-0rJ   c                    t                               t                     }d }t                              ||          }t	          |||d |fi t          ||j                  |_        ||_        d|j        v r|j        j	        |j        d<   |S )Nr  )
r  r  ro  r  r  r  r  r  r  r  )rw  r  r  r  rF   r  r  s          rG   r  z(ActorClass._ray_from_function_descriptor0  s     !!*--5<<.
 
 !4.	!
 	!
 #0M 	!
 	!
 !.D111373H3TD!-0rJ   r@   c                 ,     | j         d||d| j        S )a3  Create an actor.

        Args:
            args: These arguments are forwarded directly to the actor
                constructor.
            kwargs: These arguments are forwarded directly to the actor
                constructor.

        Returns:
            A handle to the newly created actor.
        r/  rD   )r)  r  r"  s      rG   rH   zActorClass.remoteL  s&     t|NfNN8MNNNrJ   ActorClass[T]c                 *   | | j                                         }|                    dd           t          j        ||          t          j        d           d|v rt          d                   d<    G fdd          } |            S )a  Configures and overrides the actor instantiation parameters.

        The arguments are the same as those that can be passed
        to :obj:`ray.remote`.

        Args:
            num_cpus: The quantity of CPU cores to reserve
                for this task or for the lifetime of the actor.
            num_gpus: The quantity of GPUs to reserve
                for this task or for the lifetime of the actor.
            resources (Dict[str, float]): The quantity of various custom resources
                to reserve for this task or for the lifetime of the actor.
                This is a dictionary mapping strings (resource names) to floats.
            label_selector (Dict[str, str]): If specified, requires that the actor run
                on a node which meets the specified label conditions (equals, in, not in, etc.).
            fallback_strategy (List[Dict[str, Any]]): If specified, expresses soft constraints
                through a list of decorator options to fall back on when scheduling on a node.
            accelerator_type: If specified, requires that the task or actor run
                on a node with the specified type of accelerator.
                See :ref:`accelerator types <accelerator_types>`.
            memory: The heap memory request in bytes for this task/actor,
                rounded down to the nearest integer.
            object_store_memory: The object store memory request for actors only.
            max_restarts: This specifies the maximum
                number of times that the actor should be restarted when it dies
                unexpectedly. The minimum valid value is 0 (default),
                which indicates that the actor doesn't need to be restarted.
                A value of -1 indicates that an actor should be restarted
                indefinitely.
            max_task_retries: How many times to retry an actor task if the task
                fails due to a runtime error, e.g., the actor has died. The
                default value is 0. If set to -1, the system will retry the
                failed task until the task succeeds, or the actor has reached
                its max_restarts limit. If set to `n > 0`, the system will retry
                the failed task up to n times, after which the task will throw a
                `RayActorError` exception upon :obj:`ray.get`.  Note that Python
                exceptions may trigger retries
                *only if* `retry_exceptions` is set for the method, in that case
                when `max_task_retries` runs out the task will rethrow the
                exception from the task. You can override this number with the
                method's `max_task_retries` option in `@ray.method` decorator or
                in `.option()`.
            max_pending_calls: Set the max number of pending calls
                allowed on the actor handle. When this value is exceeded,
                PendingCallsLimitExceeded will be raised for further tasks.
                Note that this limit is counted per handle. -1 means that the
                number of pending calls is unlimited.
            max_concurrency: The max number of concurrent calls to allow for
                this actor. This only works with direct actor calls. The max
                concurrency defaults to 1 for threaded execution, and 1000 for
                asyncio execution. Note that the execution order is not
                guaranteed when max_concurrency > 1.
            allow_out_of_order_execution: Only for *actors*. Whether Ray executes actor
                tasks out of order. If you're using multi-threaded
                (``max_concurrency > 1``) or async actors, you can't set this to False.
                Defaults to True if you're using multi-threaded or async actors, and
                False otherwise. Actor task retries are always executed out of order.
            name: The globally unique name for the actor, which can be used
                to retrieve the actor via ray.get_actor(name) as long as the
                actor is still alive.
            namespace: Override the namespace to use for the actor. By default,
                actors are created in an anonymous namespace. The actor can
                be retrieved via ray.get_actor(name=name, namespace=namespace).
            lifetime: Either `None`, which defaults to the actor will fate
                share with its creator and will be deleted once its refcount
                drops to zero, or "detached", which means the actor will live
                as a global object independent of the creator.
            runtime_env (Dict[str, Any]): Specifies the runtime environment for
                this actor or task and its children. See
                :ref:`runtime-environments` for detailed documentation.
            scheduling_strategy: Strategy about how to
                schedule a remote function or actor. Possible values are
                None: ray will figure out the scheduling strategy to use, it
                will either be the PlacementGroupSchedulingStrategy using parent's
                placement group if parent has one and has
                placement_group_capture_child_tasks set to true,
                or "DEFAULT";
                "DEFAULT": default hybrid scheduling;
                "SPREAD": best effort spread scheduling;
                `PlacementGroupSchedulingStrategy`:
                placement group based scheduling;
                `NodeAffinitySchedulingStrategy`:
                node id based affinity scheduling.
            enable_task_events: True if tracing is enabled, i.e., task events from
                the actor should be reported. Defaults to True.

        Examples:

        .. code-block:: python

            @ray.remote(num_cpus=2, resources={"CustomResource": 1})
            class Foo:
                def method(self):
                    return 1
            # Class Bar will require 1 cpu instead of 2.
            # It will also require no custom resources.
            Bar = Foo.options(num_cpus=1, resources=None)
        r  NT)
in_optionsr  c                   8    e Zd Z fdZe fd            ZdS ).ActorClass.options.<locals>.ActorOptionWrapperc                 $     j         d||dS r.  r(  )rF   r   r   	actor_clsupdated_optionss      rG   rH   z5ActorClass.options.<locals>.ActorOptionWrapper.remote  s#    (y(Ud6UU_UUUrJ   c                 @    ddl m}  |j        j        ||          S )z
                For Ray DAG building that creates static graph from decorated
                class or functions.
                r   	ClassNode)rE  r  r  r  )rF   r   r   r  r  r  s       rG   rL   z3ActorClass.options.<locals>.ActorOptionWrapper.bind  s=     988888 y.=#	  rJ   Nr4  )r  r  s   rG   ActorOptionWrapperr    sc        V V V V V V      \  rJ   r  )r  rI  rJ  r   update_optionsvalidate_actor_optionsr"   )rF   r  default_optionsr  r  r  s       @@rG   r2  zActorClass.optionsZ  s    H 	 /4466 	0$777*9]
 
 	/DQQQQ M))-P.. .OM*	 	 	 	 	 	 	 	 	 	 	& "!###rJ   Nc                 :   |                     d          }|                     d          }|Jt          |t                    s t          dt	          |           d          |dk    rt          d          |$t          j        j        	                    |           |                     d          rx	 t          j
        ||	          S # t
          $ rT |                                }d
|d<   	  | j        ||fi |cY S # t          $ r Y nw xY wt          j
        ||	          cY S w xY w|                    dd           |g }|i }| j        }t!          |j                  }|                     d          |rt$          nt&          j        |d<   t+                      rt-          | ||fi |S t.          j                                        D ]#\  }	}
|                     |	|
j                  ||	<   $|                    dd           |d         }|d         }|d         }|d         }|d         }|d         }|d         }|d         }|d         }|d         }|                     d          }|t          |t6                    st9          |d           t          j        j        j        }|                                 |j         t          j        j        j!        k    rddl"m#} |$                    d           |C	 t          j
        ||	           t          d| d| d| d| d	          # t
          $ r Y nw xY w|d}n!|d k    rd!}n|d"k    rd
}nt          d#          |j         t          j%        k    r|j&        r
J d$            |j&        s^|j'        |j(        k    rN|j)        *                    |j        |j+        |j,        j-        .                                           |j(        |_'        t          j/        j        0                    |          }tc          |.                                          2                    d%d&h          s-|3                    d't&          j4                   t&          j5        }n,|3                    d't&          j6                   t&          j7        }i }|d(v sJ |d)k    r$|                                }|d'xx         d)z  cc<   |j&        rtq          j9        |||          }n(|j,        j:        d*         }tw          j<        |||          }|duot          |t6                    }|dk    p|d+k    }|r|r|rtz          >                    d,           |t          |t6                    rht          |t6                    r|j?        }|j@        }|jA        }||jB        }t          |||||jD        |-          }|jE        st7          |||          }nd.}d} |t          |d
d!/          } i }!|jG        g |_G        |jG        D ]}"|"|jG        |"         g d0|!|"<   |j,        jH        D ]b}#|j,        jH        |#         }"|"|!v sJ |j+        jI        }$|j+        jD        }%|!|"         d1         J                    t          |$|#|%                     c|j&        rsd2}&|jL        t          jN        k    r|j+        jO        }&tq          jP        |jL        |j+        |&t          t          |          t          |          z                       |_+        |                     d3          }'|'|p|d)k    }'|r|'st          d4          |d)k    r|'st          d5          |jR        S                    |jL        |j+        |||||||||nd||nd|t          |          | pd6|!pt                      ||||                     d7          |                     d8          |                     d9          |'|jU        :          }(t          rt          |j+        ||           t          |jL        |(|||j,        jX        |j,        jY        |j,        j:        |j,        jZ        |j,        j[        |j,        j\        |j,        j]        |j,        j^        |jU        |j,        j_        ||j+        |j(        d!|';          })|)S )<a=  Create an actor.

        This method allows more flexibility than the remote method because
        resource requirements can be specified and override the defaults in the
        decorator.

        Args:
            args: The arguments to forward to the actor constructor.
            kwargs: The keyword arguments to forward to the actor constructor.
            **actor_options: Keyword arguments for configuring the actor options.
                See ``ActorClass.options`` for more details.

        Returns:
            A handle to the newly created actor.
        r  	namespaceNz%name must be None or a string, got: 'z'.r7  z%Actor name cannot be an empty string.get_if_exists)r  Fr  max_concurrencylifetimer  placement_groupplacement_group_bundle_index#placement_group_capture_child_tasksr  r  r   max_pending_callsr      r   )	usage_libcorez	The name z (namespace=z_) is already taken. Please use a different name or get the existing actor using ray.get_actor('z', namespace='z')detachedTnon_detachedzOactor `lifetime` argument must be one of 'detached', 'non_detached' and 'None'.z5Cross language ActorClass cannot be executed locally.r  r  CPU)r   r   r   r  r?  zScheduling a restartable detached actor with a placement group is not recommended because Ray will kill the actor when the placement group is removed and the actor will not be able to be restarted.)r  DEFAULT)is_job_runtime_env	serialize)r  r  function_descriptorsr  z<init>allow_out_of_order_executionzIf you're using async actors, Ray can't execute actor tasks in order. Set `allow_out_of_order_execution=True` to allow out-of-order execution.zIf you're using multi-threaded actors, Ray can't execute actor tasks in order. Set `allow_out_of_order_execution=True` to allow out-of-order execution.z{}_labelsr  r  )extension_dataserialized_runtime_env_infoconcurrency_groups_dictr  r  r   labelsr  r  r  r  )original_handler  )`r6  rd  r  r!  rq  ra  rX  rY  utilsvalidate_namespace	get_actorrI  r)  r'   rJ  r  r   r  r   r   DEFAULT_MAX_CONCURRENCY_THREADEDr   r   r   r  r  r  r,   r   rZ  r[  check_connectedmodeWORKER_MODEray._common.usager  record_library_usage
LOCAL_MODEr  r  current_cluster_and_jobfunction_actor_managerexport_actor_classr  r  r  keys_commonresources_from_ray_optionsr  
difference
setdefault!DEFAULT_ACTOR_CREATION_CPU_SIMPLEDEFAULT_ACTOR_METHOD_CPU_SIMPLE$DEFAULT_ACTOR_CREATION_CPU_SPECIFIED"DEFAULT_ACTOR_METHOD_CPU_SPECIFIEDr   _format_argsr  r   flatten_argsr  r  r  r  r  -should_capture_child_tasks_in_placement_groupr+   rr  is_emptyr!   r  r  module_namerN  r%   r  r   CPPfunction_name)_get_function_descriptor_for_actor_methodr   core_workercreate_actorrM  r  _actor_launch_hookr  r  r  r   r   r   r   r   r  )*rF   r   r   r  r  r  r  meta
is_asyncior  r  r  r  r  r  r  r  r  r  r   r  r   rZ  r  r  r  actor_method_cpuactor_placement_resourcescreation_argsfunction_signatureuse_placement_groupis_restartabler  r  cg_namer   r  rr  	func_namer  actor_idr  s*                                             rG   r)  zActorClass._remote  s
   $   ((!%%k22	dC(( J VT

 V V VWWW !HIII L11)<<< _-- 	@@}TY???? 
@ 
@ 
@"/"4"4"6"6380'4<fHHHHHHH.   D }TY??????
@ 	.555<D>F$&t':;;
.//7 D--"C +, &'' 	R,T4QQ=QQQ %288:: 	E 	EDAq,00AODDM! 	.555 ((9: ,#M2'(9:'45S'T$.;1/
+ ,,AB$^4();<)*=> +../CDD&j!A/
 /
& 6mQGGG$2   ;#,-999333333**6222 
di8888 .H H H) H H '+H H ;DH H H       HH##HH''HH-   ;#.((*G GFG G* % 	N,0NNN )<<#7 (--//  
 06/MD,K%@@OO	 9>>##$$//;P0QRR 	P   (WXXX,L
   }I    -O
 %'!6))))q  (1(8(8%%e,,,1,,,! 	U*7fMMMM!%!1!<Z!H%23EtVTTM1= 
*!AC
 C
 &)?\R-? 	8 	 	 NN/   &*!A+
 +
& -/OPP "5"E'D - (K 4 3:H 4 J3,) /  O #+ 0&F#07' '## '0#&*#"*>#(+ + +' #%"*&(D#. 	 	G#'#:7#C(*0 0#G,,  +I 	 	K&D[QG55555AMK@KJ#G,-CDKK(k:NN   
 ! 	 I},, CQ	HM;D		CKK/00	  3 (5'8'89W'X'X$ (/+5+L19L( 	: 	   q  )E *   %22M3%$DD"".IIB/00(C(Kt$;$Etvv/ 31 $$Y//(,,-=>>+//0CDD)E$($@1 3 
 
6  	7DW   #M0''(--?/(<3* )E'
 
 
, sH   3C	 	#D'-C>;D'>
DD'
DD'&D'8L* *
L76L7c                 H    ddl m}  || j        j        ||| j                  S )zk
        For Ray DAG building that creates static graph from decorated
        class or functions.
        r   r  )rE  r  r  r  r  )rF   r   r   r  s       rG   rL   zActorClass.bindP  s<     	100000y!0$@U
 
 	
rJ   )r@   r  )NN)rM   rN   rO   r  r  r#  r  r  r  
ActorProxyr1   rH   r2  r   r/   r)  r)   rL   rD   rJ   rG   r  r    s        
 
 
B
 
 
  B B [BH   [6OA O O O OI$ I$ I$ I$V g g*Q- g g g  ^gR 	
 	
 \	
 	
 	
rJ   r  c                   P   e Zd ZdZ	 	 	 d+dee         dedeeef         deee	ee
d         f         f         d	eeef         d
eee	eeef         f         deeef         deeef         dedeeef         dededee         fdZd Z	 	 	 	 	 	 	 	 	 	 d,dedee         deeef         dedee	ee
d         f                  dede	eeef         dee         dee         dee         dee         fdZded efd!Zd" Zd# Zd$ Zd% Zed&             Zd' Zd( Zed-defd)            Zd* ZdS ).r  a  A handle to an actor.

    The fields in this class are prefixed with _ray_ to hide them from the user
    and to avoid collision with actor method names.

    An ActorHandle can be created in three ways. First, by calling .remote() on
    an ActorClass. Second, by passing an actor handle into a task (forking the
    ActorHandle). Third, by directly serializing the ActorHandle (e.g., with
    cloudpickle).

    Attributes:
        _ray_actor_language: The actor language.
        _ray_actor_id: Actor ID.
        _ray_enable_task_events: The default value of whether task events is
            enabled, i.e., task events from the actor should be reported.
        _ray_method_is_generator: Map of method name -> if it is a generator
            method.
        _ray_method_decorators: Optional decorators for the function
            invocation. This can be used to change the behavior on the
            invocation side, whereas a regular decorator can be used to change
            the behavior on the execution side.
        _ray_method_signatures: The signatures of the actor methods.
        _ray_method_max_task_retries: Max number of retries on method failure.
        _ray_method_num_returns: The default number of return values for
            each method.
        _ray_method_retry_exceptions: The default value of boolean of whether you want
            to retry all user-raised exceptions, or a list of allowlist exceptions to
            retry.
        _ray_method_generator_backpressure_num_objects: Generator-only
            config. The max number of objects to generate before it
            starts pausing a generator.
        _ray_method_enable_task_events: The value of whether task
            tracing is enabled for the actor methods. This overrides the
            actor's default value (`_ray_enable_task_events`).
        _ray_method_name_to_tensor_transport: A dictionary mapping method names to their tensor transport protocol settings.
            The valid values are OBJECT_STORE (default), NCCL, or GLOO, and they are case-insensitive.
        _ray_actor_method_cpus: The number of CPUs required by actor methods.
        _ray_original_handle: True if this is the original actor handle for a
            given actor. If this is true, then the actor will be destroyed when
            this handle goes out of scope.
        _ray_weak_ref: True means that this handle does not count towards the
            distributed ref count for the actor, i.e. the actor may be GCed
            while this handle is still in scope. This is set to True if the
            handle was created by getting an actor by name or by getting the
            self handle. It is set to False if this is the original handle or
            if it was created by passing the original handle through task args
            and returns.
        _ray_is_cross_language: Whether this actor is cross language.
        _ray_actor_creation_function_descriptor: The function descriptor
            of the actor creation task.
        _ray_allow_out_of_order_execution: Whether the actor can execute tasks out of order.
        _ray_enable_tensor_transport: Whether tensor transport is enabled for this actor.
    FNr   r   r  method_num_returnsr   method_max_task_retriesmethod_retry_exceptions)method_generator_backpressure_num_objectsmethod_enable_task_eventsr  r  actor_method_cpusweak_refr  c                 V   || _         || _        || _        || _        || _        || _        || _        || _        || _        || _	        || _
        |	| _        |
| _        || _        || _        || _        || _        || _        || _        |t&          j        k    | _        || _        i | _        d| _        | j        s\t3          |t4                    sJ |j        }|j        }| j	                                        D ]}t5          |||          }|| j        |<   i | _        | j	                                        D ]\  }}tA          || j
        !                    |d          | j        !                    || j                  pd| j        !                    |          | j        !                    |          | j        !                    |          | j        !                    || j                  | j        !                    |          || j        !                    |          
  
        | j        |<   dS )a  Initialize an ActorHandle.

        Args:
            language: The actor language.
            actor_id: The ID of the actor.
            max_task_retries: The maximum number of times to retry a task when it fails.
            enable_task_events: Whether task events should be enabled for this actor.
            method_is_generator: Dictionary mapping method names to whether they are generator methods.
            method_decorators: Dictionary mapping method names to their decorators.
            method_signatures: Dictionary mapping method names to their signatures.
            method_num_returns: Dictionary mapping method names to their number of return values.
            method_max_task_retries: Dictionary mapping method names to their maximum task retries.
            method_retry_exceptions: Dictionary mapping method names to their retry exception settings.
            method_generator_backpressure_num_objects: Dictionary mapping method names to their generator backpressure settings.
            method_enable_task_events: Dictionary mapping method names to whether task events are enabled.
            enable_tensor_transport: Whether tensor transport is enabled for
                this actor. If True, then methods can be called with
                .options(tensor_transport=...) to specify a non-default tensor
                transport.
            method_name_to_tensor_transport: Dictionary mapping method names to their tensor transport type.
            actor_method_cpus: The number of CPUs required by actor methods.
            actor_creation_function_descriptor: The function descriptor for actor creation.
            cluster_and_job: The cluster and job information.
            original_handle: Whether this is the original actor handle.
            weak_ref: Whether this is a weak reference to the actor.
            allow_out_of_order_execution: Whether the actor can execute tasks out of order.
        r   N)
r   r   r   r   r   r   r   r   r   r   )"_ray_actor_language_ray_actor_id_ray_max_task_retries_ray_original_handle_ray_weak_ref_ray_enable_task_events!_ray_allow_out_of_order_execution_ray_method_is_generator_ray_method_decorators_ray_method_signatures_ray_method_num_returns_ray_method_max_task_retries_ray_method_retry_exceptions._ray_method_generator_backpressure_num_objects_ray_method_enable_task_eventsrb  $_ray_method_name_to_tensor_transport_ray_actor_method_cpus_ray_cluster_and_jobr   r  _ray_is_cross_language'_ray_actor_creation_function_descriptor_ray_function_descriptorrG  rd  r%   r  rr  r  _method_shellsr  r   r6  )rF   r  r*  r   r   r  method_decoratorsmethod_signaturesr.  r/  r0  r1  r2  r  r  r3  r  cluster_and_jobr  r4  r  r  rr  r   function_descriptormethod_signatures                             rG   r  zActorHandle.__init__  s   d $, %%5"$3!%'9$1M.(;%&7#&7#'9$,C),C)5 	; /H+,C)4S1&7#$3!&.(/&A#. 	4 )+%
 $% * 
	Q24L     =HK;FJ#:??AA Q Q&>j' '# >Q-k::
 !-1-H-N-N-P-P 	 	)K)/C' 8<<[$OO!%!B!F!F!;" " " !%!B!F!F{!S!S!:>>{KK373f3j3j4 4 $(#F#J#J!=$ $ 599+FF*!%!J!N!N" "#0 0 0D,,	 	rJ   c                    | j         rd S 	 t          j        j        rNt          j        j        j        }|j        r3t          |d          r%|j                            | j	                   d S d S d S d S # t          $ r Y d S w xY w)Nr  )r:  rX  rY  rZ  r[  	connectedr  r  remove_actor_handle_referencer7  AttributeErrorrF   rZ  s     rG   __del__zActorHandle.__del__  s      	F	 |" Y,:# Y(F(F Y&DDTEWXXXXXY YY Y Y Y 	 	 	 DD		s   AA0 0
A>=A>r7  r   r   r   r  r   r   rW  r   r   c                 p   t           j        j        j        }|pg }|pi }| j        rct          j        |||          }t          j        | j        | j	        |t          t          |          t          |          z                       }n9| j        |         }|s|s|sg }nt          j        |||          }| j        |         }|j        t           j        k    r| j        r
J d            |dk    rd}n|dk    rt           j        j        }d}|d}n-t)          |t*          t,          f          rt-          |          }d}t)          |t.                    s
J d	            |	d}	t0          j        }|!|t0          j        j        k    rt0          j        }|j                            | j        | j        |||||||| j        ||nd
|	|
|j                   }|t&          k    r-t          |          dk    sJ |d         }tC          ||          S t          |          dk    r	|d         }nt          |          dk    rd}|S )aw  Method execution stub for an actor handle.

        This is the function that executes when
        `actor.method_name.remote(*args, **kwargs)` is called. Instead of
        executing locally, the method is packaged as a task and scheduled
        to the remote actor instance.

        Args:
            method_name: The name of the actor method to execute.
            args: A list of arguments for the actor method.
            kwargs: A dictionary of keyword arguments for the actor method.
            name: The name to give the actor method call task.
            num_returns: The number of return values for the method.
            max_task_retries: Number of retries when method fails.
            retry_exceptions: Boolean of whether you want to retry all user-raised
                exceptions, or a list of allowlist exceptions to retry.
            concurrency_group_name: The name of the concurrency group to use.
            generator_backpressure_num_objects: The number of objects to generate
                before applying backpressure.
            enable_task_events: True if tracing is enabled, i.e., task events from
                the actor should be reported.
            tensor_transport: The tensor transport protocol to use for the actor method.

        Returns:
            object_refs: A list of object refs returned by the remote actor
                method.
        )r   z>Cross language remote actor method cannot be executed locally.dynamicr?  r   NFTzTretry_exceptions can either be             boolean or list/tuple of exception types.rJ   r   r   )"rX  rY  rZ  r[  rH  r   r  r  r6  rI  r  r   r?  r   r  rJ  r  r  _rayletr#   rd  r  r  r  r   r  r  DIRECT_TRANSPORTr  submit_actor_taskr7  rF  valuer$   )rF   r   r   r   r  r   r   r   rW  r   r   r   rZ  	list_argsrO  r%  retry_exception_allowlisttensor_transport_enumrf  generator_refs                       rG   r^  zActorHandle._actor_method_call"  s   R $2zr2& 	M&3FD&III"0"Z(< c$ii#f++566# # # "&!<[!I U U/A U		%23EtVTT	"&"?"L;#.((/P POP P/ )##KKK'' +@K$(!#$(4-88 	$(-.>(?(?%#d
 
 	7 	77	7 	7 

 .513. 3 @( $7$D$III$7$H!(::$%'&<&H""c.!'
 
" 444 {##q(((('NM%mV<<<{q  %a.KK""KrJ   itemr@   c                 |   | j         v r | j                                      |           S | j        s(t          dt	          |           j         d d          dv r G fddt                    } |            S t          | t          j	        ddd| j
                            d          | j        d	d	

  
        S )a  Handle dynamic attribute access for actor methods.

        This method is called when accessing attributes that don't exist as direct
        instance attributes. It's the core mechanism for actor method invocation.

        For Python actors (99% of cases):
        - We use strict validation: only methods in _method_shells are allowed
        - This prevents typos and provides clear error messages
        - Returns a bound ActorMethod created from the cached _ActorMethodMetadata

        For cross-language actors:
        - We can't validate method names client-side (the target language defines them)
        - We allow arbitrary method calls to pass through
        - Some Python-specific methods like `__ray_terminate__` are blocked with warnings

        Args:
            item: The attribute/method name being accessed

        Returns:
            ActorMethod: A bound method ready for .remote() calls

        Raises:
            AttributeError: For Python actors when accessing non-existent methods
        'z' object has no attribute ')__ray_terminate__c                   $    e Zd Z fdZ fdZdS )0ActorHandle.__getattr__.<locals>.FakeActorMethodc                 J    t          d                                        )NzdActor methods cannot be called directly. Instead of running 'object.{}()', try 'object.{}.remote()'.)r!  formatrF   r   r   ra  s      rG   r#  z9ActorHandle.__getattr__.<locals>.FakeActorMethod.__call__  s1    #NNTf $O O  rJ   c                 D    t                               d d           d S )NzActor method z$ is not supported by cross language.)r  r  ri  s      rG   rH   z7ActorHandle.__getattr__.<locals>.FakeActorMethod.remote  s1    NNRRRR    rJ   N)rM   rN   rO   r#  rH   )ra  s   rG   FakeActorMethodrf    sG                  rJ   rk  r   Fr?  N)r   r   )rK  rL   rH  rT  rq  rM   objectr  r  r  rC  r6  r;  )rF   ra  rk  s    ` rG   __getattr__zActorHandle.__getattr__  s   4 4&&&&t,11$777* 	 ODJJ'OOOOO   (((      &    #?$$$>?CCD"MM(
 
 
 	
rJ   c                 4    | j                                         S rC   )r?  r  rE   s    rG   __dir__zActorHandle.__dir__  s    *//111rJ   c                 V    d| j         j         d| j                                         dS )NzActor(z, r  )rI  rr  	_actor_idhexrE   s    rG   __repr__zActorHandle.__repr__  s?    ';F' '~!!##' ' '	
rJ   c                 *    t          | j                  S rC   )hashrq  rE   s    rG   __hash__zActorHandle.__hash__  s    DN###rJ   c                 B    t          |           t          |          k    S rC   )ru  )rF   _ActorHandle__values     rG   __eq__zActorHandle.__eq__  s    DzzT']]**rJ   c                     | j         S rC   )r7  rE   s    rG   rq  zActorHandle._actor_id  s    !!rJ   c                     t           j        j        j        }|                                 |j                            | j                  S )a@  Get the local actor state.

        NOTE: this method only returns accurate actor state
        after a first actor method call is made against
        this actor handle due to https://github.com/ray-project/ray/pull/24600.

        Returns:
           ActorTableData.ActorState or None if the state is unknown.
        )rX  rY  rZ  r[  r  r  get_local_actor_stater7  rU  s     rG   _get_local_statezActorHandle._get_local_state  s=     $2   !778JKKKrJ   c                    t           j        j        j        }|                                 t          |d          r |j                            | j                  }ni d| j	        d| j        d| j
        d| j        d| j        d| j        d| j        d	| j        d
| j        d| j        d| j        d| j        d| j        d| j        d| j        d| j        df}g || j        R S )zThis is defined in order to make pickling work.

        Returns:
            A dictionary of the information needed to reconstruct the object.
        r  actor_languager*  r   r   r  rL  rM  r.  r/  r0  r1  r2  r  r  r3  r  N)rX  rY  rZ  r[  r  r  r  serialize_actor_handler7  r6  r8  r  r=  r>  r?  r@  rA  rB  rC  rD  rb  rE  rF  rI  r:  )rF   rZ  rk  s      rG   _serialization_helperz!ActorHandle._serialization_helper	  sg    $2   6=)) 	&==d>PQQEE$d&> 2 '(B )$*B	
 *4+H ()D ()D )$*F .t/P .t/P @K 01T .t/P  6t7`!" ()D#$ 9$:f%( +E0 ,+*+++rJ   c                    t           j        j        j        }|                                 t          |d          r|j                            |||          S |j        |d         k    sJ  | |d         |d         |d         |d         |d         |d         |d	         |d
         |d         |d         |d         |d         |d         |d         |d         |d         |d                   S )a  This is defined in order to make pickling work.

        Args:
            state: The serialized state of the actor handle.
            outer_object_ref: The ObjectRef that the serialized actor handle
                was contained in, if any. This is used for counting references
                to the actor handle.
            weak_ref: Whether this was serialized from an actor handle with a
                weak ref to the actor.

        r  r	  r  r*  r   r   r  rL  rM  r.  r/  r0  r1  r2  r  r  r3  r  )	rX  rY  rZ  r[  r  r  r  %deserialize_and_register_actor_handler	  )rw  rk  r4  outer_object_refrZ  s        rG   _deserialization_helperz#ActorHandle._deserialization_helper,	  s#    $2   6=)) 	%KK    1U;T5UUUUU3 &'j!()*++,)*)**+/0/0AB12/078)*:;/0'  rJ   c                 T    |                                  \  }}}t          j        ||dffS )z:This code path is used by pickling but not by Ray forking.N)r  r  r  )rF   
serializedr}  r4  s       rG   
__reduce__zActorHandle.__reduce__\	  s1    $($>$>$@$@!Q 2Z44PPPrJ   )FFNrm  rC   )rM   rN   rO   r  r
   r  r  r   r  r   r	   r  r  r  rV  r   r   r^  rm  ro  rs  rv  ry  propertyrq  r}  r  r  r  r  rD   rJ   rG   r  r  ]  s       4 4R 7;+x x #3-	x
 !x "#t)_x !eC1E,E&F!FGx "&c3hx "&c5tU1B+C&C!Dx 48S>x $(T	?x "&x *.c3hx  !x( )x* '/tn+x x x xt  , !%BF $5904<@-1*.| || 3i| S#X	|
 | eC)=$=>?| |  dE 12| !)| -5SM| %TN| #3-| | | ||?
 ?
 ?
 ?
 ?
 ?
D2 2 2
 
 
$ $ $+ + + " " X"L L L&, &, &,P - -d - - - [-^Q Q Q Q QrJ   r  c                     t           d          r S t           t                    st          d           G  fdd           } j        |_         j        |_        t          t          |dd                     s
d }||_        |S )Nr  zThe @ray.remote decorator cannot be applied to old-style classes. In Python 2, you must declare the class with 'class ClassName(object):' instead of 'class ClassName:'.c                   &    e Zd Z Zd Zd Zd ZdS )_modify_class.<locals>.Classc                     dS )NTrD   rE   s    rG   __ray_ready__z*_modify_class.<locals>.Class.__ray_ready__u	  s    4rJ   c                      || g|R i |S rC   rD   )rF   fnr   r   s       rG   __ray_call__z)_modify_class.<locals>.Class.__ray_call__x	  s"    2d,T,,,V,,,rJ   c                     t           j        j        j        }|j        t           j        k    r t           j                                         d S d S rC   )rX  rY  rZ  r[  r  r  r  
exit_actorrU  s     rG   rd  z._modify_class.<locals>.Class.__ray_terminate__{	  s@    \(6F{cn,,	$$&&&&& -,rJ   N)rM   rN   rO   r  r  r  rd  rv  s   rG   Classr  r	  sH        !	 	 		- 	- 	-	' 	' 	' 	' 	'rJ   r  r  c                     d S rC   rD   rE   s    rG   r  z_modify_class.<locals>.__init__	  s    DrJ   )	r  
issubclassrl  r!  rN   rM   r   r{  r  )rw  r  r  s   `  rG   _modify_classr  d	  s    s)** 
 c6"" 
H
 
 	
' ' ' ' ' ' ' ' ' ' ~E\EN 
D!A!ABB "
	 	 	 "LrJ   c                     t          |           }t          |           d|v r/|d         dk    r#t          |d         t          j                  |d<   t
                              |t          j                    |          S )Nr  r?  )	r  r.   minr  MAX_INT64_VALUEr  r  r   from_random)rw  r  r  s      rG   _make_actorr  	  s    #Eu%%%&&(B.. -0n-}/L- -M.) .. ""  rJ   c                  \   t           j        j        j        } | j        t           j        k    rj| j                                        sQ| j        	                                 | j        
                                rt                      t          d           dS t          d| j         d          )aT  Intentionally exit the current actor.

    This API can be used only inside an actor. Use ray.kill
    API if you'd like to kill an actor using actor handle.

    When this API is called, an exception is raised and the actor
    will exit immediately. For asyncio actors, there may be a short
    delay before the actor exits if the API is called from a background
    task.
    Any queued methods will fail. Any ``atexit``
    handlers installed in the actor will be run.

    Raises:
        TypeError: An exception is raised if this is a driver or this
            worker is not an actor.
    zexit_actor() is called.z0exit_actor API is called on a non-actor worker, zR. Call this API inside an actor methodsif you'd like to exit the actor gracefully.N)rX  rY  rZ  r[  r  r  r*  is_nilr  set_current_actor_should_exitcurrent_actor_is_asyncior(   r&   r!  )rZ  s    rG   r  r  	  s    $ \ .F{co%%fo.D.D.F.F%88::: 6688 	%"$$$ 	11JKKKKK:{: : :
 
 	
rJ   )zr  loggingtypingr   r   r   r   r   r   r	   r
   r   r   r   r   r   r   ImportErrortyping_extensionsray._common.signaturer  r   ray._private.ray_constantsrY  r  ray._rayletrX  r   r   r   r   ray._commonr   ray._common.ray_constantsr   ray._common.ray_option_utilsr   ray._private.async_compatr   ray._private.auto_init_hookr   ray._private.client_mode_hookr   r   r   ray._private.custom_typesr   ray._private.inspect_utilr   r   r    ray._private.utilsr!   r"   r#   r$   r%   r&   ray.exceptionsr'   r(   ray.util.annotationsr)   r*   ray.util.placement_groupr+   ray.util.scheduling_strategiesr,   r-   ray.util.tracing.tracing_helperr.   r/   r0   	getLoggerrM   r  r  r1   rq  r,  r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r?   rQ   rX   ra   rj   rt   r   r   r   r   r   r   r  r  r  r  r  r   r  rl  ro  r  r!  r  r  r  r  r  r  r  rD   rJ   rG   <module>r     sx                               9--------- 9 9 988888888889 * ) ) ) ) ) ) ) ) 2 2 2 2 2 2 2 2 2     A A A A A A A A A A A A ( ( ( ( ( ( C C C C C C R R R R R R 7 7 7 7 7 7 6 6 6 6 6 6         
              
 Y X X X X X X X            E D D D D D D D 8 8 8 8 8 8 8 8 P P P P P P                  			8	$	$   GCLL #T!W,-
wvYt__genngenngenngenngenngenngenngenngenngenn    '$-       WT3Y'       WT3^,   
 
 
 
 
WT3S01 
 
 
    WT3S#56       WT3S#s:;   "    WT3S#sC?@   0    WT3S#sCDE   4    WT3S#sCcIJ   8    WT3S#sCc3NO   <    WT3S#sCc3PSST   @ 
Sz4'(D#I   
 
S#,-D#sN#   
 
S#s+T12D#sC'(   
 
S#sC0$67D#sC,-   
 
S#sC5t;<D#sCc12   
 
S#sCc:D@AD#sCc367   
 
S#sCc3?EFD#sCc3;<   
 
S#sCc3DdJKD#sCc3S@A   
 
S#sCc3SI4OPD#sCc3S#EF   
 
S#sCc3S#NPTTUD#sCc3S#sJK   
 
ud{#   
 
 ?C'+&*;?9=)-6:
 
 
%W[%9 9:;
  }
 sm	

 uT4%678
 *2#
 !
 23
 xCG,d234c9:
 
 
 

 m m  m`J
 J
 J
 J
 J
 J
 J
 J
^ S
 S
 S
 S
 S
 S
 S
 S
l
H H H H H H H HVT? T? T? T? T? T? T? T?n 	 	 	 	 	Y 	 	 	$ $ $N i

 i

 i

 i

 i

 i

 i

 i

X CQ CQ CQ CQ CQ'!* CQ CQ CQL) ) )X  & "
 "
 "
 "
 "
s   / ??