o
    $i
                     @   s   d dl mZmZmZ d dlZded fddZdddeedef  deeedef  eedef  f fd	d
Zdedeedef  deeedef  eedef  f fddZded defddZ	dS )    )ListOptionalTupleNreturnzray.actor.ActorHandlec                   C   s"   zt  jW S  ty   Y dS w )zv
    Get the current actor handle in this worker.
    If this is called in a driver process, it will return None.
    N)rayget_runtime_contextcurrent_actorRuntimeError r
   r
   [/home/ubuntu/veenaModal/venv/lib/python3.10/site-packages/ray/experimental/channel/utils.pyget_self_actor   s
   r   writerreader_and_node_listc                 C   sD   g }g }|D ]\}}|| kr| ||f q| ||f q||fS )a\  Split readers into remote and local readers based on writer.

    Args:
        writer: The actor handle of the writer
        reader_and_node_list: List of (reader, node) tuples

    Returns:
        Tuple containing:
            - List of (reader, node) tuples for remote readers
            - List of (reader, node) tuples for local readers
    append)r   r   remote_readerslocal_readersreadernoder
   r
   r   split_readers_by_locality   s   r   r   actor_and_node_listc                 C   sD   g }g }|D ]\}}| |kr| ||f q| ||f q||fS )a  Split actors into remote and local actors based on node. The local actors will be
    on the same node as the given node. The remote actors will be on a different node.

    Args:
        writer_node: The node of the writer
        actor_and_node_list: List of (actor, node) tuples

    Returns:
        Tuple containing:
            - List of (actor, node) tuples for actors on the same node
            - List of (actor, node) tuples for actors on a different node
    r   )r   r   actors_on_same_nodeactors_on_different_nodeactor
actor_noder
   r
   r   split_actors_by_node_locality.   s   r   r   c                 C   s8   | du s| t  jkrt   S t | jdd S )zGet the node of the actor.

    Args:
        actor: The actor handle of the actor

    Returns:
        The node of the actor
    Nc                 S   s   t   S )N)r   r   get_node_id)selfr
   r
   r   <lambda>Z   s    z get_actor_node.<locals>.<lambda>)r   r   r   r   get__ray_call__remote)r   r
   r
   r   get_actor_nodeL   s   	r"   )
typingr   r   r   r   r   strr   r   r"   r
   r
   r
   r   <module>   s,    

