
    &`i^                     :   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d dlZd dlZd dl	m
Z
 d dlmZmZmZmZmZmZmZm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mZ d dl m!Z! d d	l"m#Z# d d
l$m%Z% d dl&m'Z'm(Z(m)Z) d dl*m+Z+ d dl,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8 d dl9m:Z: d dl;m<Z< d dl=m>Z>m?Z?m@Z@ d dlAmBZBmCZC d dlDmEZEmFZF d dlGmHZH 	 d dlImJZJmKZK n# eL$ r d dlmJZJmKZK Y nw xY wejM        jN        O                                ZPde8e1e/hZQeC G d d                      ZReB G d deR                      ZSeB G d d                      ZTeC G d deSeT                      ZUeC G d deS                      ZVd eeWeWeeX         f         fd!ZYd"eWd#eWd eeXeXf         fd$ZZd"eWd#eWd eXfd%Z[d&ee(         fd'Z\	 	 	 	 	 	 	 	 	 	 dWd&ee(         d+eeeX         eeXeXf         f         d,eeeeX         eeXeXf         f                  d-e]d.e^d/eXd0ee]         d1e]d2e^d3eeX         d4eeX         d5e^fd6Z_	 dXd7ed8e]d9e^d:e^d ef
d;Z`	 	 	 	 	 	 dYd&ee(         d+eeeX         eeXeXf         f         d,eeeeX         eeXeXf         f                  d0ee]         d3eeX         d4eeX         d5e^d1e]d eeeeX         ee^eXf         f         fd<Za	 	 	 	 	 	 	 dZd&ee(         d+eeeX         eeXeXf         f         d,eeeeX         eeXeXf         f                  d/eXd0ee]         d3eeX         d4eeX         d5e^d1e]d eeX         fd=Zbd eXfd>Zc	 d[d&ee(         d/eXd0ee]         fd?Zd	 d\d@e(d3eXd,eeeeX         eeXeXf         f                  fdAZe	 d]dBeeXee(         f         dCe]d5e^fdDZfd@e(dEegd e)fdFZh	 d^d@e(dGeeX         dHeeX         d1e]fdIZieB G dJ dKe%                      Zjd]dLe^d eSfdMZkdNeedOef                  d eeeX                  fdPZl	 d\dQeRdRee]e>f         dSeeF         d eeReFf         fdTZmdUejn        dQeRdSeFd efdVZodS )_    )print_functionN)Path)AnyCallable
CollectionDictListOptionalTupleUnion)flatten_dict)tabulate)EXPR_ERROR_FILETRAINING_ITERATION)_force_on_current_node
safe_print)Callback)DEBUG_PRINT_INTERVALTrial	_Location)pretty_print)AUTO_RESULT_KEYSDEFAULT_METRICDONEEPISODE_REWARD_MEANEXPERIMENT_TAGMEAN_ACCURACY	MEAN_LOSSNODE_IPPIDTIME_TOTAL_STIMESTEPS_TOTALTRIAL_ID)	Trainableunflattened_lookup)	Verbosityhas_verbosityset_verbosity)DeveloperAPI	PublicAPI)EmptyQueue)Template)MappingMutableMappingconfigc            
           e Zd ZdZ	 	 	 	 ddee         dee         dee         dee         fdZdd	e	e
         d
efdZd	e	e
         d
edefdZdS )ProgressReporterzAbstract class for experiment progress reporting.

    `should_report()` is called to determine whether or not `report()` should
    be called. Tune will call these functions after trial state transitions,
    receiving training results, and so on.
    N
