B
    ÊÒÐ_“  ã               @   s  d Z ddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZ ddlmZmZ ddlZddlm  mZ ddlmZ ddlZejded dd	„ Zd
d„ ZG dd„ dƒZdd„ Zdd„ Zdd„ Zedkreejdd… ƒZ ee ƒZ!e! "¡  e j#dkre! $¡ Z%dS )a‡  
Functions related to batch job submission.
Should be run with a file containing jobs to submit as a batch.
Optional parameters for job submission are, --memory, --walltime, and --queuename.
Generates job scripts, runs them, and waits for output files to be written before exiting.


This script has functions to support submitting two different job types: a script as a job or a batch file consisting of
multiple parallel tasks. submitting a script as a job is done calling the function: submit_script
However submitting a batch file (calling submit_batch_jobs) can be done in 5 different ways with or without launcher.
Two environmental variables have to be set: JOB_SUBMISSION_SCHEME and QUEUENAME  (set in '~/accounts/platforms_defaults.bash')
QUEUENAME has defaults based on platforms. comment/uncomment or introduce a new one
JOB_SUBMISSION_SCHEME: it can have one of these options:

singleTask                     ---> submit each task of a batch file separately in a job
multiTask_singleNode           ---> distribute tasks of a batch file into jobs with one node
multiTask_multiNode            ---> submit tasks of a batch file in one job with required number of nodes
launcher_multiTask_singleNode  ---> distribute tasks of a batch file into jobs with one node, submit with launcher
launcher_multiTask_multiNode   ---> submit tasks of a batch file in one job with required number of nodes using launcher

é    N)Úmessage_rsmas)Úqueue_config_fileÚsupported_platforms)ÚdatetimeÚignore)Úcategoryc              C   sÄ   t jt jd} |  dd¡}|jdtdd |jddtd	d
d |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 |jdd td!d"d |jd#d$d%d&d' |jd(d)d%d*d' | S )+a  
    Creates an argument parser for parsing parameters for batch job submission.
    Required parameter: file to batch create
    Optional parameters: template file, memory, walltime, and queue name
    :return: ArgumentParser object for parsing command line batch job submission
    )Úformatter_classz
Input FilezFile/Dataset to displayÚfilezThe file to batch create)ÚtypeÚhelpz
--templateÚcustom_template_fileztemplate filez&custom template with option settings.
)Údestr
   Úmetavarr   z--memoryÚmemoryzMEMORY (KB)z4Amount of memory to allocate, specified in kilobytes)r   r   r   z
--walltimeÚ	wall_timezWALLTIME (HH:MM)z+Amount of wall time to use, in HH:MM formatz--queueÚqueueÚQUEUEzName of queue to submit job toz--outdirÚout_dirÚ	run_filesZOUTDIRzoutput directory for run files)r   Údefaultr   r   z--numBurstsÚ
num_burstsznumber of burstsz&number of bursts to calculate walltimez--writeonlyÚ	writeonlyÚ
store_truez"Write job files without submitting)r   Úactionr   z--remoraÚremoraz!use remora to get job information)ÚargparseÚArgumentParserÚRawTextHelpFormatterÚadd_argument_groupÚadd_argumentÚstrÚint)ÚparserÚgroup© r$   ú</home/centos/operations/rsmas_insar/minsar/job_submission.pyÚcreate_argument_parser,   s"    



r&   c             C   s”   t ƒ }| | ¡}yt d¡}W n   t ¡ }Y nX tj |j¡|_tj ||j 	tj 
|¡¡d  d¡d ¡|_|jdkrtj |j|j¡|_|S )z·
    Parses command line arguments into namespace.
    :param args: Arguments to parse
    :return: Namespace with submission parameters (from command line arguments or defaults)
    ZSCRATCHé   ú/r   )r&   Ú
parse_argsÚosÚgetenvÚgetcwdÚpathÚabspathr	   ÚjoinÚrsplitÚbasenameÚsplitÚwork_dirr   )Úargsr"   Z
job_paramsZscratch_dirr$   r$   r%   Úparse_argumentsH   s    
&
r5   c               @   s€   e Zd ZdZdd„ Zddd„Zddd	„Zd d
d„Zdd„ Zd!dd„Z	dd„ Z
d"dd„Zdd„ Zd#dd„Zd$dd„Zd%dd„ZdS )&Ú
JOB_SUBMITz<
        A class representing the job submission object
    c          
   C   s˜  x$|j  ¡ D ]}t| ||j | ƒ qW d|krV|jdkrVtj t d¡d¡| _d| _ntj t d¡d¡| _d| _t	|ƒ\	| _
