o
    $i                     @   s~   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 eZG dd	 d	eZdS )
    N)AnyDictOptional)Parallel)MultiprocessingBackend)PicklingPool)	usage_lib)Poolc                       s   e Zd ZdZ			ddee dee deeeef  f fddZ						dd	ed
ee
 dee dee deeeef  f
 fddZ fddZ  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                    s,   t 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__r   X/home/ubuntu/veenaModal/venv/lib/python3.10/site-packages/ray/util/joblib/ray_backend.pyr      s   
	
zRayBackend.__init__   n_jobsparallelpreferrequirec           
         s   t ft_	 |dkr7t s+ddl}d|jv r"td	|jd  ntd t
  ttjj d }|}tt| j||||fd|durH|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   r   r   r,   )   s8   



zRayBackend.configurec                    s4   t t| |}|dkrttjj d }|}|S )Nr   r   )r   r
   effective_n_jobsr(   r    r)   r*   r+   )r   r   r/   r.   r   r   r   r0   [   s
   zRayBackend.effective_n_jobs)NNN)r   NNNN)__name__
__module____qualname____doc__r   r(   r   strr   r   r   r,   r0   __classcell__r   r   r   r   r
      s:    2r
   )loggingtypingr   r   r   joblibr   joblib._parallel_backendsr   joblib.poolr   r    ray._common.usager   ray.util.multiprocessing.poolr	   	getLoggerr1   r$   r
   r   r   r   r   <module>   s    
