o
    rri                     @   s   d Z ddlZddlmZ ddlmZ ddlmZ ddlm	Z	m
Z
mZ ddlmZ dd	lmZmZ dd
lmZ dd Zdd Zdd Zdd ZedkrOe  dS dS )z
This is the central dispatch of the `dora` command. From there you can
check grid files, launch XPs, check their logs etc, as well
as doing local runs for debugging.
    N   )grid_action)info_action)launch_action)fatalsetup_logging
simple_log)
run_action)import_actionexport_action)get_mainc                 C   sN   | j ddddd | j ddddd | j d	d
ddd | j dddd dd d S )Nz-rz--retry
store_truezRetry failed jobsactionhelpz-Rz	--replacezReplace any running job.z-Dz--replace_donezAlso resubmit done jobs.z--no_git_savestore_falsegit_savez6Temporarily deactivate git_save for any scheduled job.r   destdefaultr   )add_argumentparser r   A/home/ubuntu/.local/lib/python3.10/site-packages/dora/__main__.pyadd_submit_rules   s   



r   c                 C   sX   | j ddtdd | j dddd | j d	d
dddd | j dddd | j ddd d S )Nz-gz--gpuszNumber of gpus.typer   z-pz--partitionz
Partition.r   z--devstore_const	partitiondevlabzUse dev partition.)r   r   constr   z-cz	--commentzComment.z--constraintzConstraint.)r   intr   r   r   r   add_slurm_config"   s   r$   c            	      C   s2  t  } | jddd dd | jdd dd | jddd	d
d | jddddd}|d}t| t| |jddd	dd |jdd	dd |jdddtdd |jddddd |jd d	d!d |jd"d#td$d% |jd&d'd	d(d |	 }|jd)d*td+d% |jd,d-td.d% |jd/d0td.d% |jd1d	d2d |jdd3d4d5 |jd6d7d8d5 |j
td9 |jd:d;d<}|jd)d=d>d< |jd?d@d	dAd |jdBtdCd% |jdDd	dEdFdG |jdd	dHd |jdId7dJ |j
td9 |dK}|jd)d=d>d< |jdLdMd	dNd |jdOddPddQdR |jddd	dSd |jdd	dHd t| t| |jdId7dJ |j
td9 |dT}|jd)d=d>d< |jdUdVdWd< |jddd	dXd |jd,d-d	dYd |jd/d0d	dZd |jd[d\d	d]d |jdId7dJ |j
td9 |d^}|j
td9 |d_}|jd`d7dad5 |j
td9 | S )bNz	--packagez-PzTraining module. You can also set the DORA_PACKAGE env. In last resort, Dora will look for a package in the current folder with module defined at --runfile flag.)r   r   z--main_modulezTraining exec name. Dora will search for this module to run within the package provided by --package flag. You can also set DORA_MAIN_MODULE env. Defaults to 'train' module.z	--verbosez-vr   zShow debug info.r   commandzCommand to executeT)titler   requiredr   gridz-Cz--cancelzCancel all running jobs.z--clearz=Remove XP folder, reschedule all jobs, starting from scratch.z-iz
--interval   zIUpdate status and metrics every that number of minutes. Default is 5 min.)r   r   r   z--no_monitoringr   monitorz5No monitoring, just schedule and print current state.)r   r   r   z	--dry_runz9Only simulate actions but does not run any call to Slurm.z-Tz--trimz;Trim history to the length of the exp with the given index.r   z-Lz--trim_lastzTrim history to the slowest.z-fz--folderz0Show the folder for the job with the given indexz-lz--logz-Show the log for the job with the given indexz-tz--tailz--initz=Init the given XPs so that their signature can be referenced.?zKName of the grid to run. Name of the module will be `package`.grids.`name`.)nargsr   patterns*zXOnly handle experiments matching all the given pattern. If empty, handle all experiments)r   runzRun locally the given command.r   z
--from_sigz$Signature of job to use as baseline.z-dz--ddpzDistributed training.z--ddp_workersz5Nb of workers for distributed, default to nb of GPUs.z
--git_saveFzRun from a clean git clone.)r   r   r   z8Remove XP folder, reschedule job, starting from scratch.argv)r,   launchz-az--attachzPAttach to the remote process. Interrupting the command will kill the remote job.z	--no_tailtailz*Does not tail the log once job is started.r   z#Cancel any existing job and return.infoz-jz--job_idzFind job by job id.z
Cancel jobzShow entire logzTail logz-mz	--metricszShow last metricsimportexportsigszAll the XP sigs to export.)argparseArgumentParserr   add_subparsers
add_parserr   r$   floatr#   add_mutually_exclusive_groupset_defaultsr   r	   r   r   r
   r   )	r   
subparsersr(   groupr/   r1   r3   import_r5   r   r   r   
get_parser+   s   














rA   c                  C   s   t  } |  }t|j |jd u rtd t|j|j}t	|dd d urMz|
|j}W n ty=   td|j  Y nw tdd|d|j ||j |_t	|dd d urZ|j|j_||| d S )NzYou must give an action.from_sigz(Could not find an existing run with sig ParserzInjecting argvzfrom sigr   )rA   
parse_argsr   verboser   r   r   main_modulepackagegetattrget_argv_from_sigrB   RuntimeErrorr   r0   r   dora)r   argsmainr0   r   r   r   rM      s"   


rM   __main__)__doc__r7   r(   r   r3   r   r1   r   logr   r   r   r/   r	   sharer
   r   _utilsr   r   r$   rA   rM   __name__r   r   r   r   <module>   s    	j
