
    BVh.                     z    d Z ddlZddl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e	j                        Zy)	z?Debugger wrapper session that dumps debug data to file:// URLs.    N)	event_pb2)
debug_data)	framework)gfilec                   $    e Zd ZdZ	 	 	 ddZd Zy)DumpingDebugWrapperSessionz:Debug Session wrapper that dumps debug data to filesystem.Nc                    t         j                  j                  | ||||       t        j                  j                  |      }t        j                  |      rFt        j                  |      st        d|z        t        j                  |      r#t        d|z        t        j                  |       || _        d| _        t        j                         | _        y)a  Constructor of DumpingDebugWrapperSession.

    Args:
      sess: The TensorFlow `Session` object being wrapped.
      session_root: (`str`) Path to the session root directory. Must be a
        directory that does not exist or an empty directory. If the directory
        does not exist, it will be created by the debugger core during debug
        `tf.Session.run`
        calls.
        As the `run()` calls occur, subdirectories will be added to
        `session_root`. The subdirectories' names has the following pattern:
          run_<epoch_time_stamp>_<zero_based_run_counter>
        E.g., run_1480734393835964_ad4c953a85444900ae79fc1b652fb324
      watch_fn: (`Callable`) A Callable that can be used to define per-run
        debug ops and watched tensors. See the doc of
        `NonInteractiveDebugWrapperSession.__init__()` for details.
      thread_name_filter: Regular-expression white list for threads on which the
        wrapper session will be active. See doc of `BaseDebugWrapperSession` for
        more details.
      pass_through_operrors: If true, all captured OpErrors will be
        propagated. By default this captures all OpErrors.

    Raises:
       ValueError: If `session_root` is an existing and non-empty directory or
       if `session_root` is a file.
    )watch_fnthread_name_filterpass_through_operrorsz&session_root path points to a file: %sz5session_root path points to a non-empty directory: %sr   N)r   !NonInteractiveDebugWrapperSession__init__ospath
expanduserr   ExistsIsDirectory
ValueErrorListDirectoryMakeDirs_session_root_run_counter	threadingLock_run_counter_lock)selfsesssession_rootr
   r   r   s         `/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/python/debug/wrappers/dumping_wrapper.pyr   z#DumpingDebugWrapperSession.__init__   s    @ //88dX:L3 9 5 77%%l3L||L!|,4|CE 	E|,C 	 nn\"%DD&^^-D    c                    | j                   j                          t        j                  j	                  | j
                  dt        t        j                         dz        | j                  fz        }| xj                  dz  c_        | j                   j                          t        j                  |       t        j                         }t        |      |j                  _        t        j                  j	                  |t"        j$                  t"        j&                  z         }t        j(                  t        j                  j	                  |      d      5 }|j+                  |j-                                ddd       t        j                         }|rt        |j/                               n
t        |      |j                  _        t        j                  j	                  |t"        j$                  t"        j0                  z         }t        j(                  t        j                  j	                  |      d      5 }|j+                  |j-                                ddd       d|z   gS # 1 sw Y   xY w# 1 sw Y   xY w)aW  Implementation of abstract method in superclass.

    See doc of `NonInteractiveDebugWrapperSession.prepare_run_debug_urls()`
    for details. This implementation creates a run-specific subdirectory under
    self._session_root and stores information regarding run `fetches` and
    `feed_dict.keys()` in the subdirectory.

    Args:
      fetches: Same as the `fetches` argument to `Session.run()`
      feed_dict: Same as the `feed_dict` argument to `Session.run()`

    Returns:
      debug_urls: (`str` or `list` of `str`) file:// debug URLs to be used in
        this `Session.run()` call.
    z	run_%d_%dg    .A   wbNzfile://)r   acquirer   r   joinr   inttimer   releaser   MkDirr   Eventreprlog_messagemessager   METADATA_FILE_PREFIXFETCHES_INFO_FILE_TAGOpenwriteSerializeToStringkeysFEED_KEYS_INFO_FILE_TAG)	r   fetches	feed_dictrun_dirfetches_eventfetches_pathffeed_keys_eventfeed_keys_paths	            r   prepare_run_debug_urlsz1DumpingDebugWrapperSession.prepare_run_debug_urlsQ   s   $ 	""$ggll4--{		c 12D4E4EF0G HG""$	KKOO%M(,WM%77<<''**J*JJLL 
BGGLL.	5 1ggm--/01  oo'OEN4	0@+A04Y ' WW\\''**L*LLNN 
BGGLL0$	7 31ggo//123   1 13 3s    I'9 I3'I03I<)NNN)__name__
__module____qualname____doc__r   r=    r    r   r   r      s    B
 "&%)2.h+!r    r   )rA   r   r   r'   tensorflow.core.utilr   tensorflow.python.debug.libr    tensorflow.python.debug.wrappersr   tensorflow.python.platformr   r   r   rB   r    r   <module>rG      s4    F 	   * 2 6 ,b!!L!L b!r    