| _| _| _| _| _| _| _| _d|ks¬|js²d | _d|ksÀ|jsÆd | _d	|ksÔ|jsÚd | _d
|ksè|jsð| j| _d|krþd| _d|krd | _d | _d | _d | _d|ks2|js8d| _d| _g | _y(t | j d ¡d }||j!|jd < W n    t"d #| j d ¡ƒ Y nX || _$d S )NÚprefixÚstripmapÚ
ISCE_STACKÚstripmapStackÚ	topsStackÚtopsr   r   r   r   r   Ú.r   Úreserve_noder'   Tz/DEM/*.wgs84r   zStack.demDirzDEM does not exist in {}z/DEM)%Ú__dict__ÚkeysÚsetattrr7   r*   r-   r/   r+   Ú
stack_pathÚset_job_queue_valuesÚsubmission_schemeÚplatform_nameÚ	schedulerÚ
queue_nameÚnumber_of_cores_per_nodeÚnumber_of_threads_per_coreÚmax_jobs_per_queueÚmax_memory_per_nodeÚwall_time_factorr   r   r   r   r   r   Údefault_memoryÚdefault_wall_timeÚdefault_num_threadsr>   Úemail_notifÚ	job_filesÚglobr3   ÚtemplateÚprintÚformatÚinps)ÚselfrV   ÚkZdem_filer$   r$   r%   Ú__init__e   sB    ,
zJOB_SUBMIT.__init__NÚFalsec             C   sÀ   t j | j¡s4t j | j¡r(t  | j¡ t  | j¡ |dk	rB|| _t j |d ¡d }|d 	dd„ |dd… D ƒ¡7 }| j
|dd g | _| j|||| j| jd	 |d
kr¼| j| j| jd dS )aŸ  
        Submits a single script as a job. (compare to submit_batch_jobs for several tasks given in run_file)
        :param job_name: Name of job.
        :param job_file_name: Name of job file.
        :param argv: Command line arguments for running job.
        :param email_notif: If email notifications should be on or not. Defaults to true.
        :return job number of the script that was submitted
        Nr   ú c             s   s   | ]}|d kr|V  qdS )z--submitNr$   )Ú.0Úflagr$   r$   r%   ú	<genexpr>¤   s    z+JOB_SUBMIT.submit_script.<locals>.<genexpr>r'   Úscript)Újob_type)r3   Únumber_of_nodesrZ   )r3   )r*   r-   Úisdirr3   ÚisfileÚremoveÚmakedirsrP   r1   r/   Úget_memory_walltimerQ   Úwrite_single_job_filer>   Úsubmit_and_check_job_status)rW   Újob_nameÚjob_file_nameÚargvrP   Z	writeOnlyÚcommand_liner$   r$   r%   Úsubmit_script’   s    	 
zJOB_SUBMIT.submit_scriptc          	   C   sl  |dkr| j }|dk	r|| _t | jdj|| jd¡ g | _| jt	kr6t
d | j¡ƒ | j|dd t|dƒ}| ¡ }t|ƒ}W dQ R X t t |t| jƒ | j| j  ¡¡}d| jkrÈ|  |¡ nnd	| jkr|d
 }tj |¡}| j||t|ƒ|| jd}	| j | j|	||d¡ nd| jkr6|  |||¡ t| jƒdkrhx | jD ]}
t  d |
¡¡ qNW dS )zã
        creates jobs based on scheduler
        :param batch_file: batch job name
        :param email_notif: If email notifications should be on or not. Defaults to true.
        :return: True if running on a cluster
        Nz.job_submission.py {a} --outdir {b} --writeonly)ÚaÚbz
