
    &`i,                        d dl mZmZmZmZmZmZ d dlmZ d dl	Z	d dl
mZmZmZmZ d dlmZ d dlmZ d dlmZ d dlmZ e G d	 d
e                      Z G d de          Z G d d          Ze G d de                      ZdS )    )AnyDictListOptionalTupleUnion)ReferenceTypeN)BIND_INDEX_KEYIS_CLASS_METHOD_OUTPUT_KEYPARENT_CLASS_NODE_KEYPREV_CLASS_METHOD_CALL_KEY)DAGNode)get_dag_node_str)	InputNode)DeveloperAPIc            
            e Zd ZdZ	 d fd	Zdee         deeef         deeef         deeef         fdZ	d	 Z
d
efdZdefdZd
efdZ xZS )	ClassNodez/Represents an actor creation in a Ray task DAG.Nc                     || _         d | _        t                                          ||||           |                                 rt          d          d S )Nother_args_to_resolvezInputNode handles user dynamic input the DAG, and cannot be used as args, kwargs, or other_args_to_resolve in ClassNode constructor because it is not available at class construction or binding time.)_body
_last_callsuper__init___contains_input_node
ValueError)selfclscls_args
cls_kwargscls_optionsr   	__class__s         f/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/dag/class_node.pyr   zClassNode.__init__   sw     
7;"7	 	 	
 	
 	
 $$&& 	6  	 	    new_args
new_kwargsnew_optionsnew_other_args_to_resolvec                 4    t          | j        ||||          S Nr   )r   r   r   r%   r&   r'   r(   s        r#   
_copy_implzClassNode._copy_impl.   s,     J";
 
 
 	
r$   c                 ~      t          j        | j                  j        di | j        j        | j        i | j        S )a6  Executor of ClassNode by ray.remote()

        Args and kwargs are to match base class signature, but not in the
        implementation. All args and kwargs should be resolved and replaced
        with value in bound_args and bound_kwargs via bottom-up recursion when
        current node is executed.
         )rayremoter   options_bound_options_bound_args_bound_kwargs)r   argskwargss      r#   _execute_implzClassNode._execute_impl=   sY     CJtz"", ,*, ,T%=)-);= =	
r$   returnc                 h    |                                  }|D ]}t          |t                    r dS dS )z_Check if InputNode is used in children DAGNodes with current node
        as the root.
        TF)_get_all_child_nodes
isinstancer   )r   children_dag_nodeschilds      r#   r   zClassNode._contains_input_nodeK   sH     "6688' 	 	E%++ ttur$   method_namec                     |dk    r6dt          | j                  vr t          dt          |            d          t	          | j        |           t          | |i           }|S )Nbindz .bind() cannot be used again on  )dirr   AttributeErrortypegetattr_UnboundClassMethodNode)r   r>   	call_nodes      r#   __getattr__zClassNode.__getattr__U   sh    &  V3tz??%B%B !QDJJ!Q!Q!QRRR
K(((+D+rBB	r$   c                 F    t          | t          | j                            S N)r   strr   r   s    r#   __str__zClassNode.__str__^   s    c$*oo666r$   rJ   )__name__
__module____qualname____doc__r   r   r   r   rK   r,   r7   boolr   rH   rM   __classcell__r"   s   @r#   r   r      s        99 #     2
s)
 cN
 #s(^	

 $(S>
 
 
 

 
 
d    s    7 7 7 7 7 7 7 7 7r$   r   c                   :    e Zd ZdededefdZd ZdefdZd Z	d	S )
rF   actorr>   r1   c                 0    || _         || _        || _        d S rJ   )_actor_method_name_options)r   rV   r>   r1   s       r#   r   z _UnboundClassMethodNode.__init__c   s     'r$   c                     t           | j        t          | j        j        i}t	          | j        ||| j        |          }|| j        _        |S r*   )r   rX   r   r   ClassMethodNoderY   rZ   )r   r5   r6   r   nodes        r#   r@   z_UnboundClassMethodNode.bindk   sV    !4;&(>!

 M"7
 
 
 "&r$   attrc                 V    |dk    rt          d          |                     |          S )Nr0   zd.remote() cannot be used on ClassMethodNodes. Use .bind() instead to express an symbolic actor call.)rC   __getattribute__)r   r^   s     r#   rH   z#_UnboundClassMethodNode.__getattr__{   s:    8 5  
 ((...r$   c                     || _         | S rJ   )rZ   )r   r1   s     r#   r1   z_UnboundClassMethodNode.options   s    r$   N)
rN   rO   rP   r   rK   dictr   r@   rH   r1   r.   r$   r#   rF   rF   b   sv         i  c  D           / / / / /    r$   rF   c                   V    e Zd ZdZdddefdZed
d            Zedefd            Zd	S )_ClassMethodOutputz7Represents a class method output in a Ray function DAG.class_method_callr\   
output_idxc                 "    || _         || _        d S rJ   )_class_method_call_output_idx)r   re   rf   s      r#   r   z_ClassMethodOutput.__init__   s    "3%r$   r8   c                     | j         S rJ   )rh   rL   s    r#   re   z$_ClassMethodOutput.class_method_call   s    &&r$   c                     | j         S rJ   )ri   rL   s    r#   rf   z_ClassMethodOutput.output_idx   s    r$   N)r8   r\   )	rN   rO   rP   rQ   intr   propertyre   rf   r.   r$   r#   rd   rd      s        AA&*; & & & & & ' ' ' X'  C       X     r$   rd   c                       e Zd ZdZdedee         deeef         deeef         deeef         f
 fdZde	e         d	eeef         d
eeef         deeef         fdZ
d ZdefdZdefdZdefdZdefdZd Zded         fdZedefd            Zedefd            Zedefd            Zeded          fd            Zedee         fd            Z xZS )r\   z<Represents an actor method invocation in a Ray function DAG.r>   method_argsmethod_kwargsmethod_optionsr   c                    |pg | _         |pi | _        |pi | _        || _        |                    t
                    | _        |                    t          d           | _        |                    t          d           | _
        |                    t          d          | _        d | _        | j        r!t          |d         |d                   | _        t                                          ||||           d S )NFr      r   )r3   r4   r2   rY   getr   _parent_class_noder   _prev_class_method_callr
   _bind_indexr   _is_class_method_output_class_method_outputrd   r   r   )r   r>   ro   rp   rq   r   r"   s         r#   r   zClassMethodNode.__init__   s    ',"*0b,2!, "%%&;<< 	 "%%&@$GG 	$ +@*C*CD+
 +
 .C-F-F&.
 .
$
 CG!' 	 );AA) )D% 	"7	 	 	
 	
 	
 	
 	
r$   r%   r&   r'   r(   c                 4    t          | j        ||||          S r*   )r\   rY   r+   s        r#   r,   zClassMethodNode._copy_impl   s-     ";
 
 
 	
r$   c                     | j         rAt          | j        | j                  }  |j        di | j        j        | j        i | j        S | j	        J | j        d         | j	        j
                 S )a<  Executor of ClassMethodNode by ray.remote()

        Args and kwargs are to match base class signature, but not in the
        implementation. All args and kwargs should be resolved and replaced
        with value in bound_args and bound_kwargs via bottom-up recursion when
        current node is executed.
        Nr   r.   )is_class_method_callrE   ru   rY   r1   r2   r0   r3   r4   ry   rf   )r   r5   r6   method_bodys       r#   r7   zClassMethodNode._execute_impl   s     $ 		M!$"94;LMMKD&;&==)<==D!$  
 ,888#A&t'@'KLLr$   r8   c                 2    t          | | j         d          S )Nz())r   rY   rL   s    r#   rM   zClassMethodNode.__str__   s    ):&>&>&>???r$   c                 *    |                                  S rJ   )rM   rL   s    r#   __repr__zClassMethodNode.__repr__   s    ||~~r$   c                     | j         S rJ   )rY   rL   s    r#   get_method_namezClassMethodNode.get_method_name   s      r$   c                     | j         S rJ   )rw   rL   s    r#   _get_bind_indexzClassMethodNode._get_bind_index   s    r$   c                 0    t          | j        |          }|S rJ   )rE   ru   )r   r>   r}   s      r#   _get_remote_methodz"ClassMethodNode._get_remote_method   s    d5{CCr$   zray.actor.ActorHandlec                 \    t          | j        t          j        j                  sd S | j        S rJ   )r;   ru   r/   rV   ActorHandlerL   s    r#   _get_actor_handlez!ClassMethodNode._get_actor_handle  s*    $1393HII 	4&&r$   c                     | j         rS| j                            dd          }|4|                     | j                  }|                                d         }|S | j        J | j        j        j        S )z
        Return the number of return values from the class method call. If the
        node is a class method output, return the number of return values from
        the upstream class method call.
        num_returnsN)	r|   r2   rt   r   rY   __getstate__ry   re   r   )r   r   methods      r#   r   zClassMethodNode.num_returns	  s~     $ 	K-11-FFK"001BCC$1133MB,888,>JJr$   c                     | j          S )zu
        Return True if the node is a class method call, False if the node is a
        class method output.
        rx   rL   s    r#   r|   z$ClassMethodNode.is_class_method_call  s     ///r$   c                     | j         S )zu
        Return True if the node is a class method output, False if the node is a
        class method call.
        r   rL   s    r#   is_class_method_outputz&ClassMethodNode.is_class_method_output#  s     ++r$   c                 ,    | j         dS | j         j        S )z
        Return the upstream class method call that returns multiple values. If
        the node is a class method output, return None.
        N)ry   re   rL   s    r#   re   z!ClassMethodNode.class_method_call+  s     $,4(::r$   c                 ,    | j         dS | j         j        S )z
        Return the output index of the return value from the upstream class
        method call that returns multiple values. If the node is a class method
        call, return None.
        N)ry   rf   rL   s    r#   rf   zClassMethodNode.output_idx6  s     $,4(33r$   )rN   rO   rP   rQ   rK   r   r   r   r   r   r,   r7   rM   r   r   rl   r   r   r   r   rm   r   rR   r|   r   re   rf   rS   rT   s   @r#   r\   r\      sk       FF1
1
 3Z1
 CH~	1

 S#X1
  $CH~1
 1
 1
 1
 1
 1
f
s)
 cN
 #s(^	

 $(S>
 
 
 
M M M&@ @ @ @ @#    ! ! ! ! !           '8,C#D ' ' ' '
 KS K K K XK" 0d 0 0 0 X0 , , , , X, ;8,=#> ; ; ; X; 	4HSM 	4 	4 	4 X	4 	4 	4 	4 	4r$   r\   )typingr   r   r   r   r   r   weakrefr	   r/   ray.dag.constantsr
   r   r   r   ray.dag.dag_noder   ray.dag.format_utilsr   ray.dag.input_noder   ray.util.annotationsr   r   objectrF   rd   r\   r.   r$   r#   <module>r      s   : : : : : : : : : : : : : : : : ! ! ! ! ! ! 



            % $ $ $ $ $ 1 1 1 1 1 1 ( ( ( ( ( ( - - - - - - M7 M7 M7 M7 M7 M7 M7 M7`$ $ $ $ $f $ $ $N               $ d4 d4 d4 d4 d4g d4 d4 d4 d4 d4r$   