o
    c²“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
   úR/home/ubuntu/.local/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 )zƒGet 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,    ÿþÿ
ýÿþÿ
ý