
    #Sh$                         d dl Zd dlZd dlmZ d dl mZmZmZmZm	Z	 ddl
mZ ddlmZmZ ddlmZ dej        eef         d	ej        eef         d
dfdZ G d de          Zdee         de	eef         ded
efdZdS )    N)Path)AnyListOptionalTypeUnion   )plugins)ExecutorJob)DelayedSubmissionkwargsdeprecated_argsreturnc                     t          |           D ]M}|                    |          }|s|                     |          | |<   t          j        d| d| d           Nd S )Nz	Setting 'z' is deprecated. Use 'z
' instead.)listgetpopwarningswarn)r   r   argnew_args       X/var/www/html/movieo_spanner_bot/venv/lib/python3.11/site-packages/submitit/auto/auto.py_convert_deprecated_argsr      s}    F|| R R!%%c** 	 **S//wP#PPWPPPQQQQR R    c            	       n    e Zd ZdZdddZddeeef         dee         de	d	df fd
Z
ed	efd            Zdeeeef                  d	dfdZed	ej        eef         fd            Zed	ej        e         fd            Zde	d	dfdZdej        e         d	ej        eej	                          fdZ xZS )AutoExecutoraM  Automatic job executor
    This class is used to hold the parameters to run a job on the cluster
    corresponding to the environment.
    It can also be used to run job locally or in debug mode.
    In practice, it will create a bash file in the specified directory for each job,
    and pickle the task function and parameters. At completion, the job will also pickle
    the output. Logs are also dumped in the same directory.

    Executor specific parameters must be specified by prefixing them with the name
    of the executor they refer to. eg:
        - 'chronos_conda_file' (internal)
        - 'slurm_max_num_timeout'
    See each executor documentation for the list of available parameters.

    Parameters
    ----------
    folder: Path/str
        folder for storing job submission/output and logs.
    warn_ignored: bool
        prints a warning each time a parameter is provided but ignored because it is only
        useful for the other cluster.
    cluster: str
        Forces AutoExecutor to use the given environment. Use "local" to run jobs locally,
        "debug" to run jobs in process.
    kwargs: other arguments must be prefixed by the name of the executor they refer to.
        {exname}_{argname}: see {argname} documentation in {Exname}Executor documentation.

    Note
    ----
    - be aware that the log/output folder will be full of logs and pickled objects very fast,
      it may need cleaning.
    - use update_parameters to specify custom parameters (gpus_per_node etc...). If you
      input erroneous parameters, an error will print all parameters available for you.
    slurm_max_num_timeoutchronos_conda_file)max_num_timeout
conda_fileNfolderclusterr   r   c           	        	 |p|                                  | _        t          j                    }| j        |vrt	          d| j                   t          || j                   d}dd                    |           d}|D ]L}d|v sJ | d| d|             |                    d          d	         }||v sJ | d| d
| d|             Mt          || j                 |fi || _
        |                                 		fd|                                D             | _        t                                          | j
        j        | j
        j                   d S )Nz-AutoExecutor doesn't know any executor named zHExtra arguments must be prefixed by executor named, received unknown argKnown executors: , ._z 'z'. r   z', and 'z' executor is also unknown. c                 \    i | ](\  }}|                                 D ]}|v|| d | )S r(   )_valid_parameters).0ex_nameexr   valids       r   
<dictcomp>z)AutoExecutor.__init__.<locals>.<dictcomp>S   se     !
 !
 !
++--!
 !
 % G##c##  r   )whichr#   r
   get_executors
ValueErrorr   _ctor_deprecated_argsjoinsplitflexible_init	_executorr+   items_deprecated_argssuper__init__r"   
parameters)selfr"   r#   r   	executorserrerr_ex_listnameprefixr/   	__class__s            @r   r<   zAutoExecutor.__init__@   s   .$**,,)++	<y(([T\[[\\\ )CDDDXA$))I*>*>AAA 	Y 	YD$;;;3 @ @$ @ @; @ @;;;ZZ__Q'F)###XXXXvXX;XX $###&y'>QQ&QQ&&((!
 !
 !
 !
(00!
 !
 !
 	.0IJJJJJr   c                      t          j                    t          fd          } |                                          dk    r%t	          d                                 d          | S )z%Returns what is the detected cluster.c                 8    |                                           S N)affinity)r.   r?   s    r   <lambda>z$AutoExecutor.which.<locals>.<lambda>_   s    	"0F0F0H0H r   )keyr   z*Did not found an available executor among r'   )r
   r2   maxrH   RuntimeErrorkeys)best_exr?   s    @r   r1   zAutoExecutor.which[   st     )++	i%H%H%H%HIIIW&&((A--_INNL\L\___```r   foldersc                 x    t          | j        dd          }| ||           dS t          j        d           dS )a  Archive a list of folders to be untarred in the job working directory.
        This is only implemented for internal cluster, for running job on non-installed packages.
        This is not useful on slurm since the working directory of jobs is identical to
        your work station working directory.

        folders: list of paths
            The list of folders to archive and untar in the job working directory
        register_dev_foldersNzZIgnoring dev folder registration as it is only supported (and needed) for internal cluster)getattrr8   r   r   )r>   rO   registers      r   rQ   z!AutoExecutor.register_dev_foldersf   sW     4>+A4HHHW Ml    r   c           	      h    t           t          t          t          t          t          t          t          dS )N)rB   timeout_minmem_gbnodescpus_per_taskgpus_per_nodetasks_per_nodestderr_to_stdout)strintfloatboolclss    r   _typed_parameterszAutoExecutor._typed_parametersx   s+       ! $	
 	
 		
r   c                 h    t          |                                                                           S rG   )setrb   rM   r`   s    r   r+   zAutoExecutor._valid_parameters   s(    3((**//11222r   c                     d                                  D             t                                                                           D ]R\  }}|t          k    rt          t          f}|v r0t          |         |          sJ d| d| d|          d            St           j                   fdD             }g }t          j	                    }|D ]}t          |          dk    r |                    d|d	          d
           5|\  }}	||vr |                    d| d| d|	 d           ^||                                         }
|	|
vr@|	vr<|                    d|	 d| d| d|	 d	dz   d                    |
          z              |re|                    dd                    |                                           d dg           t!          d                    |                     j        di  fd|D               j                            fdD                       }|D ]$\  }}	|	vr| j        k    r| d|	          ||	<   %  j        j        di | dS )a  Updates submission parameters to srun/crun.

        Parameters
        ----------
        AutoExecutors provides shared parameters that are translated for each specific cluster.
        Those are: timeout_min (int), mem_gb (int), gpus_per_node (int), cpus_per_task (int),
        nodes (int), tasks_per_node (int) and name (str).
        Cluster specific parameters can be specified by prefixing them with the cluster name.

        Notes
        -----
        - Cluster specific parameters win over shared parameters.
            eg: if both `slurm_time` and `timeout_min` are provided, then:
                - `slurm_time` is used on the slurm cluster
                - `timeout_min` is used on other clusters
        c                     i | ]