start_timetotal_samplesmetricmodec                     dS )ar  Setup progress reporter for a new Ray Tune run.

        This function is used to initialize parameters that are set on runtime.
        It will be called before any of the other methods.

        Defaults to no-op.

        Args:
            start_time: Timestamp when the Ray Tune run is started.
            total_samples: Number of samples the Ray Tune run will run.
            metric: Metric to optimize.
            mode: Must be one of [min, max]. Determines whether objective is
                minimizing or maximizing the metric attribute.
            **kwargs: Keyword arguments for forward-compatibility.
        N selfr5   r6   r7   r8   kwargss         n/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/tune/progress_reporter.pysetupzProgressReporter.setupB   s	    . 	    Ftrialsdonec                     t           )zReturns whether or not progress should be reported.

        Args:
            trials: Trials to report on.
            done: Whether this is the last progress report attempt.
        NotImplementedErrorr<   rA   rB   s      r>   should_reportzProgressReporter.should_report[   s
     "!r@   sys_infoc                     t           )zReports progress across trials.

        Args:
            trials: Trials to report on.
            done: Whether this is the last progress report attempt.
            sys_info: System info.
        rD   r<   rA   rB   rH   s       r>   reportzProgressReporter.reportd   s
     "!r@   NNNNF)__name__
__module____qualname____doc__r
   floatintstrr?   r	   r   boolrG   r   rK   r:   r@   r>   r4   r4   9   s          '+'+ $" UO  } 	
 sm   2" "DK "t " " " ""T%[ " " " " " " " "r@   r4   c                      e Zd ZdZ ej        ededede	de
dedi          Zeeej        ej        ej        ej         ed          hZdddd	d	d	d
dddddddeeee         eeef         f                  deeee         eeef         f                  dee         dedededededee         dee         dee         defdZ	 	 	 	 d3dee         dee         dee         dee         fdZdee         dee         fdZdefdZd4dee         fd Z d5d!ee!         d"efd#Z"d4ded$ee         fd%Z#	 d4d&ed$ee         fd'Z$d(d)d*d!ee!         d"ed+ed,ed-ef
d.Z%d6d!ee!         d0efd1Z&d!ee!         fd2Z'dS )7TuneReporterBasea  Abstract base class for the default Tune reporters.

    If metric_columns is not overridden, Tune will attempt to automatically
    infer the metrics being outputted, up to 'infer_limit' number of
    metrics.

    Args:
        metric_columns: Names of metrics to
            include in progress table. If this is a dict, the keys should
            be metric names and the values should be the displayed names.
            If this is a list, the metric name is used directly.
        parameter_columns: Names of parameters to
            include in progress table. If this is a dict, the keys should
            be parameter names and the values should be the displayed names.
            If this is a list, the parameter name is used directly. If empty,
            defaults to all available parameters.
        max_progress_rows: Maximum number of rows to print
            in the progress table. The progress table describes the
            progress of each trial. Defaults to 20.
        max_error_rows: Maximum number of rows to print in the
            error table. The error table lists the error file, if any,
            corresponding to each trial. Defaults to 20.
        max_column_length: Maximum column length (in characters). Column
            headers and values longer than this will be abbreviated.
        max_report_frequency: Maximum report frequency in seconds.
            Defaults to 5s.
        infer_limit: Maximum number of metrics to automatically infer
            from tune results.
        print_intermediate_tables: Print intermediate result
            tables. If None (default), will be set to True for verbosity
            levels above 3, otherwise False. If True, intermediate tables
            will be printed with experiment progress. If False, tables
            will only be printed at then end of the tuning run for verbosity
            levels greater than 2.
        metric: Metric used to determine best current trial.
        mode: One of [min, max]. Determines whether objective is
            minimizing or maximizing the metric attribute.
        sort_by_metric: Sort terminated trials by metric in the
            intermediate table. Defaults to False.
    acclossiterztotal time (s)tsrewardN         Fmetric_columnsparameter_columnsr6   max_progress_rowsmax_error_rowsmax_column_lengthmax_report_frequencyinfer_limitprint_intermediate_tablesr7   r8   sort_by_metricra   rb   r6   rc   rd   re   rf   rg   rh   r7   r8   ri   c                   || _         |d u| _        i | _        |p| j                                        | _        |pg | _        || _        || _        || _	        || _
        |	t          t          j                  | _        n|	| _        || _        d| _        t#          j                    | _        |
| _        || _        || _        d S Nr   )_total_samples_metrics_override_inferred_metricsDEFAULT_COLUMNScopy_metric_columns_parameter_columns_max_progress_rows_max_error_rows_max_column_length_infer_limitr)   r(   V3_TRIAL_DETAILS_print_intermediate_tables_max_report_freqency_last_report_timetime_start_time_metric_mode_sort_by_metric)r<   ra   rb   r6   rc   rd   re   rf   rg   rh   r7   r8   ri   s                r>   __init__zTuneReporterBase.__init__   s      ,!/t!;!#-L1E1J1J1L1L"3"9r"3-"3'$,.;I<V.W.WD++.GD+$8!!"9;;
-r@   r5   c                     |                      |           |                     |           |                     ||           d S )N)r7   r8   )set_start_timeset_total_samplesset_search_propertiesr;   s         r>   r?   zTuneReporterBase.setup   sK     	J'''}---""&t"<<<<<r@   c                     | j         r|s	| j        r|rt          d          |r|| _         |r|| _        | j         | j        rt          | _         dS )NzYou passed a `metric` or `mode` argument to `tune.TuneConfig()`, but the reporter you are using was already instantiated with their own `metric` and `mode` parameters. Either remove the arguments from your reporter or from your call to `tune.TuneConfig()`T)r}   r~   
ValueErrorr   )r<   r7   r8   s      r>   r   z&TuneReporterBase.set_search_properties   sv    L 	V 	 	 	N    	"!DL 	DJ<DJ)DLtr@   c                     || _         d S N)rl   )r<   r6   s     r>   r   z"TuneReporterBase.set_total_samples   s    +r@   	timestampc                 L    |t          j                     | _        d S || _        d S r   )r{   r|   )r<   r   s     r>   r   zTuneReporterBase.set_start_time   s*     #y{{D(Dr@   rA   rB   c                     t          j                     | j        z
  | j        k    rt          j                     | _        dS |S )NT)r{   rz   ry   rF   s      r>   rG   zTuneReporterBase.should_report   s6    9;;//$2KKK%)Y[[D"4r@   representationc                     d| _         || j        v r"t          d                    |                    t	          | j        t
                    r|p|}|| j        |<   dS |||k    rt          d          | j                            |           dS )a  Adds a metric to the existing columns.

        Args:
            metric: Metric to add. This must be a metric being returned
                in training step results.
            representation: Representation to use in table. Defaults to
                `metric`.
        TColumn {} already exists.Nzl`representation` cannot differ from `metric` if this reporter was initialized with a list of metric columns.)rm   rq   r   format
isinstancer1   append)r<   r7   r   s      r>   add_metric_columnz"TuneReporterBase.add_metric_column  s     "&T)))8??GGHHHd*N;; 
	0+5vN+9D ((()n.F.F )  
  ''/////r@   	parameterc                    || j         v r"t          d                    |                    t          | j         t                    r|p|}|| j         |<   dS |||k    rt          d          | j                             |           dS )a  Adds a parameter to the existing columns.

        Args:
            parameter: Parameter to add. This must be a parameter
                specified in the configuration.
            representation: Representation to use in table. Defaults to
                `parameter`.
        r   Nzo`representation` cannot differ from `parameter` if this reporter was initialized with a list of metric columns.)rr   r   r   r   r1   r   )r<   r   r   s      r>   add_parameter_columnz%TuneReporterBase.add_parameter_column  s     ///8??	JJKKKd-~>> 
	6+8yN1?D#I...)n	.I.I )  
 #**955555r@   psql
)fmtdelimrH   r   r   c                6   | j         r)| j        | j        d| _         t          j        d           | j        s5|                     || j                  }| j        	                    |           dt          | j        t          j                              g|}|rd}d}	n| j        }| j        }	|                     |          \  }
}|
r)|                    t#          |
|| j                             t'          t(          j                  r{|                    t-          || j        | j        | j        | j        ||| j        || j        | j        | j                              |                    t5          |||	                     |                    |          |z   S )a  Returns full progress string.

        This string contains a progress table and error table. The progress
        table describes the progress of each trial. The error table lists
        the error file, if any, corresponding to each trial. The latter only
        exists if errors have occurred.

        Args:
            trials: Trials to report on.
            done: Whether this is the last progress report attempt.
            fmt: Table format. See `tablefmt` in tabulate API.
            delim: Delimiter between messages.
        NFz[Both 'metric' and 'mode' must be set to be able to sort by metric. No sorting is performed.z== Status ==)ra   rb   r6   force_tabler   max_rowsre   rB   r7   r8   ri   r   r   )r   r}   r~   warningswarnrm   _infer_user_metricsrv   rq   update_time_passed_strr|   r{   rs   rt   _current_best_trialr   _best_trial_strrr   r)   r(   V1_EXPERIMENT_trial_progress_strrl   rx   ru   _trial_errors_strjoin)r<   rA   rB   r   r   rH   user_metricsmessagesmax_progress	max_errorcurrent_best_trialr7   s               r>   _progress_strzTuneReporterBase._progress_str9  s   *  	T\%9TZ=O#(D M>   % 	633FD<MNNL ''555T-ty{{;;
 

  	-LII2L,I%)%=%=f%E%E"F 	OO 2FD<STT   011 	TOO##'#7&*&="&"5 $ ?)&*&=<#'#7      OO-f#	RRRSSSzz(##e++r@      limitc                 ^   t          | j                  |k    r| j        S i | _        |D ]~}|j        s
|j                                        D ]Z\  }}|| j        vr)|t
          vr t          |          | j        v r
|| j        |<   t          | j                  |k    r| j        c c S [| j        S )z&Try to infer the metrics to print out.)lenrn   last_resultitemsro   r   typeVALID_SUMMARY_TYPES)r<   rA   r   tr7   values         r>   r   z$TuneReporterBase._infer_user_metrics  s    t%&&%//))!# 
	2 
	2A= !"!4!4!6!6 2 2!555%555;;$*BBB=CD26:t-..%77111111 82 %%r@   c                    |sdS | j         | j        }}|sDt          | j                  dk    r,t	          | j                                                  d         }|r|sd |fS |dk    rdnd}t          d          }d }|D ]H}|j        s
t          ||j        d           }t          j
        |          r6|r	||z  |k    r||z  }|}I||fS )	NNN   r   maxg      ?g      z-infdefault)r}   r~   r   rn   listkeysrR   r   r'   pdisnull)	r<   rA   r7   r8   	metric_opbest_metric
best_trialr   metric_values	            r>   r   z$TuneReporterBase._current_best_trial  s    	:|TZ  	@4)**a//d499;;<<Q? 	 T 	 <5==CCd	Fmm
 	 	A= -famTRRRLy&&  	!9K!G!G*Y6
6!!r@   rL   r   rM   )r   )(rN   rO   rP   rQ   collectionsOrderedDictr   r   r   r"   r#   r   ro   rS   rR   npfloat32float64int32int64r   r   r
   r   r	   rT   r   rU   r   r?   r   r   r   r   rG   r   r   r   r   r   r:   r@   r>   rW   rW   o   s       ' 'T .k-5v*T	
	 	O 	





T

 FJHL'+!# !#$%48 $"$&. &. &. !tCy$sCx.'@!AB&. $E$s)T#s(^*C$DE	&.
  }&. &. &. &. "&. &. $,D>&. &. sm&. &. &. &. &.T '+'+ $"
= 
=UO
=  }
= 	
=
 sm
= 
= 
= 
=HSM #    (,s , , , ,) ) ) ) ) ) DK t    0 0 0Xc] 0 0 0 04 ?C6 66.6sm6 6 6 6> D, D, D,UD, D, 	D,
 D, D, D, D, D,L& &$u+ &c & & & &$"$u+ " " " " " "r@   rW   c                   d    e Zd ZdZedefd            Zej        defd            ZdeddfdZ	dS )	RemoteReporterMixinzRemote reporter abstract mixin class.

    Subclasses of this class will use a Ray Queue to display output
    on the driver side when running Ray Client.returnc                 $    t          | dd           S )N_output_queuegetattr)r<   s    r>   output_queuez RemoteReporterMixin.output_queue  s    t_d333r@   r   c                     || _         d S r   )r   )r<   r   s     r>   r   z RemoteReporterMixin.output_queue  s    "r@   stringNc                     t           )z[Display the progress string.

        Args:
            string: String to display.
        rD   )r<   r   s     r>   displayzRemoteReporterMixin.display  s
     "!r@   )
rN   rO   rP   rQ   propertyr.   r   setterrT   r   r:   r@   r>   r   r     s        3 3
 4e 4 4 4 X4 #% # # # #"c "d " " " " " "r@   r   c                   f    e Zd ZdZddddddddddddddd	ed
eeee         e	eef         f                  deeee         e	eef         f                  dee
         de
de
de
de
de
dee         dee         dee         def fdZdee         dede	fdZdeddfdZdee         dedefdZ xZS )JupyterNotebookReporteraf  Jupyter notebook-friendly Reporter that can update display in-place.

    Args:
        overwrite: Flag for overwriting the cell contents before initialization.
        metric_columns: Names of metrics to
            include in progress table. If this is a dict, the keys should
            be metric names and the values should be the displayed names.
            If this is a list, the metric name is used directly.
        parameter_columns: Names of parameters to
            include in progress table. If this is a dict, the keys should
            be parameter names and the values should be the displayed names.
            If this is a list, the parameter name is used directly. If empty,
            defaults to all available parameters.
        max_progress_rows: Maximum number of rows to print
            in the progress table. The progress table describes the
            progress of each trial. Defaults to 20.
        max_error_rows: Maximum number of rows to print in the
            error table. The error table lists the error file, if any,
            corresponding to each trial. Defaults to 20.
        max_column_length: Maximum column length (in characters). Column
            headers and values longer than this will be abbreviated.
        max_report_frequency: Maximum report frequency in seconds.
            Defaults to 5s.
        infer_limit: Maximum number of metrics to automatically infer
            from tune results.
        print_intermediate_tables: Print intermediate result
            tables. If None (default), will be set to True for verbosity
            levels above 3, otherwise False. If True, intermediate tables
            will be printed with experiment progress. If False, tables
            will only be printed at then end of the tuning run for verbosity
            levels greater than 2.
        metric: Metric used to determine best current trial.
        mode: One of [min, max]. Determines whether objective is
            minimizing or maximizing the metric attribute.
        sort_by_metric: Sort terminated trials by metric in the
            intermediate table. Defaults to False.
    TNr]   r^   r_   F)	overwritera   rb   r6   rc   rd   re   rf   rg   rh   r7   r8   ri   r   ra   rb   r6   rc   rd   re   rf   rg   rh   r7   r8   ri   c                    t          t          |                               ||||||||	|
|||           t          st	          j        d           || _        d | _        |                     d           d S )Nr`   a!  You are using the `JupyterNotebookReporter`, but not IPython/Jupyter-compatible environment was detected. If this leads to unformatted output (e.g. like <IPython.core.display.HTML object>), consider passing a `CLIReporter` as the `progress_reporter` argument to `tune.RunConfig()` instead. )	superr   r   IS_NOTEBOOKr   r   
_overwrite_display_handler   )r<   r   ra   rb   r6   rc   rd   re   rf   rg   rh   r7   r8   ri   	__class__s                 r>   r   z JupyterNotebookReporter.__init__  s    " 	%t,,55)/'/)/!5#&?) 	6 	
 	
 	
  	M1   $#Rr@   rA   rB   rH   c                      | j         ||g|R  }| j        | j                            |           d S |                     |           d S r   )_progress_htmlr   putr   )r<   rA   rB   rH   progresss        r>   rK   zJupyterNotebookReporter.report  s^    &4&vt?h???(!!(+++++ LL"""""r@   r   r   c                     ddl m}m}m} | j        s0| j        r |d            | ||          d          | _        d S | j                             ||                     d S )Nr   )HTMLclear_outputr   T)wait
display_id)IPython.displayr   r   r   r   r   r   )r<   r   r   r   r   s        r>   r   zJupyterNotebookReporter.display&  s    ??????????# 	6 ($''''#*744<<D#I#I#ID    ''V55555r@   c                    | j         s5|                     || j                  }| j                            |           t          | j        t          j                              \  }}t                      \  }}}	t          d|fd|fd| d| dfgd          }
t          || j        | j        d|rdn| j        | j        | j        | j        | j        		  	        }|d
         }|dd         }t#          |d|rdn| j                  }t'          |	||g          r&t)          d                              |	||          }nd}t)          d                              |
