
    &`i                         d dl Z d dlmZmZmZ d dlmZ d dlmZ d dl	m
Z
 d dlZd dlmZ d dlmZ  e j        e          Z G d d	e          ZdS )
    N)AnyDictOptional)Parallel)MultiprocessingBackend)PicklingPool)	usage_lib)Poolc                        e Zd ZdZ	 	 	 ddee         dee         deeeef                  f fdZ		 	 	 	 	 dded	ee
         d
ee         dee         deeeef                  f
 fdZ fdZ xZS )
RayBackendzRay backend uses ray, a system for scalable distributed computing.
    More info about Ray is available here: https://docs.ray.io.
    Nnesting_levelinner_max_num_threadsray_remote_argsc                 v    t          j        d           || _         t                      j        d||d| dS )zT``ray_remote_args`` will be used to configure Ray Actors
        making up the pool.zutil.joblib)r   r   N )r	   record_library_usager   super__init__)selfr   r   r   kwargs	__class__s        o/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/util/joblib/ray_backend.pyr   zRayBackend.__init__   s]     	&}555. 	
'"7	
 	
 	
 	
 	
 	
 	
       n_jobsparallelpreferrequirec                    t           ft          _        	 |dk    rt          j                    ssddl}d|j        v r9t                              d	                    |j        d                              nt                              d           t          j
                     t          t          j        j                                        d                   }|} t          t           |           j        ||||fd||n| j        i|}	|	S )	a  Make Ray Pool the father class of PicklingPool. PicklingPool is a
        father class that inherits Pool from multiprocessing.pool. The next
        line is a patch, which changes the inheritance of Pool to be from
        ray.util.multiprocessing.pool.

        ``ray_remote_args`` will be used to configure Ray Actors making up the pool.
        This will override ``ray_remote_args`` set during initialization.
        r   NRAY_ADDRESSz)Connecting to ray cluster at address='{}'zStarting local ray clusterCPUr   )r
   r   	__bases__rayis_initializedosenvironloggerinfoformatinitint_privatestatecluster_resourcesr   r   	configurer   )r   r   r   r   r   r   memmappingpool_argsr&   ray_cpus
eff_n_jobsr   s             r   r0   zRayBackend.configure)   s!   " #'	 R<<%'' 			 BJ..KKCJJJ}5     KK <===


3<-??AA%HIIHF6U:t,,6		
 	
 * ,O%	
 "	
 	

 r   c                     t          t          |                               |          }|dk    r8t          t          j        j                                        d                   }|}|S )Nr    r"   )r   r   effective_n_jobsr,   r$   r-   r.   r/   )r   r   r3   r2   r   s       r   r5   zRayBackend.effective_n_jobs[   sW    :t,,==fEE
R<<3<-??AA%HIIH!Jr   )NNN)r   NNNN)__name__
__module____qualname____doc__r   r,   r   strr   r   r   r0   r5   __classcell__)r   s   @r   r   r      s          (,/348	
 
}
  (}
 "$sCx.1	
 
 
 
 
 
. '+ $!%480 00 8$0 	0
 #0 "$sCx.10 0 0 0 0 0d        r   r   )loggingtypingr   r   r   joblibr   joblib._parallel_backendsr   joblib.poolr   r$   ray._common.usager	   ray.util.multiprocessing.poolr
   	getLoggerr6   r(   r   r   r   r   <module>rD      s     & & & & & & & & & &       < < < < < < $ $ $ $ $ $ 



 ' ' ' ' ' ' . . . . . .		8	$	$Q Q Q Q Q' Q Q Q Q Qr   