
    &`i                         d dl mZ d dlmZmZmZ d dlZd dlmZmZ d dl	m
Z
mZmZ d dlmZ d dlmZ dZee G d	 d
e
                                  Ze G d de                      ZdS )    )	dataclass)DictListOptionalN)
LOCAL_MODESCRIPT_MODE)AcquiredResourcesRemoteRayEntityResourceRequest)ResourceManager)DeveloperAPIi c                   ^    e Zd ZU eeeef                  ed<   dedeeef         de	defdZ
dS )FixedAcquiredResourcesbundlesentitybundlebundle_indexreturnc                     |                                 }|                    dd          }|                    dd          }|                    dd          }|                    ||||          S )NCPUr   GPUmemory        )num_cpusnum_gpusr   	resources)copypopoptions)selfr   r   r   r   r   r   s          u/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/air/execution/resources/fixed.py_annotate_remote_entityz.FixedAcquiredResources._annotate_remote_entity   sq     ::eQ''::eQ''Hc**~~	  
 
 	
    N)__name__
__module____qualname__r   r   strfloat__annotations__r
   intr"    r#   r!   r   r      so          $sEz"####
%
/3CJ/?
OR
	
 
 
 
 
 
r#   r   c                       e Zd ZU dZeZeed<   ddee	e
ef                  fdZede	e
ef         fd            Zdefd	Zdefd
ZdedefdZdedee         fdZdefdZd ZdS )FixedResourceManageraI  Fixed budget based resource manager.

    This resource manager keeps track of a fixed set of resources. When resources
    are acquired, they are subtracted from the budget. When resources are freed,
    they are added back to the budget.

    The resource manager still requires resources to be requested before they become
    available. However, because the resource requests are virtual, this will not
    trigger autoscaling.

    Additionally, resources are not reserved on request, only on acquisition. Thus,
    acquiring a resource can change the availability of other requests. Note that
    this behavior may be changed in future implementations.

    The fixed resource manager does not support placement strategies. Using
    ``STRICT_SPREAD`` will result in an error. ``STRICT_PACK`` will succeed only
    within a placement group bundle. All other placement group arguments will be
    ignored.

    Args:
        total_resources: Budget of resources to manage. Defaults to all available
            resources in the current task or all cluster resources (if outside a task).

    _resource_clsNtotal_resourcesc                 8   t          j                    }|sC|j        j        d t          t
          hv rt          j                    }n|                                }t           j        	                                d uo|j
        | _        || _        g | _        g | _        d S N)rayget_runtime_contextworkermoder   r   cluster_resourcesget_assigned_resourcesutilget_current_placement_group-should_capture_child_tasks_in_placement_group_allow_strict_pack_total_resources_requested_resources_used_resources)r    r/   rtcs      r!   __init__zFixedResourceManager.__init__E   s    %'' 	?z4j"AAA"%"7"9"9"%"<"<">"> H0022$> BA 	
 !0$&!!r#   r   c                     | j                                         }| j        D ]I}|j        }|                                D ]+\  }}||         t
          z  |t
          z  z
  t
          z  ||<   ,J|S r1   )r<   r   r>   required_resourcesitems_DIGITS)r    available_resourcesused_resourcesall_resourceskvs         r!   _available_resourcesz)FixedResourceManager._available_resourcesZ   s    "388::"2 	 	N*=M%++--  1'*W4q7{B*#A&& #"r#   resource_requestc                     |j         dk    s| j        s#|j         dk    rt          d|j          d          | j                            |           d S )NSTRICT_SPREADSTRICT_PACKz-Requested a resource with placement strategy z, but this cannot be fulfilled by a FixedResourceManager. In a nested setting, please set the inner placement strategy to be less restrictive (i.e. no STRICT_ strategy).)strategyr;   RuntimeErrorr=   appendr    rK   s     r!   request_resourcesz&FixedResourceManager.request_resourcesf   sy    $77' 8,<,E,V,VY#,Y Y Y   	!(()9:::::r#   c                 :    | j                             |           d S r1   )r=   removerR   s     r!   cancel_resource_requestz,FixedResourceManager.cancel_resource_requests   s     !(()9:::::r#   c                     || j         vrdS | j        }|j        }|                                D ]"\  }}|                    |d          |k     r dS #dS )NFr   T)r=   rJ   rB   rC   get)r    rK   rE   rG   rH   rI   s         r!   has_resources_readyz(FixedResourceManager.has_resources_readyv   sq    4#<<<5"7(;!'')) 	 	DAq"&&q#..22uu 3tr#   c                     |                      |          sd S | j                            |           |                     |j        |          S )N)r   rK   )rY   r>   rQ   r.   r   rR   s     r!   acquire_resourcesz&FixedResourceManager.acquire_resources   s^     ''(899 	4##$4555!!$,?O " 
 
 	
r#   acquired_resourcec                 H    |j         }| j                            |           d S r1   )rK   r>   rU   )r    r\   r   s      r!   free_resourcesz#FixedResourceManager.free_resources   s'    %6	##I.....r#   c                 "    g | _         g | _        d S r1   )r=   r>   )r    s    r!   clearzFixedResourceManager.clear   s    $&!!r#   r1   )r$   r%   r&   __doc__r   r.   r	   r)   r   r   r'   r(   r@   propertyrJ   r   rS   rV   boolrY   r[   r^   r`   r+   r#   r!   r-   r-   (   s>         2 (>M$===" "c5j1A(B " " " "* 	#d3:&6 	# 	# 	# X	#;/ ; ; ; ;; ; ; ; ;	O 	 	 	 	 		
 /	
	#	$	
 	
 	
 	
/0A / / / /" " " " "r#   r-   )dataclassesr   typingr   r   r   r2   r   r   #ray.air.execution.resources.requestr	   r
   r   ,ray.air.execution.resources.resource_managerr   ray.util.annotationsr   rD   r   r-   r+   r#   r!   <module>ri      sA   ! ! ! ! ! ! ' ' ' ' ' ' ' ' ' ' 



 ' ' ' ' ' ' ' '         
 I H H H H H - - - - - -  

 
 
 
 
. 
 
  
& j" j" j" j" j"? j" j" j" j" j"r#   