\  }}|||S rG    )r,   kvs      r   r0   z<AutoExecutor._internal_update_parameters.<locals>.<dictcomp>   s    CCC41aQ]!Q]]]r   zParameter "z" expected type z (but value: "z")c                 D    g | ]}|v|                     d d          S )r(      )r6   )r,   xgenericss     r   
<listcomp>z<AutoExecutor._internal_update_parameters.<locals>.<listcomp>   s/    IIIq7H7HAGGCOO7H7H7Hr   r	   zParameter 'r   z*' need to be prefixed by an executor name.zUnknown executor 'z' in parameter 'r(   z'.zUnknown argument 'z' for executor 'z Valid arguments: r&   r%   z=As a reminder, shared/generic (non-prefixed) parameters are: r'   
c                 j    i | ]/\  }}|j         k    |v |                    | d |           0S r*   )r#   r   )r,   r.   r   rm   r   r>   s      r   r0   z<AutoExecutor._internal_update_parameters.<locals>.<dictcomp>   sR       B%%#// VZZ2..*9//r   c                 *    i | ]}|v ||         S rg   rg   )r,   rh   rm   r   s     r   r0   z<AutoExecutor._internal_update_parameters.<locals>.<dictcomp>   s+    8g8g8g!YZ^fYfYfF1IYfYfYfr   Nrg   )r9   r   rb   r^   r]   
isinstancer   r:   r
   r2   lenappendr+   r5   extendrM   	NameErrorupdater8   _convert_parametersr#   _internal_update_parameters)r>   r   rB   expected_typespecificinvalidr?   ex_argr.   r   r/   r=   rm   s   ``          @r   ry   z(AutoExecutor._internal_update_parameters   sf   $ DC6<<>>CCC1133#+>>#3#3 	 	D-%%!$ev~~!&,>>  i$iiiiY_`dYeiii > 	!)>???IIIIVIII)++	 	 	F6{{abVAYbbbcccGB""TBTTTTSTTTUUUbM3355E%Cx$7$7^^^b^^RT^^WZ^^^*+ii&&'  
  	0NNE		)..2B2B(C(CEE_T\___   DIIg../// 	 	
 	
     '  	
 	
 	
 ^778g8g8g8g8gv8g8g8ghh
 	8 	8GB(""rT\'9'9"(B"7
322@@Z@@@@@r   delayed_submissionsc                 6    | j                             |          S rG   )r8   _internal_process_submissions)r>   r~   s     r   r   z*AutoExecutor._internal_process_submissions   s     ~;;<OPPPr   rG   )__name__
__module____qualname____doc__r4   r   r\   r   r   r   r<   staticmethodr1   r   rQ   classmethodtpDictr   rb   Setr+   ry   r   r   r   __classcell__)rD   s   @r   r   r      s       ! !F 1HWkllK KuS$Y/ K(3- KZ] Kbf K K K K K K6 3    \DsDy1A,B t    $ 

"'#t)"4 

 

 

 [

 3"&+ 3 3 3 [3LAC LAD LA LA LA LA\Q#%7+<#=Q	RV	Q Q Q Q Q Q Q Qr   r   ra   r"   c                     |                                  dz    | |fi fd|                                D             S )Nr(   c                 p    i | ]2\  }}|                               |t                    d          |3S rG   )
startswithrs   )r,   rh   valrC   s      r   r0   z!flexible_init.<locals>.<dictcomp>   sC    eeeFAsPQP\P\]cPdPde!CKKMM*Ceeer   )rB   r9   )ra   r"   r   rC   s      @r   r7   r7      sJ    XXZZ#F3vffeeeefllnneeefffr   )typingr   r   pathlibr   r   r   r   r   r   corer
   	core.corer   r   
core.utilsr   r   r\   Mappingr   r   r7   rg   r   r   <module>r      sk              3 3 3 3 3 3 3 3 3 3 3 3 3 3       % % % % % % % % * * * * * *RRWS#X%6 RTWY\T\I] Rbf R R R R@Q @Q @Q @Q @Q8 @Q @Q @QFgtH~ guS$Y/? g3 gS[ g g g g g gr   