
    %`i9                        U d Z ddlZddlmZ ddlmZmZmZmZm	Z	m
Z
 ddlZddlmZ ddlmZmZ ddlmZ ddlmZ dd	lmZmZmZ e G d
 d                      ZdKdededefdZd ZdLdedefdZdeeeef                  dee         fdZ i d ee! e"d          fd           d ee# e"d          fd           d ee e"d          f          d ed          d ee e"d          f          d ed          d ed          d edd          d  e e"d          eefd!"          d# ee$d$"          d% ee e"d          f          d ee! e"d          fd&           d' ee! e"d          f          d( e e"d          eeeef          d) eed"          d* ee! e"d          f          Z%d+ed,e"defd-Z& ed.dd"           ed/ej'        "           edd0"           ee$e e"d          fd1 d"           ee$ e"d          fd2            eee#e(fd3 d"           ee$ e"d          fd4           d5Z) ee#e! e"d          f           ee e"d          fd"           ee e"d          fd6            ed7d           ed8d"           ed9d"           ed:d$"           ee e"d          f           eed"           ee e"d          f          d;
Z*i e)e*e%Z+eeef         e,d<<   i e%e)Z-eeef         e,d=<   i e%e*Z.eeef         e,d><   d? e#e+/                                           d@Z0dAeeef         fdBZ1dAeeef         dCe$fdDZ2dAeeef         dEefdFZ3dAeeef         dEefdGZ4dHeeef         dIeeef         deeef         fdJZ5dS )MzKManage, parse and validate options for Ray tasks, actors and actor methods.    N)	dataclass)AnyCallableDictOptionalTupleUnion)ray_constants)validate_fallback_strategyvalidate_label_selector)get_ray_doc_version)PlacementGroup)NodeAffinitySchedulingStrategyNodeLabelSchedulingStrategy PlacementGroupSchedulingStrategyc                       e Zd ZU dZeeeee         f                  ed<   dZ	ee
egee         f                  ed<   dZeed<   dedefdZdS )OptionNtype_constraintvalue_constraintdefault_valuekeywordvaluec           
          | j         ?t          || j                   s*t          d| d| j          dt          |                     | j        &|                     |          }|rt          |          dS dS )zValidate the option.NzThe type of keyword 'z
' must be z, but received type )r   
isinstance	TypeErrortyper   
ValueError)selfr   r   possible_error_messages       p/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/_common/ray_option_utils.pyvalidatezOption.validate    s    +eT%9:: 7G 7 7t?S 7 7)-e7 7    ,%)%:%:5%A%A"% 9 !7888 -,9 9    )__name__
__module____qualname__r   r   r	   r   r   __annotations__r   r   r   strr   r!    r"   r    r   r      s          ;?OXeD%+$567>>> BFhxx}(<=>EEEM39 9C 9 9 9 9 9 9r"   r   Tnameinfiniter   c                      |r)t          t          t          d          f fd|          S t          t          t          d          f fd|          S )a  This is used for positive and discrete options.

    Args:
        name: The name of the option keyword.
        infinite: If True, user could use -1 to represent infinity.
        default_value: The default value for this option.

    Returns:
        An Option object.
    Nc                 $    | | dk    rd nd dS )NThe keyword 'zO' only accepts None, 0, -1 or a positive integer, where -1 represents infinity.r(   xr)   s    r    <lambda>z"_counting_option.<locals>.<lambda><   s6    	Q"WW dD D D D r"   r   c                 $    | | dk    rd nd dS )Nr   r.   z-' only accepts None, 0 or a positive integer.r(   r/   s    r    r1   z"_counting_option.<locals>.<lambda>D   s*    Ia $PTPPP r"   )r   intr   )r)   r*   r   s   `  r    _counting_optionr5   .   s      
$t**D D D D (
 
 
 	
 	d4jj	Q 	Q 	Q 	Q $   r"   c                    |dk     rd|  dS t          |t                    r1|dk    r+t          |t          j        j        z            dk    rd|  dS | dk    rdn| }|t          j        j                                        v r>t          j        j        	                    |          
                    |          \  }}|s|S d S )	Nr   zThe quantity of resource z cannot be negativeg        z5The precision of the fractional quantity of resource z cannot go beyond 0.0001num_gpusGPU)r   floatr4   ray_rayletRESOURCE_UNIT_SCALING_privateaccelerators"get_all_accelerator_resource_names$get_accelerator_manager_for_resource"validate_resource_request_quantity)r)   quantityresource_namevaliderror_messages        r    _validate_resource_quantityrF   K   s    !||D4DDDD8U##
OO3;<<==BB'D ' ' '	
 "Z//EETM1TTVVVV L%JJ
 

