
    &`i'                         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  e            \  Z	Z
Z e j        e          Ze G d d                      Zd addZdS )	    N)OldAPIStack)try_import_tf)log_oncec                   *    e Zd ZdZd Zd Zd Zd ZdS )_TFRunBuilderzUsed to incrementally build up a TensorFlow run.

    This is particularly useful for batching ops from multiple different
    policies in the multi-agent setting.
    c                 L    || _         || _        i | _        g | _        d | _        d S N)session
debug_name	feed_dictfetches	_executed)selfr
   r   s      r/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/rllib/utils/tf_run_builder.py__init__z_TFRunBuilder.__init__   s)    $    c                     | j         rJ |D ]-}|| j        v r"t          d                    |                    .| j                            |           d S )NzKey added twice: {})r   r   
ValueErrorformatupdate)r   r   ks      r   add_feed_dictz_TFRunBuilder.add_feed_dict   sl    >!!! 	B 	BADN"" !6!=!=a!@!@AAA #i(((((r   c                     | j         rJ t          | j                  }| j                            |           t	          t          |t          | j                                      S r	   )r   lenr   extendlistrange)r   r   
base_indexs      r   add_fetchesz_TFRunBuilder.add_fetches#   sW    >!!!&&
G$$$E*c$,&7&788999r   c           	      n     j         	 t           j         j         j         j        t          j                            d                     _         nL# t          $ r?}t                              d                     j         j                             |d }~ww xY wt          |t                    r j         |         S t          |t                    r fd|D             S t          |t                     rt!           fd|D                       S t#          d                    |                    )NTF_TIMELINE_DIRz Error fetching: {}, feed_dict={}c                 :    g | ]}                     |          S  get.0xr   s     r   
<listcomp>z%_TFRunBuilder.get.<locals>.<listcomp>=   s#    222ADHHQKK222r   c              3   B   K   | ]}                     |          V  d S r	   r$   r&   s     r   	<genexpr>z$_TFRunBuilder.get.<locals>.<genexpr>?   s-      77!777777r   zUnsupported fetch type: {})r   _run_timeliner
   r   r   r   osenvironr%   	Exceptionlogger	exceptionr   
isinstanceintr   tupler   )r   to_fetches   `  r   r%   z_TFRunBuilder.get)   sG   >!!.LLONJNN#455" "      6==dn   
  h$$ 	L>(++$'' 	L22222222%(( 	L7777h7777779@@JJKKKs   A	A 
B:BBN)__name__
__module____qualname____doc__r   r   r   r%   r#   r   r   r   r      s_           ) ) ): : :L L L L Lr   r   c           	         |i }|rddl m} 	 t                              t          j        j                  }n;# t          $ r. d }t          d          rt          	                    d           Y nw xY wt          
                                }t          j                    }|                     ||||          }	|                    |j                  }
t          j                            |d                    |t          j                    t(          d	z                      }t(          d
z  at+          |d          }t                              d                    t          j                    |z
  t          j                            |                               |                    |
                                           n@t          d          rt                              d           |                     ||          }	|	S )Nr   )timeline)trace_levelztf1.RunOptions_not_availablezCan not access tf.RunOptions.FULL_TRACE. This may be because you have used `ray.init(local_mode=True)`. RLlib will use timeline without `options=tf.RunOptions.FULL_TRACE`.)optionsrun_metadatar   )
step_statsztimeline-{}-{}-{}.json
      wzWrote tf timeline ({} s) to {}tf_timelinezsExecuting TF run without tracing. To dump TF timeline traces to disk, set the TF_TIMELINE_DIR environment variable.)r   )tensorflow.python.clientr<   tf1
RunOptionstf
FULL_TRACEAttributeErrorr   r0   r1   RunMetadatatimerunTimeliner@   r-   pathjoinr   getpid_countopeninfoabspathwritegenerate_chrome_trace_format)sessopsr   r   timeline_dirr<   run_optionsr?   startr   traceoutf
trace_files                r   r,   r,   G   s   	 '5555555
	..R]5M.NNKK 	 	 	K677   K  		 ((	((<9  
 
 !!\-D!EEw||$++J	Vb[QQ
 
 	!$__
,33	e#RW__T%:%: 	
 	
 	

 	;;==>>>>M"" 	KKI   ((3)(44Ns   *: 5A21A2)NN)loggingr-   rL   ray.rllib.utils.annotationsr   ray.rllib.utils.frameworkr   ray.util.debugr   rF   rH   tfv	getLoggerr7   r0   r   rR   r,   r#   r   r   <module>rf      s     				  3 3 3 3 3 3 3 3 3 3 3 3 # # # # # #}R		8	$	$ 3L 3L 3L 3L 3L 3L 3L 3Ll 
, , , , , ,r   