
    'i                         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	Z	 ddl
mZ ddlmZ dd	lmZ  G d
 d      ZdeddfdZdeddfdZdeddfdZdeddfdZdefdZdeddfdZdeddfdZdeddfdZy)    N)Path)AnyTuple   )utils)Job)JobEnvironment   )debugc                   4    e Zd ZdZdeddfdZdededefdZy)	CheckFunctionz8Function used for checking that computations are correctnreturnNc                 p    t        t        |            | _        t        t        dd|z               | _        y )N
   )listrangedata1data2)selfr   s     S/var/www/stems/demucs_env/lib/python3.12/site-packages/submitit/local/test_debug.py__init__zCheckFunction.__init__   s(    %(^
%BF+,
    xyc                 L    || j                   v sJ || j                  v sJ ||z   S N)r   r   )r   r   r   s      r   __call__zCheckFunction.__call__   s+    DJJDJJ1ur   )__name__
__module____qualname____doc__intr   floatr    r   r   r   r      s2    B-# -$ -% E e r   r   tmp_pathr   c                    dt         dt         fd}t        j                  |       }|j                  |d      }|j	                         dk(  sJ |j                         5  |j                  |d      }d d d        j	                         dk(  sJ d |j                         _        |j	                         dk(  sJ y # 1 sw Y   IxY w)Npr   c                     d| z  S )Nr   r%   )r(   s    r   funcztest_debug_job.<locals>.func"   s    1ur            r   )r#   r   DebugExecutorsubmitresultbatch
submissionfunction)r&   r*   executorjobjob2s        r   test_debug_jobr7   !   s       ""8,H
//$
"C::<1		 (tQ'(;;=B!%DOO;;=B( (s   B88Cc                 v   t        d      }t        j                  |       }|j                  ||j                  |j
                        }t        t        |d                t        |       t        t        ||j                  |j
                              |D cg c]  }|j                          c}k(  sJ y c c}w )Nr-   r   )r   r   r.   	map_arrayr   r   printtyper   mapr0   )r&   gr4   jobsjs        r   test_debug_map_arrayr@   0   s    aA""8,Ha!''2D	$tAw-	$KAqww()$-GQahhj-GGGG-Gs   B6c           	         t        d      }t        j                  |       }t        |j                  |j
                        D cg c]  \  }}t        j                  |||       }}}|j                  |      }t        t        ||j                  |j
                              |D cg c]  }|j                          c}k(  sJ y c c}}w c c}w )Nr-   )r   r   r.   zipr   r   	functoolspartialsubmit_arrayr   r<   r0   )r&   r=   r4   r   r   fnsr>   r?   s           r   test_debug_submit_arrayrG   9   s    aA""8,H25aggqww2G
H$!Q9Q1%
HC
H  %DAqww()$-GQahhj-GGGG I-Gs   !C&Cc                     dd}t        j                  |       }|j                  |      }|j                         }t	        |t
              sJ |j                  d   }d|v sJ y )Nc                      t        d      )NFailed on purpose)RuntimeErrorr%   r   r   failing_jobz%test_debug_error.<locals>.failing_jobB   s    .//r   r   rJ   )r   N)r   r.   r/   	exception
isinstancerK   args)r&   rL   r4   r5   rM   messages         r   test_debug_errorrQ   A   s^    0 ""8,H
//+
&CIi...nnQG')))r   c                       y)N*   r%   r%   r   r   f_42rT   M   s    r   c                 :   dt         dt        t        t        f   fd}t	        j
                  |       }dD ]d  }|j                  t              }|j                  dk(  sJ  ||      dk(  sJ  t        ||              |j                  dk(  sJ  ||      dk(  rdJ  y )	Nr5   r   c                     t        | t        j                        sJ | j                  j                  | j                  j
                  fS r   )rN   r   DebugJob_submission_done_result)r5   s    r   
get_resultz(test_debug_triggered.<locals>.get_resultR   s5    #u~~...%%s'>'>??r   )waitdonerM   resultsQUEUED)FNDONE)TrS   )
r   r   boolr   r   r.   r/   rT   stategetattr)r&   r[   r4   triggerr5   s        r   test_debug_triggeredre   Q   s    @ @dCi 0 @ ""8,H; -ood#yyH$$$#-///WyyF"""#*,,,-r   c                 P   t        j                  |       }|j                  t              }|j                  dk(  sJ |j                          |j                  dk(  sJ t        j                  t        j                  d      5  |j                          d d d        y # 1 sw Y   y xY w)Nr_   	CANCELLEDzwas cancelled)match)r   r.   r/   rT   rb   cancelpytestraisesr   UncompletedJobErrorr0   )r&   r4   r5   s      r   test_cancelrm   `   s    ""8,H
//$
C99   JJL99###	u00	H 

  s   BB%c                     t        j                  |       }d }|j                  |      }|j                          dt        j
                  vsJ y )Nc                      t               } | j                  dk(  sJ | j                  dk(  sJ | j                  dk(  sJ | j                  dk(  sJ | j
                  dk(  sJ d| j                  v sJ y )Nr
   r   DEBUG)r	   	num_nodes	num_tasksnodeglobal_rank
local_rankjob_id)envs    r   use_envz%test_job_environment.<locals>.use_envm   st    }}!!!}}!!!xx1}}!###~~"""#**$$$r   SUBMITIT_DEBUG_JOB_ID)r   r.   r/   r0   osenviron)r&   r4   rx   r5   s       r   test_job_environmentr|   j   sB    ""8,H% //'
"CJJL""**444r   )rC   rz   pathlibr   typingr   r   rj   corer   	core.corer   core.job_environmentr	    r   r   r7   r@   rG   rQ   r#   rT   re   rm   r|   r%   r   r   <module>r      s     	      1 
 
T d H4 HD HHd Ht H	*t 	* 	*c -4 -D -$ 4 54 5D 5r   