
    &`i                     B   d dl mZmZmZmZ d dlmZ d dlmZ erd dl	m
Z
 e G d d                      Ze G d d                      Zd	 Z ed
           G d d                      Z ed
           G d d                      Z ed
           G d d                      Z ed
           G d d                      Z G d d          Zeeeeeeef         f         Z ed
           G d d                      ZdedefdZedeeeef         ZdS )    )TYPE_CHECKINGDictOptionalUnion)NodeID)	PublicAPI)PlacementGroupc                   8    e Zd ZdZ	 	 d	dddedee         fdZdS )
 PlacementGroupSchedulingStrategya4  Placement group based scheduling strategy.

    Attributes:
        placement_group: the placement group this actor belongs to,
            or None if it doesn't belong to any group.
        placement_group_bundle_index: the index of the bundle
            if the actor belongs to a placement group, which may be -1 to
            specify any available bundle.
        placement_group_capture_child_tasks: Whether or not children tasks
            of this actor should implicitly use the same placement group
            as its parent. It is False by default.
    Nplacement_groupr	   placement_group_bundle_index#placement_group_capture_child_tasksc                 0    || _         || _        || _        d S N)r   r   r   )selfr   r   r   s       r/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/util/scheduling_strategies.py__init__z)PlacementGroupSchedulingStrategy.__init__   s"      /,H)3V000    )r   N)__name__
__module____qualname____doc__intr   boolr    r   r   r   r      si           -/>B	W W)W '*W .6d^	W W W W W Wr   r   c            	       6    e Zd ZdZ	 	 d
dedededefdZd Zd	S )NodeAffinitySchedulingStrategya)  Static scheduling strategy used to run a task or actor on a particular node.

    Attributes:
        node_id: the hex id of the node where the task or actor should run.
        soft: whether the scheduler should run the task or actor somewhere else
            if the target node doesn't exist (e.g. the node dies) or is infeasible
            during scheduling.
            If the node exists and is feasible, the task or actor
            will only be scheduled there.
            This means if the node doesn't have the available resources,
            the task or actor will wait indefinitely until resources become available.
            If the node doesn't exist or is infeasible, the task or actor
            will fail if soft is False
            or be scheduled somewhere else if soft is True.
    Fnode_idsoft_spill_on_unavailable_fail_on_unavailablec                     t          |t                    s|                                }|| _        || _        || _        || _        |                                  d S r   )
isinstancestrhexr   r    r!   r"   _validate_attributes)r   r   r    r!   r"   s        r   r   z'NodeAffinitySchedulingStrategy.__init__<   sY     '3'' 	$kkmmG	%:"$8!!!#####r   c                 :   t          d| j         d          }	 t          j        | j                  }n# t          $ r}||d }~ww xY w|                                r|| j        r| j        st          d          | j        r| j        rt          d          d S d S )NzInvalid node_id 'z'. Node ID must be a valid hex string. To get a list of all nodes and their IDs in your cluster, use ray.nodes(). See https://docs.ray.io/en/latest/ray-core/miscellaneous.html#node-information for more details.zm_spill_on_unavailable cannot be set when soft is False. Please set soft to True to use _spill_on_unavailable.zk_fail_on_unavailable cannot be set when soft is True. Please set soft to False to use _fail_on_unavailable.)	
ValueErrorr   r   from_hex	Exceptionis_nilr!   r    r"   )r   invalid_node_id_errorr   es       r   r'   z3NodeAffinitySchedulingStrategy._validate_attributesN   s     *@ @ @ @!
 !

	/odl33GG 	/ 	/ 	/'Q.	/ >> 	(''% 	di 	O   $ 	 	N  	 	 	 	s   4 
AAAN)FF)r   r   r   r   r%   r   r   r'   r   r   r   r   r   *   st         ( ',%*$ $$ $  $	$
 #$ $ $ $$    r   r   c                     | st          d| d| d          d}| D ]U}t          |t                    s9t          d| d| d| dt          |           d	t          |           d
          |dz   }Vd S )NzThe variadic parameter of the z* operator must be a non-empty tuple: e.g. z("value1", "value2").r   zType of value in position z	 for the z operator must be str (e.g. z("value1", "value2")) but got 	 of type .   )r)   r$   r%   type)valuesoperatorindexvalues       r   %_validate_label_match_operator_valuesr8   h   s     
PX P P08P P P
 
 	

 E  %%% 	?U ? ?X ? ?%-? ?u::? ?04U? ? ?  
 	 r   alpha)	stabilityc                       e Zd Zd ZdS )Inc                 N    t          |d           t          |          | _        d S )Nr<   r8   listr4   r   r4   s     r   r   zIn.__init__|   s#    -fd;;;6llr   Nr   r   r   r   r   r   r   r<   r<   z   #        # # # # #r   r<   c                       e Zd Zd ZdS )NotInc                 N    t          |d           t          |          | _        d S )NrD   r>   r@   s     r   r   zNotIn.__init__   s#    -fg>>>6llr   NrA   r   r   r   rD   rD      rB   r   rD   c                       e Zd Zd ZdS )Existsc                     d S r   r   r   s    r   r   zExists.__init__       r   NrA   r   r   r   rG   rG      #            r   rG   c                       e Zd Zd ZdS )DoesNotExistc                     d S r   r   rI   s    r   r   zDoesNotExist.__init__   rJ   r   NrA   r   r   r   rM   rM      rK   r   rM   c                   6    e Zd ZdZdedeeeee	f         fdZ
dS )_LabelMatchExpressionu   An expression used to select node by node's labels
    Attributes:
        key: the key of label
        operator: In、NotIn、Exists、DoesNotExist
    keyr5   c                 "    || _         || _        d S r   )rQ   r5   )r   rQ   r5   s      r   r   z_LabelMatchExpression.__init__   s     r   N)r   r   r   r   r%   r   r<   rD   rG   rM   r   r   r   r   rP   rP      sN         !C !5UFL1P+Q ! ! ! ! ! !r   rP   c                   .    e Zd ZdZdddedefdZd ZdS )NodeLabelSchedulingStrategyz
    Label based node affinity scheduling strategy

    scheduling_strategy=NodeLabelSchedulingStrategy({
        "region": In("us"),
        "gpu_type": Exists(),
    })
    N)r    hardr    c                    t          |d          | _        t          |d          | _        |                                  d S )NrU   r    )_convert_map_to_expressionsrU   r    _check_usage)r   rU   r    s      r   r   z$NodeLabelSchedulingStrategy.__init__   s>     0f==	/f==	r   c                 D    | j         s| j        st          d          d S d S )NzTThe `hard` and `soft` parameter of NodeLabelSchedulingStrategy cannot both be empty.)rU   r    r)   rI   s    r   rX   z(NodeLabelSchedulingStrategy._check_usage   sA    	 	TY 	G  	 	 	 	r   )r   r   r   r   LabelMatchExpressionsTr   rX   r   r   r   rT   rT      sb          OS  *5K       r   rT   map_expressionsparamc                 H   g }| |S t          | t                    s#t          d| dt          |            d          |                                 D ]\  }}t          |t
                    s3t          d| dt          |           dt          |           d          t          |t          t          t          t          f          s6t          d| d| d	t          |           dt          |           d	          |
                    t          ||                     |S )
NzThe zD parameter must be a map (e.g. {"key1": In("value1")}) but got type r1   zThe map key of the zE parameter must be of type str (e.g. {"key1": In("value1")}) but got r0   zThe map value for key z of the zw parameter must be one of the `In`, `NotIn`, `Exists` or `DoesNotExist` operator (e.g. {"key1": In("value1")}) but got )r$   r   r)   r3   itemsr%   r<   rD   rG   rM   appendrP   )r[   r\   expressionsrQ   r7   s        r   rW   rW      s   Kot,, 
55 5 5 115 5 5
 
 	

 &++-- > >
U#s## 	;e ; ;s88; ;.23ii; ; ;   %"eV\!BCC 	? ? ?e ? ? u::? ? 15U? ? ?   	0e<<====r   N)typingr   r   r   r   ray._rayletr   ray.util.annotationsr   ray.util.placement_groupr	   r   r   r8   r<   rD   rG   rM   rP   r%   rZ   rT   rW   SchedulingStrategyTr   r   r   <module>rf      s   7 7 7 7 7 7 7 7 7 7 7 7       * * * * * * 8777777 W W W W W W W W2 : : : : : : : :z  $ W# # # # # # # # W# # # # # # # # W       
 W       
	! 	! 	! 	! 	! 	! 	! 	! c5UFL)H#IIJ  W       21G PS    > $"	!   r   