Working on a {} machine ...
Úbatch)r`   ÚrZ
singleTaskZmultiTask_multiNodeZ_0)Únumber_of_tasksra   r3   )Ú
batch_fileZmultiTask_singleNoder   zchmod +x {})!r	   rP   r   Úlogr3   rU   r   rQ   rE   r   rT   rF   rf   ÚopenÚ	readlinesÚlenÚnpr!   ÚceilÚfloatrO   rH   rI   rD   Úwrite_batch_singletask_jobsr*   r-   r1   Úget_job_file_linesÚappendÚadd_tasks_to_job_file_linesÚ
split_jobsÚsystem)rW   rs   rP   ÚfÚtasksrr   ra   Úbatch_file_nameri   Újob_file_linesÚjob_filer$   r$   r%   Úwrite_batch_jobs±   s:    
zJOB_SUBMIT.write_batch_jobsc          	   C   s–   t | jƒdkr$| j| j| jd dS tdƒ t d¡}t|dƒH}| ¡ }| j	dkrZd}nd	}x$|D ]}t 
|| ¡ |tjd< qdW W d
Q R X dS d
S )zâ
        submit jobs based on scheduler
        :param batch_file: batch job name
        :param email_notif: If email notifications should be on or not. Defaults to true.
        :return: True if running on a cluster
        r   )r3   Tz!
Working on a single machine ...
ÚPATHrq   r8   z-export PATH=$ISCE_STACK/stripmapStack:$PATH; z)export PATH=$ISCE_STACK/topsStack:$PATH; NF)rw   rQ   rh   r   rT   r*   r+   ru   rv   r7   r€   Úenviron)rW   rs   Úsystem_pathr   Zcommand_linesÚcmdrl   r$   r$   r%   Úsubmit_batch_jobsæ   s    


zJOB_SUBMIT.submit_batch_jobsc             C   s  d}| j dkr"dtj ||¡ }nš| j dkr@dtj ||¡ }n|| j dkr¬tjddtjdj ¡  	d	¡}| 
d
¡s|| 
d¡r’d tj ||¡¡}q¼d tj ||¡¡}d}ntd | j ¡ƒ‚tj|tjdd}|rüt d| 	d	¡¡}ttdd„ |D ƒƒƒ}nd}|S )zí
        Submit a single job (to bsub or qsub). Used by submit_jobs_individually and submit_job_with_launcher and submit_script.
        :param job_file_name: Name of job file to submit.
        :return: Job number of submission
        TÚLSFzbsub < ÚPBSzqsub < ÚSLURMÚhostname)ÚshellÚstdoutzutf-8ÚloginÚcometz	sbatch {}z{}Fz"ERROR: scheduler {0} not supported)Ústderrr   z\d+c             S   s   g | ]}t |ƒ‘qS r$   )r!   )r\   Úxr$   r$   r%   ú
<listcomp>  s    z0JOB_SUBMIT.submit_single_job.<locals>.<listcomp>ÚNone)rF   r*   r-   r/   Ú
subprocessÚPopenÚPIPEr‘   ÚreadÚdecodeÚ
startswithrU   Ú	ExceptionÚcheck_outputÚSTDOUTÚreÚfindallr    Úmax)rW   rj   r3   Zjob_num_existsÚcommandr   Z
output_jobÚ
job_numberr$   r$   r%   Úsubmit_single_job  s$    


zJOB_SUBMIT.submit_single_jobr'   c          	   C   s¦   | j ||||d}| d¡ | jr@| d¡ | d| d ¡ n| d| d ¡ d |¡}ttj ||¡dƒ}| |¡ W dQ R X | j	 |¡ t 
d	 |¡¡ dS )
a  
        Writes a job file for a single job.
        :param job_name: Name of job.
        :param job_file_name: Name of job file.
        :param command_line: Command line containing process to run.
        :param work_dir: working or output directory
        )r3   ra   z
freez
module load remoraz
remora Ú
z{0}.jobzw+Nzchmod +x {})r|   r}   r   rU   ru   r*   r-   r/   Ú
writelinesrQ   r€   )rW   ri   rj   rl   r3   ra   r„   r…   r$   r$   r%   rg   #  s    




z JOB_SUBMIT.write_single_job_filec          	   C   sn   t |ƒ}| ¡ }W dQ R X xLt|ƒD ]@\}}tj |¡ tj¡d d t|ƒ }| j	|||| j
d q&W dS )ab  
        Iterates through jobs in input file and writes a job file for each job using the specified scheduler. This function
        is used for batch jobs in pegasus (LSF) to split the tasks into multiple jobs
        :param batch_file: File containing batch of jobs for which we are creating job files.
        :return: List of job file names.
        NéÿÿÿÿÚ_)r3   )ru   rv   Ú	enumerater*   r-   r.   r2   Úsepr    rg   r   )rW   rs   Ú
input_fileZjob_listÚirl   rj   r$   r$   r%   r{   @  s    
$z&JOB_SUBMIT.write_batch_singletask_jobsc          
   C   st  g }g }g }x|D ]ˆ}t  d t j ||¡¡¡ |  ||¡}t j |d | d¡d |¡¡}t j |d | d¡d |¡¡}	| |¡ | |¡ | |	¡ qW d}
d}d}t 	d¡ | j
dkr–g }t j |d	¡}xt||ƒD ]\}}|d
ksàd}xì|dkrât  d ||¡¡ t 	d¡ t|dƒ}| ¡ }t|ƒdk rBwøW dQ R X d|d kshd|d krœtd ||¡ƒ ||d 7 }t 	|d ¡ |
d7 }
qød|d kr°d}qød|d krÎd}| |¡ qød}td |¡ƒ‚qøW qàW t|ƒdkröxŒ|D ]„}t |¡}tj|dd}t ||¡ t t ¡ d¡}|d t j |¡ d | d | }t| jd  d!ƒ}| |¡ W dQ R X qüW | j|| jd" n`x^t||ƒD ]P\}}d
|kr¢x:t j |¡sîtd ||¡ƒ ||d 7 }t 	|¡ q¶W q¢W xx|D ]p}t | d¡d d# ¡}xP|D ]H}t|d$ƒt|d%ƒt|d&ƒt|d'ƒg}t  |¡ !¡ rtd( |¡ƒ‚qW qüW dS ))aƒ  
        Writes a single job file for launcher to submit as array. This is used to submit jobs in slurm or sge where launcher
        is available (compare to submit_jobs_individually used on pegasus with LSF)
        :return:
        :param batch_file: File containing tasks that we are submitting.
        :param work_dir: the directory to check outputs and error files of job
        zchmod +x {}z{}_{}.or=   r   z{}_{}.eé<   é   rŽ   Z
