
    Vh"(                         d dl mZ d dlmZ d dlZd dlZd dlZd dlZd dlZ	ej                  d        ZdddZdddd	Zd
 Z G d d      Zd Zy)    )TracebackType)OptionalNc               #     K   	 d  y # t         $ r} | j                  }g }||j                  j                  j                  }|j                  j
                  j                  d      }|dk(  rE|Bt        j                  ddd      5 }|j                  |       d d d        n# 1 sw Y   nxY w|j                  }t        dj                  d      }|j                  |j                  j                  	      }t        |j                  d
      r;|j                  |j                  j                  |j                  j                         }t#        ||j
                  i |j$                  dt&        j(                  i      }t+        d ||j,                  |j.                        }	|j1                  |	       n|j1                  |       |j2                  }|d }
t5        |      D ]  }|
|_        |}
 | j7                  |
      d } ~ ww xY ww)N__compile_source__z<string>wFz.py)modedeletesuffixz__inspect_currentframe()eval)co_nameco_linetable)r   co_firstlineno__inspect_currentframe)	Exception__traceback__tb_framef_codeco_filename	f_globalsgettempfileNamedTemporaryFilewritecompilenamereplacer   hasattrr   r   r   f_localsinspectcurrentframer   tb_lasti	tb_linenoappendtb_nextreversedwith_traceback)exctbstackfilenamesourcefframecode
fake_framefake_tbr$   s              F/home/dcms/DCMS/lib/python3.12/site-packages/torch/utils/_traceback.pyreport_compile_source_on_errorr2   /   s    S* Q* n{{))55H[[**../CDF:%&*<2 00c%PUV $Z[GGFO$ $ $ 91666J||ELL,@,@|A5<<8  <<%*\\%>%>',||'B'B ( D "OO..0'2F2F
 (*bkk2<< W%R BG nL 5/ 	B BJG	   ))cQ*sD   H		 H	
HA7H
B%	H%B.	*D)H,HHH	basec                   |@t         j                  j                  t         j                  j                  t                    }	 t         j                  j	                  | |g      }| t        |      dz   d S # t        $ r | cY S w xY w)ziShorten a source filepath, with the assumption that torch/ subdirectories don't need to be shown to user.N   )ospathdirname__file__
commonpathlen
ValueError)fnr4   prefixs      r1   shorten_filenamer@      sq    |wwrwwx89$##RJ/ #f+/"##  	s   !A6 6BBF)r4   linec                    d}|r| j                    d}| t        | j                  |       d| j                   d| j                   S )z
    Format a FrameSummary in a short way, without printing full absolute path or code.

    The idea is the result fits on a single line.
     z  # r3   :z in )rA   r@   r*   linenor   )r-   r4   rA   
extra_lines       r1   format_framerG      sQ     J

|4(
\*5>>EFa~UYZ_ZdZdYeff    c                 D    t        t        j                  |       d         S )zJFormat a TracebackType in a short way, printing only the inner-most frame.)rG   	traceback
extract_tbr(   s    r1   format_traceback_shortrN      s    	,,R0455rH   c                   ^    e Zd ZddgZddZd Zd Zd Zedddd	d
       Z	d Z
ed        Zy)CapturedTracebackr(   skipr   c                      || _         || _        y Nr(   rQ   )selfr(   rQ   s      r1   __init__zCapturedTraceback.__init__   s    	rH   c                     d | _         y rS   rM   rU   s    r1   cleanupzCapturedTraceback.cleanup   s	    rH   c                     dd l }| j                  t        j                         S t	        |j
                  j                  j                  | j                  g      d   | j                        S )Nr   )	torch._C._profilerr(   rK   StackSummary_extract_symbolized_tb_C	_profilersymbolize_tracebacksrQ   )rU   torchs     r1   summaryzCapturedTraceback.summary   sT    !77?))++%HH33TWWI>qAII
 	
rH   c                 $    d d | j                   dfS )NrT   )rQ   rX   s    r1   __getstate__zCapturedTraceback.__getstate__   s    II
  	rH   F)scriptcpprQ   c                     ddl }| s|r|dk(  sJ d       t        |j                  j                  j	                  d| |      | s|rd      S |dz         S )a  
        Like traceback.extract_stack(), but faster (approximately 20x faster); it
        is fast enough that you can unconditionally log stacks this way as part of
        normal execution.  It returns a torch._C._profiler.CapturedTraceback
        object that must be formatted specially with format_captured_tb.

        By default, this only reports Python backtraces (like extract_stack).  You
        can set the script/cpp kwargs to also turn on TorchScript/C++ trace
        reporting.
        r   Nzskip with script/cpp NYIT)pythonre   rf   r6   )r[   rP   r^   r_   gather_traceback)re   rf   rQ   ra   s       r1   extractzCapturedTraceback.extract   sg     	"S198889 HH//tFPS/T 3A	
 	
 %)1H	
 	
rH   c                 H    t        j                  | j                               S )al  
        Formats a single torch._C._profiler.CapturedTraceback into a list of
        strings equivalent to the output of traceback.format_list.  Note that if
        pass it CapturedTraceback with C++ traces,  it is better not to use this
        function and use the batch formatting API format_captured_tbs to amortize
        the cost of symbolization
        )rK   format_listrb   rX   s    r1   formatzCapturedTraceback.format   s     $$T\\^44rH   c                    ddl }g }g }t        |       D ]E  \  }}|j                  |j                  g        $|j                  d       |j                  |       G |j                  j
                  j                  |D cg c]  }| |   j                   c}       |D ]+  }t        j                  | |   j                               ||<   - |S c c}w )z_
        Bulk version of CapturedTraceback.format.  Returns a list of list of strings.
        r   N)
r[   	enumerater(   r#   r^   r_   r`   rK   rl   rb   )tbsra   rsdelayed_idxsir(   s         r1   
format_allzCapturedTraceback.format_all   s    
 	" )+s^ 	'EAruu}		"		$##A&	' 	//L0QqQ0QR 	<A))#a&..*:;BqE	< 		 1Rs   ?CN)r   )__name__
__module____qualname__	__slots__rV   rY   rb   rd   staticmethodrj   rm   rt    rH   r1   rP   rP      sS    vI

 U 
 
.5  rH   rP   c           	          t        j                         }t        | |d       D ]1  }|j                  t        j                  |d   |d   |d                3 |S )z
    Given a symbolized traceback from symbolize_tracebacks, return a StackSummary object of
    pre-processed stack trace entries.
    Nr*   rA   r   )rK   r\   r%   r#   FrameSummary)r(   rQ   r)   r,   s       r1   r]   r]      sZ    
 ""$Ebi  RY++AjM1V9aiPQRLrH   )typesr   typingr   r   rK   
contextlibr   os.pathr7   contextmanagerr2   r@   rG   rN   rP   r]   rz   rH   r1   <module>r      sf          N T* T*l "& 
$ !%5 	g6S SlrH   