t-          | ||          S )aR  Generate an HTML-formatted progress update.

        Args:
            trials: List of trials for which progress should be
                displayed
            done: True if the trials are finished, False otherwise
            *sys_info: System information to be displayed

        Returns:
            Progress update to be rendered in a notebook, including HTML
                tables and formatted error messages. Includes
                - Duration of the tune job
                - Memory consumption
                - Trial progress table, with information about each experiment
        zCurrent time:zRunning for:zMemory:/z GiBhtml)tablefmtN	rA   ra   rb   r   r   r7   r8   ri   re   r   r   r   ztune_status_messages.html.j2)memory_messagetrial_progress_messagestrial_errorsztune_status.html.j2)status_tablesys_info_messagetrial_progressr   )rm   r   rv   rq   r   _get_time_strr|   r{   _get_memory_usager   _trial_progress_tablerr   rs   r}   r~   r   ru   r   rt   anyr/   render_generate_sys_info_str)r<   rA   rB   rH   r   current_timerunning_forused_gbtotal_gbr   r   trial_progress_datar   r   r   msgs                   r>   r   z&JupyterNotebookReporter._progress_html0  s     % 	633FD<MNNL ''555$1$2BDIKK$P$P!k,=,?,?)> ,/-w777778
 
 
 
 4/"5!>TTt'></"5

 

 

 -Q/"5abb"9()O4;O
 
 
  7FGG 	9::AA-(?) B  CC C-..55%3X>)	 6 
 
 	