job_statusr—   Úwaitz!sacct --format="State" -j {} > {}rq   é   NZPENDINGZRUNNINGz/Waiting for job {} output file after {} minutesr'   Z	COMPLETEDÚcompleteZTIMEOUTÚtimeoutÚfailedz'Error: {} job was terminated with Errorg333333ó?)Úfactorz%Y%m%d:%H-%Mz: re-running: z: z --> z/run_files/rerun.logrn   )r3   z*.ezSegmentation faultZAbortedÚERRORÚErrorzError terminating job: {})"r*   r€   rU   r-   r/   r¦   r2   r}   ÚtimeÚsleeprF   Úzipru   rv   rw   rT   ÚRuntimeErrorÚputilsÚextract_walltime_from_job_fileÚmultiply_walltimeÚreplace_walltime_in_job_filer   ÚstrftimeÚnowr1   r3   r¨   rh   ÚexistsrR   Úcheck_words_in_filerx   ÚarrayÚany)rW   rQ   r3   Zjob_numbersZjobs_outZjobs_errrj   Zjob_numÚoutÚerrr®   Zwait_time_secZtotal_wait_time_minZrerun_job_filesZjob_status_filer¥   Zjob_statZ	stat_fileÚstatusr   Únew_wall_timeÚdateStrÚstringZrerunÚerror_filesÚerrfileZjob_exitr$   r$   r%   rh   P  s†    	
  






$


