o
    `۷i/                     @   s   d Z ddlmZmZ ddlmZmZmZmZm	Z	m
Z
 ddlmZ er.ddlmZ ddlmZ G dd deZe
d	ed
ZG dd deee ZG dd dee	eef  ZdS )z>Ranker component for operator selection in streaming executor.    )ABCabstractmethod)TYPE_CHECKINGGenericListProtocolTupleTypeVar)PhysicalOperator)ResourceManager)Topologyc                   @   sj   e Zd ZdZdd defddZdd defddZdd defdd	Zdd defd
dZdd defddZ	dS )
Comparablez4Protocol for types that can be compared for ranking.otherreturnc                 C      d S N selfr   r   r   Y/home/ubuntu/vllm_env/lib/python3.10/site-packages/ray/data/_internal/execution/ranker.py__lt__      zComparable.__lt__c                 C   r   r   r   r   r   r   r   __le__   r   zComparable.__le__c                 C   r   r   r   r   r   r   r   __gt__   r   zComparable.__gt__c                 C   r   r   r   r   r   r   r   __ge__   r   zComparable.__ge__c                 C   r   r   r   r   r   r   r   __eq__   r   zComparable.__eq__N)
__name__
__module____qualname____doc__boolr   r   r   r   r   r   r   r   r   r      s    r   RankingValue)boundc                	   @   sP   e Zd ZdZededddddefdd	Zd
ee dddddee fddZ	dS )Rankerz4Abstract base class for operator ranking strategies.optopologyr   resource_managerr   r   c                 C   s   dS )a  Rank operator for execution priority.

        Operator to run next is selected as the one with the *smallest* value
        of the lexicographically ordered ranks composed of (in order):

        Args:
            op: Operator to rank
            topology: Current execution topology
            resource_manager: Resource manager for usage information

        Returns:
            Rank (tuple) for operator
        Nr   )r   r$   r%   r&   r   r   r   rank_operator'   s   zRanker.rank_operatoropsc                    s&   t |dksJ  fdd|D S )Nr   c                    s   g | ]	} | qS r   )r'   ).0r$   r&   r   r%   r   r   
<listcomp>E   s    z)Ranker.rank_operators.<locals>.<listcomp>)len)r   r(   r%   r&   r   r*   r   rank_operators=   s   zRanker.rank_operatorsN)
r   r   r   r   r   r
   r!   r'   r   r-   r   r   r   r   r#   $   s*    r#   c                
   @   s2   e Zd ZdZdedddddeeef fdd	Zd
S )DefaultRankerzRanker implementation.r$   r%   r   r&   r   r   c                 C   s    |  rdnd}|||jfS )a  Computes rank for op. *Lower means better rank*

            1. Whether operator's could be throttled (int)
            2. Operators' object store utilization

        Args:
            op: Operator to rank
            topology: Current execution topology
            resource_manager: Resource manager for usage information

        Returns:
            Rank (tuple) for operator
        r      )throttling_disabledget_op_usageobject_store_memory)r   r$   r%   r&   r0   r   r   r   r'   K   s   
zDefaultRanker.rank_operatorN)r   r   r   r   r
   r   intr'   r   r   r   r   r.   H   s    
r.   N)r   abcr   r   typingr   r   r   r   r   r	   'ray.data._internal.execution.interfacesr
   -ray.data._internal.execution.resource_managerr   5ray.data._internal.execution.streaming_executor_stater   r   r!   r#   r3   r.   r   r   r   r   <module>   s      $