r@   )rN   rO   rP   rQ   rU   r
   r   r	   rT   r   rS   r   r   rK   r   r   __classcell__r   s   @r>   r   r     s       $ $R EIHL'+!# !#$%48 $"$, , , , !tCy$sCx.'@!AB	,
 $E$s)T#s(^*C$DE,  }, , , , ", , $,D>, , sm, , , , , , ,\#T%[ # # # # # #6c 6d 6 6 6 6?
T%[ ?
 ?
C ?
 ?
 ?
 ?
 ?
 ?
 ?
 ?
r@   r   c                   <    e Zd ZdZddddddddddddddeeee         eeef         f                  d	eeee         eeef         f                  d
ee	         de	de	de	de	de	dee
         dee         dee         de
f fdZdefdZdee         de
defdZ xZS )CLIReportera  Command-line reporter

    Args:
        metric_columns: Names of metrics to
            include in progress table. If this is a dict, the keys should
            be metric names and the values should be the displayed names.
            If this is a list, the metric name is used directly.
        parameter_columns: Names of parameters to
            include in progress table. If this is a dict, the keys should
            be parameter names and the values should be the displayed names.
            If this is a list, the parameter name is used directly. If empty,
            defaults to all available parameters.
        max_progress_rows: Maximum number of rows to print
            in the progress table. The progress table describes the
            progress of each trial. Defaults to 20.
        max_error_rows: Maximum number of rows to print in the
            error table. The error table lists the error file, if any,
            corresponding to each trial. Defaults to 20.
        max_column_length: Maximum column length (in characters). Column
            headers and values longer than this will be abbreviated.
        max_report_frequency: Maximum report frequency in seconds.
            Defaults to 5s.
        infer_limit: Maximum number of metrics to automatically infer
            from tune results.
        print_intermediate_tables: Print intermediate result
            tables. If None (default), will be set to True for verbosity
            levels above 3, otherwise False. If True, intermediate tables
            will be printed with experiment progress. If False, tables
            will only be printed at then end of the tuning run for verbosity
            levels greater than 2.
        metric: Metric used to determine best current trial.
        mode: One of [min, max]. Determines whether objective is
            minimizing or maximizing the metric attribute.
        sort_by_metric: Sort terminated trials by metric in the
            intermediate table. Defaults to False.
    Nr]   r^   r_   Fr`   ra   rb   r6   rc   rd   re   rf   rg   rh   r7   r8   ri   c                p    t          t          |                               |||||||||	|
||           d S )Nr`   )r   r  r   )r<   ra   rb   r6   rc   rd   re   rf   rg   rh   r7   r8   ri   r   s                r>   r   zCLIReporter.__init__  sZ      	k4  )))/'/)/!5#&?) 	* 	
 	
 	
 	
 	
r@   r  c                 $    t          |           d S r   r   r<   r  s     r>   _printzCLIReporter._print      3r@   rA   rB   rH   c                 J    |                       | j        ||g|R             d S r   )r  r   rJ   s       r>   rK   zCLIReporter.report  s2    &D&vt?h???@@@@@r@   )rN   rO   rP   rQ   r
   r   r	   rT   r   rS   rU   r   r  r   rK   r  r	  s   @r>   r  r  r  s       # #P FJHL'+!# !#$%48 $"$
 
 
 !tCy$sCx.'@!AB
 $E$s)T#s(^*C$DE	

  }
 
 
 
 "
 
 $,D>
 
 sm
 
 
 
 
 
 
>#    AT%[ A A A A A A A A A Ar@   r  r   c                  :   	 ddl } ddl}|                                j        dz  }||                                j        dz  z
  }||dz  k    rd}nd}t          |d          t          |d          |fS # t          $ r t          j        t          j        dfcY S w xY w)zGet the current memory consumption.

    Returns:
        Memory used, memory available, and optionally a warning
            message to be shown to the user when memory consumption is higher
            than 90% or if `psutil` is not installed
    r   Ni   @g?a
  : ***LOW MEMORY*** less than 10% of the memory on this node is available for use. This can cause unexpected crashes. Consider reducing the memory used by your application or reducing the Ray object store size by setting `object_store_memory` when calling `ray.init`.r   z@Unknown memory usage. Please run `pip install psutil` to resolve)	raypsutilvirtual_memorytotal	availableroundImportErrorr   nan)r  r  r  r  messages        r>   r   r     s    



((**0G<V2244>'JJX^##A G GWa  %!"4"4g== 
 
 
FFN
 	
 	
 	

s   A1A4 4#BBr5   r  c                 H   t           j                             |          }t           j                             |           }||z
  }|                                }|dz  }||dz  z  }|dz  }||dz  z  }|dz  }||dz  z
  }	|dk    r|dd}
nd}
|
|dd	|dd	|	d
z  }
|d|
fS )a  Get strings representing the current and elapsed time.

    Args:
        start_time: POSIX timestamp of the start of the tune run
        current_time: POSIX timestamp giving the current time

    Returns:
        Current time and elapsed time for the current run
    iQ i  <   r   z.0fz days, r   z02.0f:z05.2fz%Y-%m-%d %H:%M:%S)datetimefromtimestamptotal_seconds)r5   r  current_time_dtstart_time_dtdeltarestdayshoursminutessecondsrunning_for_strs              r>   r   r     s     '55lCCO%33J??M /- ?E  DL!DDL!!DWEEWDbjGWr\!Gaxx!....%GGGGGGGGGGO11?BBr@   c                 :    t          | |          \  }}d| d| dS )aa  Generate a message describing the current and elapsed time in the run.

    Args:
        start_time: POSIX timestamp of the start of the tune run
        current_time: POSIX timestamp giving the current time

    Returns:
        Message with the current and elapsed time for the current tune run,
            formatted to be displayed to the user
    zCurrent time: z (running for ))r   )r5   r  current_time_strr*  s       r>   r   r     s3     )6j,(O(O%oR,RRRRRRr@   rA   c                     t          j        t                    }| D ]"}||j                                     |           #|S r   )r   defaultdictr   statusr   )rA   trials_by_stater   s      r>   _get_trials_by_stater2    sE    !-d33O , ,!((++++r@   Fr   r]   ra   rb   r6   r   r   r   re   rB   r7   r8   ri   c                    g }|dk    rdnd}t          |           dk     r|                    |          S t          |           }t          |           t          d | D                       D ]*}|                    d                    |                     +fdt                    D             }|r|t          j        k    rd}|                    d	                    ||rd
| ndd                    |                               |st          t          j
                  r|r|t          | |||||	|