z&JOB_SUBMIT.submit_and_check_job_statusc                s   |}d}x(|t | jƒkr0|d }t || ¡}q
W t t t|ƒ| ¡ƒ‰ t | j| | j ƒ}x<|ˆ k r˜|t | jƒk r”|d7 }t t t|ƒ| ¡ƒ‰ q^P q^W x(|ˆ k rÂ|d }t | j| | j ƒ}qœW t ˆ | ¡| _|dkrêt	d 
|¡ƒ tjdt|ƒˆ …  ¡ }‡ fdd„|D ƒ}t|ƒ|d< xzt||ƒD ]l\}	}
| |	¡}|d 
|¡ }tj |¡}| j|||
|	 || jd}| j|||	|
… |d	}| j |¡ q,W d
S )zÝ
        splits the batch file tasks into multiple jobs with one node
        :param batch_file:
        :param tasks:
        :param number_of_nodes: Total number of nodes required for all tasks
        :return:
        r'   z|Note: Number of jobs exceed the numbers allowed per queue for jobs with 1 node...
Number of Nodes per job are adjusted to {}r   c                s   g | ]}|ˆ  ‘qS r$   r$   )r\   r•   )Únumber_of_parallel_tasksr$   r%   r–   Ñ  s    z)JOB_SUBMIT.split_jobs.<locals>.<listcomp>r©   z_{})rr   ra   r3   )rs   N)r!   rJ   rx   ry   rw   rK   rM   ÚmathÚ!number_of_parallel_tasks_per_noderT   rU   ÚogridÚtolistr»   Úindexr*   r-   r1   r|   r   r~   rQ   r}   )rW   rs   r‚   ra   Znumber_of_jobsZnumber_of_nodes_per_jobZnumber_of_limited_memory_tasksZstart_linesZ	end_linesZ
start_lineZend_lineZ	job_countrƒ   ri   r„   rj   r$   )rÏ   r%   r   ª  s@    	