,
,
 
	
  	!  4r"   c                 b     t          t          t          t          d          f fd|          S )z*This is used for resource related options.Nc                 ,    | d nt          |           S N)rF   r/   s    r    r1   z"_resource_option.<locals>.<lambda>j   s    19$$+FtQ+O+O r"   r2   )r   r9   r4   r   )r)   r   s   ` r    _resource_optionrJ   f   s9    	T$ZZ OOOO#   r"   	resourcesreturnc                     | d S d| v sd| v r	 dS |                                  D ]\  }}t          ||          }|r|c S d S )NCPUr8   z[Use the 'num_cpus' and 'num_gpus' keyword instead of 'CPU' and 'GPU' in 'resources' keyword)itemsrF   )rK   r)   rB   r   s       r    _validate_resourcesrP   o   s    t	Ui//%	
 	

 $//++ * *h!<T8!L!L! 	*))))	* 4r"   label_selectorc                      t          |           S rI   )r   r0   s    r    r1   r1      s    ;RST;U;U r"   fallback_strategyc                      t          |           S rI   )r   rS   s    r    r1   r1      s    &@&C&C r"   accelerator_typememorynum_cpusr7   object_store_memoryFplacement_groupdefaultr2   placement_group_bundle_indexr-   #placement_group_capture_child_tasksc                      t          |           S rI   )rP   rS   s    r    r1   r1      s    6I!6L6L r"   runtime_envscheduling_strategyenable_task_events_labelsobjcls_c                 F    	 t          | |          S # t          $ r Y dS w xY w)NF)
issubclassr   )rc   rd   s     r    issubclass_saferg      s9    #t$$$   uus    
  	max_callsmax_retries   c                 2    | | dk    s| dk    s| dk    rd ndS )Ndynamic	streamingr   ag  Default None. When None is passed, The default value is 1 for a task and actor task, and 'streaming' for generator tasks and generator actor tasks. The keyword 'num_returns' only accepts None, a non-negative integer, 'streaming' (for generators), or 'dynamic'. 'dynamic' flag will be deprecated in the future, and it is recommended to use 'streaming' instead.r(   rS   s    r    r1   r1      s2    Ii1+;+;qAvv $ r"   c                     | d ndS )Nz:Setting 'object_store_memory' is not implemented for tasksr(   rS   s    r    r1   r1      s    I $I r"   c                     t          | t                    s5t          | t          t          f          rt	          d | D                       rd ndS )Nc              3   @   K   | ]}t          |t                    V  d S rI   )rg   	Exception).0x_s     r    	<genexpr>z<lambda>.<locals>.<genexpr>   s,      CC2I66CCCCCCr"   zAretry_exceptions must be either a boolean or a list of exceptions)r   boollisttupleallrS   s    r    r1   r1      s_    q$Q 1tUm,,	Q
 CCCCCCCQ$$ Q r"   c                     | dk    rd ndS )Nr   z_generator_backpressure_num_objects=0 is not allowed. Use a value > 0. If the value is equal to 1, the behavior is identical to Python generator (generator 1 object whenever `next` is called). Use -1 to disable this feature. r(   rS   s    r    r1   r1      s    66 $K r"   )rh   ri   rX   num_returnsrY   retry_exceptions#_generator_backpressure_num_objectsc                     | dv rd ndS )N)Ndetachednon_detachedzOactor `lifetime` argument must be one of 'detached', 'non_detached' and 'None'.r(   rS   s    r    r1   r1      s    222 $% r"   max_concurrencymax_restartsmax_task_retriesmax_pending_calls)
concurrency_groupsenable_tensor_transportlifetimer   r   r   r   	namespaceget_if_existsallow_out_of_order_executionvalid_optionstask_optionsactor_optionszThe @ray.remote decorator must be applied either with no arguments and no parentheses, for example '@ray.remote', or it must be applied using some of the arguments in the list zL, for example '@ray.remote(num_returns=2, resources={"CustomResource": 1})'.optionsc                     |                      dd          }|                      d          }|dvr|t          d          dS dS )z2Check if deprecated placement group option exists.rZ   r[   r`   )r[   NNzrPlacement groups should be specified via the scheduling_strategy option. The placement_group option is deprecated.)getr   )r   rZ   r`   s      r     _check_deprecate_placement_groupr     sb    kk"3Y??O!++&;<<
 	0007J7V8
 
 	
 	107V7Vr"   caller_stacklevelc                 p   | d         }| d         }| d         }|dk    r/t          j        dt                       dt          |dz              |d	k    r/t          j        d
t                       dt          |dz              |r1t          j        dt                       dt          |dz              d S d S )NrZ   r\   r]   r[   zplacement_group parameter is deprecated. Use scheduling_strategy=PlacementGroupSchedulingStrategy(...) instead, see the usage at https://docs.ray.io/en/z&/ray-core/package-ref.html#ray-remote.rj   
stacklevelr-   zplacement_group_bundle_index parameter is deprecated. Use scheduling_strategy=PlacementGroupSchedulingStrategy(...) instead, see the usage at https://docs.ray.io/en/zplacement_group_capture_child_tasks parameter is deprecated. Use scheduling_strategy=PlacementGroupSchedulingStrategy(...) instead, see the usage at https://docs.ray.io/en/)warningswarnr   DeprecationWarning)r   r   rZ   r\   r]   s        r    )_warn_if_using_deprecated_placement_groupr     s8    /0O#*+I#J *12W*X')##d ':&;&;d d d (1,	
 	
 	
 	
 $r))d ':&;&;d d d (1,	
 	
 	
 	
 + 