||	  	        z  }|                    |          S )a  Returns a human readable message for printing to the console.

    This contains a table where each row represents a trial, its parameters
    and the current values of its metrics.

    Args:
        trials: List of trials to get progress string for.
        metric_columns: Names of metrics to include.
            If this is a dict, the keys are metric names and the values are
            the names to use in the message. If this is a list, the metric
            name is used in the message directly.
        parameter_columns: Names of parameters to
            include. If this is a dict, the keys are parameter names and the
            values are the names to use in the message. If this is a list,
            the parameter name is used in the message directly. If this is
            empty, all parameters are used in the message.
        total_samples: Total number of trials that will be generated.
        force_table: Force printing a table. If False, a table will
            be printed only at the end of the training for verbosity levels
            above `Verbosity.V2_TRIAL_NORM`.
        fmt: Output format (see tablefmt in tabulate API).
        max_rows: Maximum number of rows in the trial table. Defaults to
            unlimited.
        max_column_length: Maximum column length (in characters).
        done: True indicates that the tuning run finished.
        metric: Metric used to sort trials.
        mode: One of [min, max]. Determines whether objective is
            minimizing or maximizing the metric attribute.
        sort_by_metric: Sort terminated trials by metric in the
            intermediate table. Defaults to False.
    r   <br>r   r   c                     h | ]	}|j         
S r:   )local_experiment_path.0r   s     r>   	<setcomp>z&_trial_progress_str.<locals>.<setcomp>Q  s    EEEQ4EEEr@   zResult logdir: {}c                 b    g | ]+}d                      t          |                   |          ,S ){} {})r   r   )r8  stater1  s     r>   
<listcomp>z'_trial_progress_str.<locals>.<listcomp>T  sD        	s?5122E::  r@   infinitezNumber of trials: {}{} ({})r   r   , r   )r   r   r2  sortedr   r   sysmaxsizer)   r(   V2_TRIAL_NORMr   )rA   ra   rb   r6   r   r   r   re   rB   r7   r8   ri   r   r   
num_trials	local_dirnum_trials_strsr1  s                    @r>   r   r     s   Z HVmmFFE
6{{Qzz(###VJ*622OEEfEEEFF ? ?	+229==>>>>   O,,  O
  ##+55"OO%,,#08bIIo&&	
 	
    
}Y%<== 
$ 
))/)/

 

 

 
	
 ::hr@   r   max_lenadd_addrwrapc                 0   | -t          | t          t          t          j        t
          f          r| S t          |           }t          |          |k    r|S |rTt          |           |dz  k    rd|d|dz  z
  d         z   } t          j	        | |          }d
                    |          S |rXt          | t          t          t
          f          s6|d|dz
            dt          t          |                     d	d          }|S d|d|z
  d         z   }|S )
a  Abbreviate a string representation of an object to `max_len` characters.

    For numbers, booleans and None, the original value will be returned for
    correct rendering in the table formatting tool.

    Args:
        value: Object to be represented as a string.
        max_len: Maximum return string length.
        add_addr: If True, will add part of the object address to the end of the
            string, e.g. to identify different instances of the same class. If
            False, three dots (``...``) will be used instead.
    N   z...r_   )widthr   r^   _)r   rS   rR   numbersNumberrU   rT   r   textwraprI  r   hexid)r   rG  rH  rI  r   wrappedresults          r>   _max_lenrV  t  s!    }
53w~t*LMM}ZZF
6{{g " u::!##FA1$5#8#899E-W555yy!!! 
53t*<== ?gk?+CCc"U))nnRSS.ACCVQ[OO,,FMr@   c                 >    t                     }t                     }	|r6t          |	t          j                 |dk    fd          |	t          j        <   t          j        t          j        t          j        t          j        t          j        g}
|pt          d          }||k    rt          |	||          }g  g }|
D ]l}||	vr ||         z   t          |	|                   t          ||                   z
  }|dk    r)|                    d                    ||                     m||z
  }d                    |          }nd}d	}g  |
D ]}||	vr |	|         z   t          t                    r"t!                                                    n fd
D             s.t           t%                      j        d  D                        n9t          t                    r"t!                                                    nfd D             }t          t                    rfdD             }nfdD             }t          t                    rfdD             }nfdD             }g d|z   |z   }||||ffS )a  Generate a table showing the current progress of tuning trials.

    Args:
        trials: List of trials for which progress is to be shown.
        metric_columns: Metrics to be displayed in the table.
        parameter_columns: List of parameters to be included in the data
        max_rows: Maximum number of rows to show. If there's overflow, a
            message will be shown to the user indicating that some rows
            are not displayed
        metric: Metric which is being tuned
        mode: Sort the table in descending order if mode is "max";
            ascending otherwise
        sort_by_metric: If true, the table will be sorted by the metric
        max_column_length: Max number of characters in each column

    Returns:
        - Trial data
        - List of column names
        - Overflow tuple:
            - boolean indicating whether the table has rows which are hidden
            - string with info about the overflowing rows
    r   c                 2    t          | j        d           S Nr   r'   r   )r   r7   s    r>   <lambda>z*_get_progress_table_data.<locals>.<lambda>  s    ,VQ]DQQQ r@   reversekeyinfr   r;  r?  Fr   c                 L    g | ]t          fd D                        S )c              3   J   K   | ]}t          |j        d           d uV  d S rY  rZ  )r8  r   ks     r>   	<genexpr>z6_get_progress_table_data.<locals>.<listcomp>.<genexpr>  sM       
 
 q!->>>dJ
 
 
 
 
 
r@   )r   )r8  rb  rA   s    @r>   r=  z,_get_progress_table_data.<locals>.<listcomp>  s`        
 
 
 

 
 
 
 
	  r@   c                     g | ]	}|j         
S r:   )evaluated_paramsr7  s     r>   r=  z,_get_progress_table_data.<locals>.<listcomp>  s    -Q-Q-QQa.@-Q-Q-Qr@   c                 6    g | ]}t          |           S ))re   )_get_trial_info)r8  trialre   metric_keysparameter_keyss     r>   r=  z,_get_progress_table_data.<locals>.<listcomp>  sD         	>;BS	
 	
 	
  r@   c                 B    g | ]}t          |         d d          S FT)rG  rH  rI  rV  )r8  rb  re   ra   s     r>   r=  z,_get_progress_table_data.<locals>.<listcomp>  sJ     $
 $
 $
  q!+<uSW  $
 $
 $
r@   c                 6    g | ]}t          |d d          S rl  rm  r8  rb  re   s     r>   r=  z,_get_progress_table_data.<locals>.<listcomp>  s;     $
 $
 $
 Q 1EMMM$
 $
 $
r@   c                 B    g | ]}t          |         d d          S rl  rm  )r8  rb  re   rb   s     r>   r=  z,_get_progress_table_data.<locals>.<listcomp>  sK     '
 '
 '
  !!$)	  '
 '
 '
r@   c                 6    g | ]}t          |d d          S rl  rm  ro  s     r>   r=  z,_get_progress_table_data.<locals>.<listcomp>  s;     '
 '
 '
 Q 1EMMM'
 '
 '
r@   )
Trial namer0  loc)r   r2  r@  r   
TERMINATEDRUNNINGPAUSEDPENDINGERRORrR   _fair_filter_trialsr   r   r   r   r0   r   r   setunion)rA   ra   rb   r   r7   r8   ri   re   rD  r1  state_tbl_ordertrials_by_state_truncoverflow_strsr<  numoverflowoverflow_strtrial_tableformatted_metric_columnsformatted_parameter_columnscolumnsri  rj  s   ``` `  `             @@r>   _get_progress_table_datar    s   @ VJ*622O  
,2E,-U]QQQQ-
 -
 -
