
    mi                        d Z ddlmZ ddlmZ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 d	e
j                  d
efdZd	e
j                  defdZe G d d             Ze G d d             Ze G d d             Ze G d d             Zy)z'
Basic configuration for Dora is here.
    )	Namespace)	dataclassfield)fnmatch)PathN)
DictConfig)	OmegaConfdataargsc                     | j                   D ]=  }t        |t              sJ t        ||      s"t	        ||      }|1t        | ||       ? y)z>Update the given dataclass from the argument parser args.
    N)__dict__
isinstancestrhasattrgetattrsetattr)r
   r   keyvalues       C/var/www/stems/demucs_env/lib/python3.12/site-packages/dora/conf.pyupdate_from_argsr      sO     }} *#s###4D#&E c5)*    cfgc                    t        j                  |d      }t        |t              sJ |j	                         D ]K  \  }}t        |t
              sJ t        | |      rt        | ||       2t        d| j                   d|        y)z6Update the given dataclass from the hydra config.
    T)resolvezObject of type z does not have an attribute N)
r	   to_containerr   dictitemsr   r   r   AttributeError	__class__)r
   r   dctr   r   s        r   update_from_hydrar!      s     
 
 d
3Cc4   iik F
U#s###4D#u% ?4>>2B C??Be"E F FFr   c                      e Zd ZU dZdZeed<   dZeed<   dZ	eed<   dZ
eed	<   d
Zej                  e   ed<   dZeed<   d
Zej                  e   ed<    ee      Zej(                  e   ed<   dZeed<   dZeed<   dZeed<   dZeed<   d
Zej                  e   ed<   d
Zej                  e   ed<   d
Zej                  e   ed<   y
)SlurmConfiga+  
    Configuration when scheduling a job.
    This differs slightly from Slurm/Submitit params because this will
    automatically scale some values based on the number of GPUs.

    Args:
        gpus (int): number of total GPUs to schedule. Number of nodes
            and tasks per nodes will be automatically inferred.
        mem_per_gpu (float): amount of memory in GB to schedule
            per gpus.
        time (int): maximum duration for the job in minutes.
        cpus_per_gpu (int): number of cpus per gpu, this will set
            the `cpus_per_task` automatically, based on the
            number of gpus and `one_task_per_node`, unless `cpus_per_task`
            is explicitely provided.
        cpus_per_task (int or None): number of cpus per task.
        partition (str): partition name
        comment (str): comment for the job.
        setup (List[str]): list of shell commands to execute
            before the actual command. Use it for `module load`.
        max_num_timeout (int): maximum number of requeue.
        one_task_per_node (bool): if True, schedules a single task
            per node, otherwise, will schedule one task per gpu (default is False).
        array_parallelism (int): when using job arrays, how many tasks can run
            in parallel.
        qos: (str or None): qos param for slurm.
        account: (str or None): account param for slurm.

    ..warning:: this assumes one task per GPU.
        Set `one_task_per_node` if you do not want that.
        Tasks without any gpus are not really supported at the moment.
       gpus(   mem_per_gpui  time
   cpus_per_gpuNcpus_per_tasklearnlab	partitioncommentdefault_factorysetup   max_num_timeout 
constraintFone_task_per_node   array_parallelismexcludeqosaccount)__name__
__module____qualname____doc__r%   int__annotations__r'   floatr(   r*   r+   tpOptionalr-   r   r.   r   listr1   Listr3   r5   r6   boolr8   r9   r:   r;    r   r   r#   r#   .   s    @ D#MKD#L#&*M2;;s#*Is $GR[[$5E2773<5OSJ#t# s  $GR[[$ CS	  $GR[[$r   r#   c                   J    e Zd ZU dZdZeed<   dZeed<   dZeed<   dZ	eed<   y)SubmitRulesa:  
    Submit rules describe in which case Shepherd will schedule new jobs.

    Args:
        retry (bool): if true, all failed or canceled jobs will be rescheduled.
        update_pending (bool): if true, all pending jobs whose Slurm parameters
            have changed will be replaced.
        update (bool): if true, all pending or running jobs whose Slurm parameters
            have changed will be replaced.
        replace (bool): if true, all running jobs will be replaced by new jobs.
        replace_done (bool): if true, all done jobs will be relaunched.
    Fretryupdatereplacereplace_doneN)