d ':&;&;d d d (1,	
 	
 	
 	
 	
 	

 
r"   
in_optionsc           	      &   |                                  D ]W\  }}|t          vr(t          d| dt          t                     d          t          |                             ||           X|rd| v rt          d          t          |            dS )zOptions check for Ray tasks.

    Args:
        options: Options for Ray tasks.
        in_options: If True, we are checking the options under the context of
            ".options()".
    Invalid option keyword z& for remote functions. Valid ones are .rh   z5Setting 'max_calls' is not supported in '.options()'.N)rO   r   r   rv   r!   r   r   r   kvs       r    validate_task_optionsr   ?  s      ' '1L  8! 8 8"&|"4"48 8 8   	Q  A&&&& RkW,,PQQQ$W-----r"   c           	         |                                  D ]W\  }}|t          vr(t          d| dt          t                     d          t          |                             ||           X|rd| v rt          d          |                     d          r$|                     d          st          d          d	| v r,t          j        d
t                       dt          d           t          |            dS )zOptions check for Ray actors.

    Args:
        options: Options for Ray actors.
        in_options: If True, we are checking the options under the context of
            ".options()".
    r   z for actors. Valid ones are r   r   z>Setting 'concurrency_groups' is not supported in '.options()'.r   r)   z8The actor name must be specified to use `get_if_exists`.rY   zSetting 'object_store_memory' for actors is deprecated since it doesn't actually reserve the required object store memory. Use object spilling that's enabled by default (https://docs.ray.io/en/zb/ray-core/objects/object-spilling.html) instead to bypass the object store memory size limitation.rj   r   N)rO   r   r   rv   r!   r   r   r   r   r   r   r   s       r    validate_actor_optionsr   S  sP     ( (1M!!9! 9 9"&}"5"59 9 9   	a!!!Q'''' 
*g55L
 
 	
 {{?## UGKK,?,? USTTT''I WjVkVkI I I
 	
 	
 	
 	
 %W-----r"   original_optionsnew_optionsc                     i | |S )zUpdate original options with new options and return.
    The returned updated options contain shallow copy of original options.
    r(   )r   r   s     r    update_optionsr   y  s     /.+..r"   )TNrI   )6__doc__r   dataclassesr   typingr   r   r   r   r   r	   r:   ray._privater
   ray._private.label_utilsr   r   ray._private.utilsr   ray.util.placement_groupr   ray.util.scheduling_strategiesr   r   r   r   r'   ru   r5   rF   rJ   r9   rP   dictr   rv   r4   _common_optionsrg   DEFAULT_TASK_MAX_RETRIESrw   _task_only_options_actor_only_optionsr   r&   r   r   keysremote_args_error_stringr   r   r   r   r   r(   r"   r    <module>r      s   Q Q Q  ! ! ! ! ! ! > > > > > > > > > > > > > > > > 



 & & & & & &        3 2 2 2 2 2 3 3 3 3 3 3          9 9 9 9 9 9 9 90 3 $ c    :  6 3 s    8De,<#= (3-    $ ffdDDJJ/1U1UVV 	ttDzzCC  
 TT$ZZ011  x((  FFCd$%%    ,,    ,,  ++,A5II  vv	dS.)   " #FF3b$A$A$A# $ *664d2D+E+E% & ttDzz*,L,LMM' ( 664d,--) * 66DJJ,*'	
 + < &&T:::= > vvtTT$ZZ())? F D T     "!+uAFFF $#]%K   ! 1===6	c44::		 		    "6	dd4jj	J 	J  	tU	Q 	Q    ,26	dd4jj	
 	

, 
,U5 5 p !&$dd4jj!9::%vtTT$ZZ&8MMM	dd4jj	% 	%  ('(95AA$$^1EEE(();1MMM))*=RPPPdd4jj)**VD666$*FD$$t**+=$>$>!  0$$$ $tCK     #L_"K8J"Kd3; K K K#Mo#M9L#MtCK  M M MG!%m&8&8&:&:!;!;G G G 
d38n 
 
 
 
  
#s(^ 
03 
  
  
  
F.4S> .t . . . .(#.DcN #. #. #. #. #.L/38n/37S>/	#s(^/ / / / / /r"   