zJOB_SUBMIT.split_jobsrp   c       
      C   sŠ  t jdd}|dkr<d}| | d¡d  d¡dd… ¡}n|}| jd	krj|dkrj| jdkrjt  | j¡| _| jrx| j}nd
}| jdkrÒ||kr¨|| d }|| d }n|d d }|d d }t  	|||¡| _
n| j| _
| jdkr<||kr
|| d }|| d }	n|d d }|d d }	t  || j||	| j¡| _n
| j}d}	t  || j||	| j¡| _||krx|| d | _n|d d | _dS )z¶
        get memory, walltime and number of threads for the job from job_defaults.cfg
        :param job_name: the job file name
        :param job_type: 'batch' or 'script'
        zjob_defaults.cfg)Úconfig_filerp   rª   r(   r©   r°   Nr<   r'   )Nr—   Úc_memoryÚs_memoryr   Ú
c_walltimeÚ
s_walltimeÚ0Únum_threads)r½   Úget_config_defaultsr/   r2   r7   r   Úget_number_of_burstsrV   r   Úscale_memoryrM   r   Úscale_walltimerL   rF   rN   rO   )
rW   ri   r`   ÚconfigÚ	step_nameÚnumber_of_burstsrÖ   r×   rØ   rÙ   r$   r$   r%   rf   ã  sF    $





zJOB_SUBMIT.get_memory_walltimec             C   s  || j  }| jdkrN|}d}d}d}d}	d| d }
d}d	}d
}d}d}d}n˜| jdkrŽd}d}d}d}	d}
d}d}d
}d}d}d| d }nX| jdkrÖd}d}d}d}	d| d }
d}d	}d}d| d }d}d }ntd! | j¡ƒ‚| jd"krø|d#9 }d$| || tj |¡¡ ||	 t d%¡¡ g}| j	rJ| 
|| t d&¡¡ ¡ | ||
 ||¡ || tj ||¡¡ || tj ||¡¡ || | j¡ || | j¡ g¡ |rÔd'| jkrÔ| || | j¡ g¡ | jdkrî| 
|d( ¡ | jd)kr| 
|d* ¡ |S )+aÇ  
        Generates the lines of a job submission file that are based on the specified scheduler.
        :param job_name: Name of job.
        :param job_file_name: Name of job file.
        :param number_of_tasks: Number of lines in batch file to be supposed as number of tasks
        :param number_of_nodes: Number of nodes based on number of tasks (each node is able to perform 68 tasks)
        :return: List of lines for job submission file
        rŒ   z
#BSUB z	/bin/bashz-J {0}z-P {0}z-n {0}z-R span[hosts={1}]z-o {0}_%J.oz-e {0}_%J.ez-q {0}z-W {0}z-M {}z	-B -u {0}r   z
#PBS z-N {0}z-A {0}z-l nodes={0}:ppn={1}z-o {0}_$PBS_JOBID.oz-e {0}_$PBS_JOBID.ez-l walltime={0}z
-l mem={0}z-m beaz-M {0}rŽ   z	
#SBATCH z-n {1}z-p {0}z--mail-user={}z--mail-type=failz-t {0}Fz"ERROR: scheduler {0} not supportedÚparallelé   z#! ZJOBSHEDULER_PROJECTNAMEZNOTIFICATIONEMAILÚlauncherz-VZgpuz--gres=gpu:4)rH   rF   rž   rU   r   r*   r-   r1   r+   rP   r}   Úextendr/   rN   rD   rM   )rW   ri   rj   rr   ra   r3   r7   r   Zname_optionZproject_optionZprocess_optionZstdout_optionZstderr_optionZqueue_optionZwalltime_limit_optionZmemory_optionZemail_optionr„   r$   r$   r%   r|      sx    





zJOB_SUBMIT.get_job_file_linesc             C   sÌ  d}| j dkrDtjddtjdj ¡  d¡}| d¡r@| d¡sDd}d	 |¡}g }d
| j	ksb|rÚxf|D ]^}t
 |¡}	t
 |	¡}
| d | d¡d tj |¡d |
 d tj |¡d |
 d ¡¡ qhW tj |¡ràt |¡ t|dƒ}| |¡ W dQ R X | jr| d¡ | d¡ | d | j¡¡ | d | j¡¡ | d | j¡¡ | d | j¡¡ | d |¡¡ | jr¢| d¡ | dtj |¡ d ¡ n
| d¡ ttj | j|¡dƒ}| |¡ W dQ R X nîxXt|ƒD ]L\}}| d | d¡d tj |¡d |¡ tj |¡d  |¡ ¡¡ qäW | j dkrJ| d!¡ | d" | j¡¡ | d | j¡¡ | d¡ x|D ]}| |¡ q~W | d#¡ ttj | j|¡dƒ}| |¡ W dQ R X |S )$a^  
        complete job file lines based on job submission scheme. if it uses launcher, add launcher specific lines
        :param job_file_lines: raw job file lines from function 'get_job_file_lines'
        :param tasks:number of tasks to be include in this job
        :param batch_file: name of batch file containing tasks
        :return:
        FrŽ   r   T)r   r‘   zutf-8r’   r“   z{0}.jobrå   z{} > {} 2>{}
r§   r   rª   z_$LAUNCHER_JID.oz_$LAUNCHER_JID.ezw+Nz

module load remoraz

module load launcherz
export OMP_NUM_THREADS={0}z
export PATH={0}:$PATHz
export LAUNCHER_WORKDIR={0}z
export LAUNCHER_PPN={0}
z
export LAUNCHER_JOB_FILE={0}
z
remora $LAUNCHER_DIR/paramrun
z 
mv remora_$SLURM_JOB_ID remora_z_$SLURM_JOB_ID
z
$LAUNCHER_DIR/paramrun
z{} > {} 2>{} &
z_{}.oz_{}.ezC
export LD_PRELOAD=/home1/apps/tacc-patches/python_cacher/myopen.soz

export OMP_NUM_THREADS={0}z
wait)rF   r˜   r™   rš   r‘   r›   rœ   r   rU   rD   r½   Ú$extract_config_file_from_task_stringÚ)extract_date_string_from_config_file_namer}   r2   r*   r-   r.   rÃ   rd   ru   r¨   r   rO   rB   r   rÑ   r1   r/   r«   )rW   r„   r‚   rs   Zdo_launcherr   rj   Ztasks_with_outputÚlinerÕ   Údate_stringZbatch_fZjob_fÚcountr$   r$   r%   r~   y  s^    




 




 



z&JOB_SUBMIT.add_tasks_to_job_file_lines)NrZ   )NN)N)Nr'   )N)rp   )r'   r'   N)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__rY   rm   r†   r‹   r¦   rg   r{   rh   r   rf   r|   r~   r$   r$   r$   r%   r6   `   s   -

5
!