() 	O '5<<HH 3X~!
 !
 $ 	A 	AEO+++E22Foe,--4I%4P0Q0QQCQww$$W^^C%?%?@@@(yy//$ 	- 	-EO++oe,,FF .'** %>..0011$     K  +-Q-Q&-Q-Q-Q RSS	%w	/	/ +/446677*      	  K .'** 
$
 $
 $
 $
 $
 !	$
 $
 $
  $
 $
 $
 $
 $
 $
 $
  #W-- 
'
 '
 '
 '
 '
 $'
 '
 '
##'
 '
 '
 '
#'
 '
 '
#
 	(''
%	&
"	#  (L!999r@   c	           
          t          | |||||||          \  }	}
\  }}t          |	|
|d          g}|r|                    d| d| d           |S )aq  Generate a list of trial progress table messages.

    Args:
        trials: List of trials for which progress is to be shown.
        metric_columns: Metrics to be displayed in the table.
        parameter_columns: List of parameters to be included in the data
        fmt: Format of the table; passed to tabulate as the fmtstr argument
        max_rows: Maximum number of rows to show. If there's overflow, a
            message will be shown to the user indicating that some rows
            are not displayed
        metric: Metric which is being tuned
        mode: Sort the table in descenting order if mode is "max";
            ascending otherwise
        sort_by_metric: If true, the table will be sorted by the metric
        max_column_length: Max number of characters in each column

    Returns:
        Messages to be shown to the user containing progress tables
    F)headersr   	showindexz... z more trials not shown (r,  )r  r   r   )rA   ra   rb   r   r   r7   r8   ri   re   datar  r  r  r   s                 r>   r   r   *  s    < /G	/ 	/+D'+Hl wNNNOH RPxPPPPPQQQOr@   c                  \    | r)d                     |                               dd          S dS )zFormat system info into a string.
        *sys_info: System info strings to be included.

    Returns:
        Formatted string containing system information.
    r4  r   r   )r   replace)rH   s    r>   r  r  X  s3      ;{{8$$,,T6:::2r@   c           	      B   g }d | D             }t          |          }|dk    r|                    d                    |                     ||pt          d          k    r,|                    d                    |||z
                       g d}d |d|         D             }|                    t	          |||d	d
                     t          d |d|         D                       r|                    d           |dk    rdnd}|                    |          S )a  Returns a readable message regarding trial errors.

    Args:
        trials: List of trials to get progress string for.
        fmt: Output format (see tablefmt in tabulate API).
        max_rows: Maximum number of rows in the error table. Defaults to
            unlimited.
    c                      g | ]}|j         	|S r:   )
error_filer7  s     r>   r=  z%_trial_errors_str.<locals>.<listcomp>p  s    000A1<0a000r@   r   zNumber of errored trials: {}r_  z(Table truncated to {} rows ({} overflow))rr  z
# failuresz
error filec                     g | ]J}t          |          t          |j        j                  |j        t          j        k    rd ndz   |j        gKS )r   *)rT   run_metadatanum_failuresr0  r   rx  r  r8  rh  s     r>   r=  z%_trial_errors_str.<locals>.<listcomp>|  sf     
 
 
  E

E&3444422#? 	
 
 
r@   NF)leftrightr  )r  r   r  colalignc              3   @   K   | ]}|j         t          j        k    V  d S r   )r0  r   rt  r  s     r>   rc  z$_trial_errors_str.<locals>.<genexpr>  s,      OOEu|u//OOOOOOr@   z3* The trial terminated successfully after retrying.r   r4  r   )r   r   r   rR   r   r   r   )	rA   r   r   r   failed
num_failedfail_headerfail_table_datar   s	            r>   r   r   d  sk    H00000FVJA~~6==jIIJJJ1U5\\22OO:AAj83    A@@
 
  		*
 
 
 	#2  	
 	
 	
 OOVIXI=NOOOOO 	SOOQRRRVmmFFE::hr@   rh  c                 B   t          || j        d          }| j                            di           |p t                                                    }t          |t                    r|                                }fd|D             }d| j         d| d| d| S )	z:Returns a readable message stating the current best trial.Nr   r2   c                 2    i | ]}|t          |          S r:   r&   )r8  pr2   s     r>   
<dictcomp>z#_best_trial_str.<locals>.<dictcomp>  s&    JJJ1a#Av..JJJr@   zCurrent best trial: z with =z and parameters=)r'   r   getr   r   r   r0   trial_id)rh  r7   rb   valparamsr2   s        @r>   r   r     s     VU%6
E
E
EC""8R00F)@T&++---@-@#W-- 5-2244JJJJ8IJJJF	u~ 	 	V 	 	c 	 		 	r@   r1  
max_trialsc                    t          j        t                    d}|dk    rT|sRd}t          |           D ]8}|         t	          | |                   k     rd}|dz  }|xx         dz  cc<   9|dk    r|Rt                      t          |           D ]<}|t          j        k    r|r| |         |<    t          | |         dd           |<   =fdt          |           D             }|S )a  Filters trials such that each state is represented fairly.

    The oldest trials are truncated if necessary.

    Args:
        trials_by_state: Maximum number of trials to return.
    Returns:
        Dict mapping state to List of fairly represented trials.
    Fr   Tr   c                     | j         S r   )r  )r   s    r>   r[  z%_fair_filter_trials.<locals>.<lambda>  s    QZ r@   r\  c                 >    i | ]}||         d |                  S r   r:   )r8  r<  num_trials_by_statesorted_trials_by_states     r>   r  z'_fair_filter_trials.<locals>.<dictcomp>  sB        	%e,-I/B5/I-IJ  r@   )r   r/  rS   r@  r   dictr   rt  )r1  r  ri   	no_changer<  filtered_trialsr  r  s         @@r>   ry  ry    sO    &1#66I
q...	O,, 	0 	0E"5)C0F,G,GGG!	a
#E***a/*** q... "VV((  E$$$$,;E,B"5)),2&;O;O- - -"5))    O,,  O r@   rU  c                     |                     t          d           |                     t          d           }}|r|rt          ||          }n| j        j        }|S r   )r  r    r!   r   temporary_statelocation)rh  rU  node_ippidr  s        r>   _get_trial_locationr    s[     ::gt,,fjjd.C.CSG 23 2Wc** (1Or@   
parametersmetricsc                     | j         | j        t          |           }t          |           | j        t          |          g}|fd|D             z  }|fd|D             z  }|S )aI  Returns the following information about a trial:

    name | status | loc | params... | metrics...

    Args:
        trial: Trial to get information for.
        parameters: Names of trial parameters to include.
        metrics: Names of metrics to include.
        max_column_length: Maximum column length (in characters).
    c           	      T    g | ]$}t          t          |d           d          %S Nr   T)rG  rH  rV  r'   )r8  paramr2   re   s     r>   r=  z#_get_trial_info.<locals>.<listcomp>  sR         	ufd;;;%	
 	
 	
  r@   c           	      T    g | ]$}t          t          |d           d          %S r  r  )r8  r7   re   rU  s     r>   r=  z#_get_trial_info.<locals>.<listcomp>  sR         	vvt<<<%	
 	
 	
  r@   )r   r2   r  rT   r0  )rh  r  r  re   r  