r<   r=   r>   r?   rK   rG   rA   rL   rM   rN   rH   r   r   rJ   rJ   a   s1     E4FDGTL$r   rJ   c                   f    e Zd ZU dZdZeed<   dZeed<   dZeed<   dZ	eed<   dZ
eed	<   d
Zeed
<   y)
ShepConfigz
    Configuration for Shepherd. Mostly naming conventions for folders and files.
    There should be little reasons to change that.
    zjob.pkljob_fileby_idorphanssubmititsubmitit_folderlatestlatest_submititarraysN)r<   r=   r>   r?   rQ   r   rA   rR   rS   rU   rW   rX   rH   r   r   rP   rP   v   sE     HcE3GS%OS%#OS#FCr   rP   c                   R    e Zd ZU dZ ed      Zeed<    ee      Z	e
j                  e   ed<   dZeed<   dZe
j                   e   ed	<   dZe
j                   e   ed
<   dZeed<   dZeed<    ee      Zeed<   dZeed<   dZeed<   dZeed<   dZeed<   dedefdZ fdZ xZS )
DoraConfiga<  
    Main Dora configuration. The main parameters to change are the following.

    Args:
        dir (Path or str): path where Dora will save all useful informations, logs.
            This is also where you should store your checkpoints (see `dora.xp.XP`).
        exclude (List[str]): list of patterns of argument names to ignore
            when computing the XP signature and doing deduplication.
            For instance 'num_workers', etc.
        git_save (bool): when True, experiments can only be scheduled from a clean repo.
            A shallow clone of the repo will be made and execution will happen from there.
            This does not impact `dora run` unless you pass the `--git_save` flag.
        shared (Path or None): if provided, the path to a central repository of XPs.
            For the moment, this only supports sharing hyper-params, logs etc. will stay
            in the per user folder.
        grid_package (str or None): if provided, package to look for grids. Default
            to the package with the `train.py` module followed by `.grids`.
    z	./outputsdirr/   r9   Fgit_saveNsharedgrid_packagezhistory.jsonhistoryxpsshepzrendezvous.txtrendezvous_fileuse_rendezvousgrids_gridscodes_codesarg_namereturnc                 B    | j                   D ]  }t        ||      s y y)zUReturn True if the given argument name should be excluded from
        the signature.TF)r9   r   )selfrh   patterns      r   is_excludedzDoraConfig.is_excluded   s)     || 	Gx)	 r   c                 `    |dv rddl m} |t         ||            }t        |   ||       y )N)r[   r]   r$   )to_absolute_path)r\   ro   r   super__setattr__)rk   namer   ro   r   s       r   rq   zDoraConfig.__setattr__   s4    $$2 -e45D%(r   )r<   r=   r>   r?   r   r[   rA   r   rE   r9   rC   rF   r   r\   rG   r]   rD   r^   r_   r`   rP   ra   rb   rc   re   rg   rm   rq   __classcell__)r   s   @r   rZ   rZ      s    $ [!C!!$7GRWWS\7Hd $FBKK$%)L"++c") "GS!CZ8D*8+OS+ ND FCFCC D ) )r   rZ   )r?   argparser   dataclassesr   r   r   pathlibr   typingrC   omegaconf.dictconfigr   	omegaconfr	   Anyr   r!   r#   rJ   rP   rZ   rH   r   r   <module>r{      s     (    + *266 * *FBFF F F /% /% /%d   ( 
 
 
 1) 1) 1)r   