Z9
=
Yr6   c          	      sN   t | dƒ}| ¡ }W dQ R X ‡ fdd„|D ƒ}t d| ¡dkrFdS dS dS )	zÈ
    Checks for existence of a specific word in a file
    :param errfile: The file to be checked
    :param eword: The word to search for in the file
    :return: True if the word is in the file
    rq   Nc                s   g | ]}ˆ |k‘qS r$   r$   )r\   Úitem)Úewordr$   r%   r–   Ü  s    z'check_words_in_file.<locals>.<listcomp>r'   r   TF)ru   rv   rx   Úsum)rÎ   rñ   r   ÚlinesZcheck_ewordr$   )rñ   r%   rÄ   Ñ  s    rÄ   c          
   C   sL  t | ƒ}|d }|dkr2t d¡r.t d¡}nd}tjddtjdj ¡  d¡}x t	D ]}||krj|}P qVd }qVW | j
r„| j
|d	< nt d	¡rœt d	¡|d	< |d	 |d
 |d |d |d |d dœ}xN| ¡ D ]B}|| dksÐ|dkrút|| ƒ||< qÐ|dksÐt|| ƒ||< qÐW |t	kr˜ttdƒ}| ¡ }	W d Q R X x(|	D ] }
|
 d¡rD|	d  ¡ }P qDW x,|	D ]"}
|
 d¡sp|
 |¡rp|
 ¡ }|| d	¡ }|d dkrº||d< ||d kr€|d dkrìt|| d
¡ ƒ|d< |d dkrt|| d¡ ƒ|d< |d dkr4t|| d¡ ƒ|d< |d dkrXt|| d¡ ƒ|d< |d dkr|t|| d¡ ƒ|d< P n|dkrqpnP qpW |dkr¨d}n$|dkr¸d}n|d krÈd!}nd }d d"d#d#d$d#g}d}x8| ¡ D ],\}}|| dkrê|| ||< |d#7 }qêW ||||d |d |d |d |d |d f	}|S )%NÚjob_submission_schemeÚautoZJOB_SUBMISSION_SCHEMEZlauncher_multiTask_singleNodezhostname -fT)r   r‘   zutf-8Ú	QUEUENAMEÚCPUS_PER_NODEÚTHREADS_PER_COREÚMAX_JOBS_PER_QUEUEÚWALLTIME_FACTORÚMEM_PER_NODE)rG   rH   rI   rJ   rL   rK   rL   rG   rq   ZPLATFORM_NAMEr   ú#)rõ   ÚNONEr—   rH   rI   rJ   rK   r—   )Ú	stampede2Úfronterar“   rŽ   )ÚpegasusrŒ   )Úeos_sanghoonÚbeijing_serverÚdeqing_serverr   rä   r'   i€>  )Ú"auto_template_not_existing_optionsr*   r+   r˜   r™   rš   r‘   r›   rœ   r   r   r@   rz   r!   ru   r   rv   r   r2   rÔ   Úitems)r4   rS   rD   r   ÚplatformrE   Z
check_autoÚkeyr   ró   ré   Zqueue_headerZsplit_valuesZdefault_queuerF   Zdef_autor®   ÚvalueZout_putsr$   r$   r%   rC   ä  s’    








rC   c             C   sn   dddddddg}| j rPdd	lm} || j ƒj}x8|D ]}||kr6d
||< q6W ni }x|D ]}d
||< qZW |S )Nrö   r÷   rø   rù   rú   rû   rô   r   )ÚTemplaterõ   )r   Úminsar.objects.dataset_templater	  Úoptions)r4   Zjob_optionsr	  rS   Úoptionr$   r$   r%   r  B  s    


r  Ú__main__r'   F)&rï   r*   Úsysr˜   r   r¹   rR   Únumpyrx   rÐ   Úminsar.objectsr   Úminsar.objects.auto_defaultsr   r   ÚwarningsZminsar.utils.process_utilitiesÚutilsÚprocess_utilitiesr½   r   r¡   ÚfilterwarningsÚFutureWarningr&   r5   r6   rÄ   rC   r  rì   rk   ZPARAMSÚjob_objr†   r   r‹   rÉ   r$   r$   r$   r%   Ú<module>   s>       u^