trial_infor2   rU  s      `  @@r>   rg  rg    s     F\F"5&11He**elCMM:J          J          J r@   c                   <   e Zd ZdZ	 ddee         deee                  fdZdefdZde	d	ed
         dd
de
fdZde	d	ed
         dd
fdZde	d	ed
         dd
fdZddd
de
defdZdede
dedefdZd	e
ee
f         dee         defdZdede
dedefdZde
fdZdS )TrialProgressCallbacka  Reports (prints) intermediate trial progress.

    This callback is automatically added to the callback stack. When a
    result is obtained, this callback will print the results according to
    the specified verbosity level.

    For ``Verbosity.V3_TRIAL_DETAILS``, a full result list is printed.

    For ``Verbosity.V2_TRIAL_NORM``, only one line is printed per received
    result.

    All other verbosity levels do not print intermediate trial progress.

    Result printing is throttled on a per-trial basis. Per default, results are
    printed only once every 30 seconds. Results are always printed when a trial
    finished or errored.

    Nr7   progress_metricsc                 b   t          j        t                    | _        t          j        t                    | _        t                      | _        i | _        || _	        t          |pg           | _
        | j	        r&| j
        r| j
                            | j	                   i | _        d | _        d S r   )r   r/  rR   _last_printrS   _last_print_iterationrz  _completed_trials_last_result_strr}   _progress_metricsadd_last_resultr   )r<   r7   r  s      r>   r   zTrialProgressCallback.__init__  s     '2599%0%<S%A%A"!$ "!$%5%;!<!< < 	5D2 	5"&&t|444#r@   r  c                 $    t          |           d S r   r   r  s     r>   r  zTrialProgressCallback._print%  r  r@   	iterationrA   r   rh  rU  c                 6    |                      ||d           d S )NFerror)
log_result)r<   r  rA   rh  rU  infos         r>   on_trial_resultz%TrialProgressCallback.on_trial_result(  s"     	vU33333r@   c                 @    |                      ||j        d           d S )NTr  )r  r   )r<   r  rA   rh  r  s        r>   on_trial_errorz$TrialProgressCallback.on_trial_error2  s%     	u0=====r@   c                 :   || j         vr| j                             |           |                     |j                  }| j                            |d          }||k    r|                     ||j        d           d S |                     d| d|            d S d S )Nr   Fr  Trial z completed. Last result: )r  r  _print_resultr   r  r  r  r  )r<   r  rA   rh  r  print_result_strlast_result_strs          r>   on_trial_completez'TrialProgressCallback.on_trial_complete7  s     ..."&&u---#11%2CDD"377rBBO?22u'8FFFFFWUWWEUWWXXXXX /.r@   Fr  c                    |                     dd          du }| j        |         }|p |pt          j                    |z
  t          k    }|r#|| j        vr| j                            |           |rst          r|                     ||||           n|                     ||||           t          j                    | j        |<   t          |v r|t                   | j
        |<   d S d S d S )NrB   FT)r  r  r{   r   r  r  r   display_resultprint_resultr   r  )r<   rh  rU  r  rB   
last_printshould_prints          r>   r  z TrialProgressCallback.log_resultF  s   zz&%((D0%e,
WuW	j(@CW(W 	.E!777"&&u--- 	O >##E65$????!!%===&*ikkDU#!V++4:;M4N*5111	O 	O ,+r@   rB   c           
      Z   | j         |         }t          t          j                  r|                    t
                    |k    rb|                     d| d           |                     d                    t          |          	                    dd                               |r|                     d| d           dS dS t          t          j
                  r| j        pd}|                    |d	          }t          |j        t                                                    }d
}	|rd}	|                     |          }
|
| j        |<   |rd| d|j         d| }n2| j        rd| d| d|dd|j         d|	 
}nd| d|
 d|j         d|	 }|                     |           dS dS )a=  Print the most recent results for the given trial to stdout.

        Args:
            trial: Trial for which results are to be printed
            result: Result to be printed
            error: True if an error has occurred, False otherwise
            done: True if the trial is finished, False otherwise
        zResult for r  z  {}r   z
  r  z completed.r}   g     Xr   z This trial completed.z
The trial z errored with parameters=z. Error file: z
 reported r  z.2fz with parameters=.N)r  r)   r(   rw   r  r   r  r   r   r  rC  r}   r   
local_pathr   as_posixr  r  r2   )r<   rh  rU  r  rB   last_print_iterationmetric_namer   r  r  r  r  s               r>   r  z"TrialProgressCallback.print_resultX  sJ     $9%@344 '	!zz,--1EEE2%222333FMM,v*>*>*F*FtV*T*TUUVVV 97U777888889 9 9233  	!,3)K!::k599Le.@@IIKKJD 0/#11&99+;D!%( 0 0 0"',0 0#-0 0 
  =U = ="= =%18= =',|= =6:= = =U = ='= =',|= =6:= =  KK     A 	!  	!r@   r  r   c                    g }t          |          }t          j        t          | j                                        d                     }|                                D ]7\  }|                    t          |          gfd|D             z              8t          d                              t          |ddg|z   d          	          S )
a  Generate an HTML table of trial progress info.

        Trials (rows) are sorted by name; progress stats (columns) are sorted
        as well.

        Args:
            trials: Trials and their associated latest results
            columns: Columns to show in the table; must be a list of valid
                keys for each Trial result

        Returns:
            HTML template containing a rendered table of progress info
        c                 ,    t          | d                   S rk   )rT   )items    r>   r[  z<TrialProgressCallback.generate_trial_table.<locals>.<lambda>  s    s47|| r@   )r^  c                 <    g | ]}                     |d           S )r   )r  )r8  colrU  s     r>   r=  z>TrialProgressCallback.generate_trial_table.<locals>.<listcomp>  s'    'O'O'O

3(;(;'O'O'Or@   ztrial_progress.html.j2r   rr  F)r   r  r  )table)
r@  r   r   r  r   r   rT   r/   r   r   )r<   rA   r  r  sorted_trialsrh  rU  s         @r>   generate_trial_tablez*TrialProgressCallback.generate_trial_table  s      //#/4$**,,2K2KLLL
 
 +0022 	Q 	QME6KKU'O'O'O'Ow'O'O'OOPPPP01188v~/GSX   9 
 
 	
r@   c                    ddl m}m} || j        |<   t	          t
          j                  rddh}n5t	          t
          j                  rh dt          t                    z  }ndS | 
                    | j        t          |                                          |z
            }| j        s | ||          d          | _        dS | j                             ||                     dS )	a  Display a formatted HTML table of trial progress results.

        Trial progress is only shown if verbosity is set to level 2 or 3.

        Args:
            trial: Trial for which results are to be printed
            result: Result to be printed
            error: True if an error has occurred, False otherwise
            done: True if the trial is finished, False otherwise
        r   )r   r   r2   
hist_stats>   rB   r2   r  r  experiment_tagNTr   )r   r   r   r  r)   r(   rw   rC  rz  r   r  r   r   r   )	r<   rh  rU  r  rB   r   r   ignored_keysr  s	            r>   r  z$TrialProgressCallback.display_result  s    	21111111#)% 344 	LL
 9233 		   $%%&LL F))s6;;==11L@
 
 # 	5#*744;;4#H#H#HD    ''U44444r@   c                    | j         r4t          |          }i }| j         D ]}|                    |          ||<   nT|                                }t          D ]}|                    |d            t          D ]}|                    |d            d                    d |                                D                       }|S )N,c                 &    g | ]\  }}|| d| S )Nr  r:   )r8  rb  vs      r>   r=  z7TrialProgressCallback._print_result.<locals>.<listcomp>  s'    JJJDAqAMZZAZZMMMr@   )	r  r   r  rp   SKIP_RESULTS_IN_REPORTpopr   r   r   )r<   rU  flat_resultr  r7   skip_resultauto_resultr  s           r>   r  z#TrialProgressCallback._print_result  s    ! 	4&v..KL0 ? ?'2v'>'>V$$?
 ";;==L5 4 4  d3333/ 4 4  d333388JJL$6$6$8$8JJJ
 
  r@   r   rM   )rN   rO   rP   rQ   r
   rT   r	   r   r  rS   r   r  r  r  rU   r  r   r  r  r  r  r:   r@   r>   r  r     s        ( UY$ $sm$>FtCy>Q$ $ $ $ #    44 W4 	4
 4 4 4 4>>&*7m><C> > > >
YY&*7mY<CY Y Y YO O O Od O O O O$2!% 2! 2!d 2!$ 2! 2! 2! 2!h
5$;'
26s)
	
 
 
 
>%5E %54 %5 %5D %5 %5 %5 %5N D            r@   r  _trainer_apic                     t           r=| s;|                    dt          t          j                              t          di |}nt          di |}|S )zDetect progress reporter class.

    Will return a :class:`JupyterNotebookReporter` if a IPython/Jupyter-like
    session was detected, and a :class:`CLIReporter` otherwise.

    Keyword arguments are passed on to the reporter class.
    r   r:   )r   
setdefaultr)   r(   rC  r   r  )r  r=   progress_reporters      r>   _detect_reporterr    sh      2< 2+=9P+Q+Q'QRRR3==f=='11&11r@   	trainabler%   c                 ,    | sdS t          | dd          S )z"Detect progress metrics to report.Nr  r   )r  s    r>   _detect_progress_metricsr     s$      t914888r@   r  	verbositystring_queuec                     t          |           | pt                      } t          | t                    r*|!t	          ddit          d                    }|| _        | |fS )zzPrepares progress reported for Ray Client by setting the string queue.

    The string queue will be created if it's None.Nnum_cpusr   )actor_options)r*   r  r   r   r.   r   r   )r  r  r  s      r>   )_prepare_progress_reporter_for_ray_clientr    s     ))?-=-?-? #%899 6 )1M0Ft0L0LM  L *6&l**r@   remote_futurec                     dS fdfd}t          j        | gd          d         r' |             t          j        | gd          d         ' |             dS )zZ
    Stream items from string queue to progress_reporter until remote_future resolves
    Nc                  T    	                       d          S # t          $ r Y d S w xY w)NF)block)r  r-   )r  s   r>   get_next_queue_itemz2_stream_client_output.<locals>.get_next_queue_item)  sA    	##%#000 	 	 	44	s    
''c                  f                 } | #                     |                         } | !d S d S r   )r   )string_itemr  r  s    r>   _handle_string_queuez3_stream_client_output.<locals>._handle_string_queue/  sM    ))++%%%k222--//K %%%%%r@   g?)timeoutr   )r  r   )r  r  r  r  r  s    `` @r>   _stream_client_outputr    s         0 0 0 0 0 0 (M?C
0
0
0
3  (M?C
0
0
0
3 
 r@   )
Nr   Fr   Nr]   FNNF)r]   FF)NNNNFr]   )Nr   NNNFr]   )r   Nr   rM   )r]   )p
__future__r   r   r  rO  rA  rQ  r{   r   pathlibr   typingr   r   r   r   r	   r
   r   r   numpyr   pandasr   r  ray._private.dictr   )ray._private.thirdparty.tabulate.tabulater   ray.air.constantsr   r   ray.air.util.noder   ray.experimental.tqdm_rayr   ray.tune.callbackr   ray.tune.experiment.trialr   r   r   ray.tune.loggerr   ray.tune.resultr   r   r   r   r   r   r   r    r!   r"   r#   r$   ray.tune.trainabler%   ray.tune.utilsr'   ray.tune.utils.logr(   r)   r*   ray.util.annotationsr+   r,   ray.util.queuer-   r.   ray.widgetsr/   collections.abcr0   r1   r  widgetsutilin_notebookr   r  r4   rW   r   r   r  rR   rT   r   r   r   r2  rS   rU   r   rV  r  r   r  r   r   ry  r  r  rg  r  r  r   r  	ObjectRefr  r:   r@   r>   <module>r*     s
   % % % % % %       



          P P P P P P P P P P P P P P P P P P P P         



 * * * * * * > > > > > > A A A A A A A A 4 4 4 4 4 4 0 0 0 0 0 0 & & & & & & L L L L L L L L L L ( ( ( ( ( (                            ) ( ( ( ( ( - - - - - - F F F F F F F F F F 8 8 8 8 8 8 8 8 ' ' ' ' ' ' ' '            4777777777 4 4 433333333334 k**,,"HndC  2" 2" 2" 2" 2" 2" 2" 2"j {" {" {" {" {"' {" {" {"|	 " " " " " " " ". h
 h
 h
 h
 h
.0C h
 h
 h
V IA IA IA IA IA" IA IA IAX!
5x}!<= !
 !
 !
 !
H Ce  C5  CU38_  C  C  C  CFS Se S S S S Se     EI"  U  U KU $s)T#s(^34U   d3ic3h&? @AU  	U 
 U  
U  smU  U  U  SMU  3-U  U  U  U  U r IN$ $$$-1$AE$$ $ $ $T EI"  L: L:KL:$s)T#s(^34L:  d3ic3h&? @AL: sm	L:
 SML: 3-L: L: L: 4cE$),,-L: L: L: L:d EI"  + +K+$s)T#s(^34+  d3ic3h&? @A+ 
	+
 sm+ SM+ 3-+ + + 
#Y+ + + +\	 	 	 	 	 GK.  . K. !. 6>sm.  .  .  . h EI   d3ic3h&? @A   * !& &#tE{*+&& & & & &R	u 	d 	y 	 	 	 	 WY! !!"3i!26s)!PS! ! ! !H g  g  g  g  g H g  g  g T 4 >N     9k83459jo9 9 9 9 %)+ +'+S)^$+ 5/+ U"#	+ + + +2='  		     s   C C! C!