
    &`iol                        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 d dl	m
Z
mZmZmZmZmZ d dlZd dlmZmZ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  d dl!m"Z"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.Z/d dl.m0Z0 n# e1$ r dZ/dZ0Y nw xY w ej2        e3          Z4 e-d           G d d                      Z5dS )    N)Number)Path)AnyDictListOptionalTupleUnion)EXPR_PROGRESS_FILEEXPR_RESULT_FILETRAINING_ITERATION)_exists_at_fs_pathget_fs_and_path)
Checkpoint)"_find_newest_experiment_checkpoint)TuneController)Trial)CONFIG_PREFIXDEFAULT_METRIC)flatten_dict)TuneFunctionDecoder)is_nanis_nan_or_infunflattened_lookup)	PublicAPI)	DataFramebeta)	stabilityc                       e Zd ZdZddddddeeej        f         dee	j
        j                 deee                  dee         dee         f
d	Zd
ee         fdZded
efdZd
eeef         fdZd/ded
eeef         fdZed
efd            Zed
efd            Zed
efd            Zed
efd            Zed
efd            Zed
efd            Zd Zed
efd            Zed
eeef         fd            Z ed
efd            Z!ed
eeef         fd            Z"	 d0dee         dee         d
efdZ#	 d1dedee         d
ee$ee%f                  fd Z&	 	 d0dedee         dee         d
ee         fd!Z'	 	 	 	 d2dee         dee         d$ed%ed
ee         f
d&Z(	 	 	 d3dee         dee         d$ed
ee         fd'Z)	 d4d
ee         fd*Z*ded
efd+Z+ded
efd,Z,	 d0dee         dee         d
eee-f         fd-Z.d
eee-f         fd.Z/dS )5ExperimentAnalysisa  Analyze results from a Ray Train/Tune experiment.

    To use this class, the run must store the history of reported metrics
    in log files (e.g., `result.json` and `progress.csv`).
    This is the default behavior, unless default loggers are explicitly excluded
    with the `TUNE_DISABLE_AUTO_CALLBACK_LOGGERS=1` environment variable.

    Parameters:
        experiment_checkpoint_path: Path to an `experiment_state.json` file,
            or a directory that contains an `experiment_state.json` file.
        default_metric: Default metric for comparing results. Can be
            overwritten with the ``metric`` parameter in the respective
            functions.
        default_mode: Default mode for comparing results. Has to be one
            of [min, max]. Can be overwritten with the ``mode`` parameter
            in the respective functions.
        trials: List of trials that can be accessed via `analysis.trials`.
    N)storage_filesystemtrialsdefault_metricdefault_modeexperiment_checkpoint_pathr!   r"   r#   r$   c          	         || _         |r|dvrt          d          || _        | j         | j        t          | _         |r|| _        nt          |          \  | _        }t          |          }|                    d          r,t          j	        
                    |          | _        || _        nr|| _        t          | j        | j                  }|Gt          j                            d          }t          d| d| j        j         d| j         d	          || _        |p|                                 | _        |                                 | _        |                                 | _        d S )
Nminmaxz2`default_mode` has to be None or one of [min, max]z.json)experiment_pathfs*z%No experiment snapshot file of form 'z' was found at: (z, z)
Please check if you specified the correct experiment path, which should be a combination of the `storage_path` and `name` specified in your run.)r#   
ValueErrorr$   r   _fsr   strendswithospathdirname_experiment_fs_path_experiment_json_fs_pathr   r   CKPT_FILE_TMPLformat	type_name_load_trialsr"   _fetch_trial_dataframes_trial_dataframesget_all_configs_configs)selfr%   r!   r"   r#   r$   experiment_json_fs_pathpatterns           y/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/tune/analysis/experiment_analysis.py__init__zExperimentAnalysis.__init__8   s    - 	SL>>QRRR(&4+<+H"0D  	)DHH3B*4 40DH0
 &))C%D%D"%..w77 	D')w7Q'R'RD$,FD))'AD$&H $ 8TX' ' '# '.(7>>sCC -G - -*- -.2.F- - -   -DD)3 1 1 3 3!%!=!=!?!?,,..    returnc                 b   | j                             | j                  5 }t          j        |                                t                    }d d d            n# 1 swxY w Y   t          | j                  }g }|d         }|D ]\  }}t          j
        |d          }|                    |           t          j        |j                  }	|j                                        |	_        | j         |	_        |j        |	_        |                    |	           |                    |           |S )N)cls
trial_dataTstub)r.   open_input_streamr5   jsonloadsreadallr   r   r4   r   from_json_staterestore_run_metadatacopystorageparentas_posixstorage_fs_pathr!   nameexperiment_dir_nameset_storageappend)
r>   fexperiment_stateexperiment_fs_pathr"   trial_statestrial_json_statetrial_runtime_metadatatrialnew_storages
             rA   r9   zExperimentAnalysis._load_trialsl   si   X''(EFF 	P!#z!))++;NOOO	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P "$":;;'58D 
	! 
	!44)*:FFFE&&'=>>>)EM22K*<*C*L*L*N*NK'-1XK*.@.EK+k***MM%    s   .AA!Ar_   c           
      `   dt           i}|j        t                      S t          |j        j        t                                                    }t          |j        j        t                                                    }t          |j        j
        |          r|j        j
                            |          5 }|                                                    d                              d          }|st                      cd d d            S d |                    d          D             }d d d            n# 1 swxY w Y   t!          j        |d          }nt          |j        j
        |          r|j        j
                            |          5 }|                                                    d          }	d d d            n# 1 swxY w Y   t!          j        t'          j        |	          |          }n/t+          d| d	t           d
t           d|j        j                   |S )Ntrial_idzutf-8
c                 6    g | ]}t          j        |          S  )rK   rL   ).0rows     rA   
<listcomp>z=ExperimentAnalysis._fetch_trial_dataframe.<locals>.<listcomp>   s     LLLTZ__LLLrC   /)sep)dtypezCould not fetch metrics for z: both z and z were not found at )r/   last_resultr   r   rQ   trial_fs_pathr   rS   r   r   r!   rJ   rM   decoderstripsplitpdjson_normalizeread_csvioStringIOFileNotFoundError)
r>   r_   force_dtypejson_fs_pathcsv_fs_pathrY   content	json_listdfcsv_strs
             rA   _fetch_trial_dataframez)ExperimentAnalysis._fetch_trial_dataframe   s   !3' $;;EM79IJJSSUU5=68JKKTTVVem>MM 	1CCLQQ MUV))++,,W55<<TBB '$;;M M M M M M M M MLd8K8KLLL		M M M M M M M M M M M M M M M
 "9#666BB @+NN 	1CCKPP 6TU))++,,W556 6 6 6 6 6 6 6 6 6 6 6 6 6 6R[11EEEBB#Xu X X=M X X%X X:?-:UX X  
 	s+   :A
D<D<<E E (GGGc                    g }i }| j         D ]d}	 |                     |          ||j        <   !# t          $ r7}|                    ||f           t                      ||j        <   Y d}~]d}~ww xY w|rLd                    d |D                       }t                              dt          |           d|            |S )zyFetches trial dataframes from files.

        Returns:
            A dictionary mapping trial_id -> pd.DataFrame
        Nrc   c                 >    g | ]\  }}d | dt          |           S )z- z: )repr)rf   r_   errors      rA   rh   z>ExperimentAnalysis._fetch_trial_dataframes.<locals>.<listcomp>   s3    JJJ,e,,tE{{,,JJJrC   zFailed to fetch metrics for z trial(s):
)
r"   r~   rb   	ExceptionrX   r   joinloggerwarninglen)r>   failures	trial_dfsr_   efail_strs         rA   r:   z*ExperimentAnalysis._fetch_trial_dataframes   s     	[ 	 	E,0,G,G,N,N	%.))   
+++,5KK	%.)
  	yyJJJJJ H NNTs8}}TT(TT   s   -
A.-A))A.Fprefixc                 *    fd| j         D             S )zReturns all trial hyperparameter configurations.

        Args:
            prefix: If True, flattens the config dict
                and prepends `config/`.

        Returns:
            Dict[str, Dict]: Mapping trial_id -> config dict
        c                 d    i | ],}|j         rt          t          |j        i          n|j        -S re   )rb   r   r   config)rf   r_   r   s     rA   
<dictcomp>z6ExperimentAnalysis.get_all_configs.<locals>.<dictcomp>   sK     
 
 
  N?EWmU\:;;;5<
 
 
rC   r"   )r>   r   s    `rA   r<   z"ExperimentAnalysis.get_all_configs   s2    
 
 
 
 	
 
 
 	
rC   c                     | j         S )zPath pointing to the experiment directory on persistent storage.

        This can point to a remote storage location (e.g. S3) or to a local
        location (path on the head node).)r4   r>   s    rA   r*   z"ExperimentAnalysis.experiment_path   s     ''rC   c                 |    | j         r| j        st          d          |                     | j         | j                  S )a)  Get the best trial of the experiment

        The best trial is determined by comparing the last trial results
        using the `metric` and `mode` parameters passed to `tune.run()`.

        If you didn't pass these parameters, use
        `get_best_trial(metric, mode, scope)` instead.
        zTo fetch the `best_trial`, pass a `metric` and `mode` parameter to `tune.run()`. Alternatively, use the `get_best_trial(metric, mode)` method to set the metric and mode explicitly.)r#   r$   r-   get_best_trialr   s    rA   
best_trialzExperimentAnalysis.best_trial   sN     " 	$*; 	'   ""4#68IJJJrC   c                 |    | j         r| j        st          d          |                     | j         | j                  S )a8  Get the config of the best trial of the experiment

        The best trial is determined by comparing the last trial results
        using the `metric` and `mode` parameters passed to `tune.run()`.

        If you didn't pass these parameters, use
        `get_best_config(metric, mode, scope)` instead.
        zTo fetch the `best_config`, pass a `metric` and `mode` parameter to `tune.run()`. Alternatively, use the `get_best_config(metric, mode)` method to set the metric and mode explicitly.)r#   r$   r-   get_best_configr   s    rA   best_configzExperimentAnalysis.best_config   sN     " 	$*; 	'   ##D$79JKKKrC   c                     | j         r| j        st          d          | j        }|s t          d| j          d| j         d          |                     || j         | j                  S )a  Get the checkpoint path of the best trial of the experiment

        The best trial is determined by comparing the last trial results
        using the `metric` and `mode` parameters passed to `tune.run()`.

        If you didn't pass these parameters, use
        `get_best_checkpoint(trial, metric, mode)` instead.

        Returns:
            :class:`Checkpoint <ray.tune.Checkpoint>` object.
        zTo fetch the `best_checkpoint`, pass a `metric` and `mode` parameter to `tune.run()`. Alternatively, use the `get_best_checkpoint(trial, metric, mode)` method to set the metric and mode explicitly.zONo best trial found. Please check if you specified the correct default metric (z) and mode (z).)r#   r$   r-   r   get_best_checkpoint)r>   r   s     rA   best_checkpointz"ExperimentAnalysis.best_checkpoint   s     " 	$*; 	.   _
 	*+/+>* *%* * *  
 ''+T->
 
 	
rC   c                 j    | j         r| j        st          d          | j        | j        j                 S )a  Get the full result dataframe of the best trial of the experiment

        The best trial is determined by comparing the last trial results
        using the `metric` and `mode` parameters passed to `tune.run()`.

        If you didn't pass these parameters, use
        `get_best_trial(metric, mode)` and use it to look for the dataframe
        in the `self.trial_dataframes` dict.
        zQTo fetch the `best_result`, pass a `metric` and `mode` parameter to `tune.run()`.)r#   r$   r-   trial_dataframesr   rb   r   s    rA   best_dataframez!ExperimentAnalysis.best_dataframe  sE     " 	$*; 	-   $T_%=>>rC   c                 T    | j         r| j        st          d          | j        j        S )aH  Get the last result of the best trial of the experiment

        The best trial is determined by comparing the last trial results
        using the `metric` and `mode` parameters passed to `tune.run()`.

        If you didn't pass these parameters, use
        `get_best_trial(metric, mode, scope).last_result` instead.
        zTo fetch the `best_result`, pass a `metric` and `mode` parameter to `tune.run()`. Alternatively, use `get_best_trial(metric, mode).last_result` to set the metric and mode explicitly and fetch the last result.)r#   r$   r-   r   rl   r   s    rA   best_resultzExperimentAnalysis.best_result)  s>     " 	$*; 	L   **rC   c                 B    t           j                            dd          S )NTUNE_RESULT_DELIMri   )r1   environgetr   s    rA   
_delimiterzExperimentAnalysis._delimiter<  s    z~~13777rC   c                     t           st          d          t          | j        |                                           }t           j                            |gd          S )aM  Get the best result of the experiment as a pandas dataframe.

        The best trial is determined by comparing the last trial results
        using the `metric` and `mode` parameters passed to `tune.run()`.

        If you didn't pass these parameters, use
        `get_best_trial(metric, mode, scope).last_result` instead.
        zD`best_result_df` requires pandas. Install with `pip install pandas`.	delimiterrb   index)rq   r-   r   r   r   r   from_records)r>   r   s     rA   best_result_dfz!ExperimentAnalysis.best_result_df?  sa      	(  
 #4#3t?P?PQQQ|((+j(IIIrC   c                 $    d | j         D             S )z7Get the last result of the all trials of the experimentc                 (    i | ]}|j         |j        S re   )rb   rl   )rf   r_   s     rA   r   z.ExperimentAnalysis.results.<locals>.<dictcomp>U  s    KKKe 1KKKrC   r   r   s    rA   resultszExperimentAnalysis.resultsR  s     LKt{KKKKrC   c                      t           st          d          t           j                             fd j        D             d          S )z/Get all the last results as a pandas dataframe.z@`results_df` requires pandas. Install with `pip install pandas`.c                 `    g | ]*}t          |j                                                   +S )r   )r   rl   r   )rf   r_   r>   s     rA   rh   z1ExperimentAnalysis.results_df.<locals>.<listcomp>_  sC        U.$//:K:KLLL  rC   rb   r   )rq   r-   r   r   r"   r   s   `rA   
results_dfzExperimentAnalysis.results_dfW  sp      	R   |((   ![    ) 
 
 	
rC   c                     | j         S )zList of all dataframes of the trials.

        Each dataframe is indexed by iterations and contains reported
        metrics.
        )r;   r   s    rA   r   z#ExperimentAnalysis.trial_dataframesf  s     %%rC   metricmodec                    |r|dvrt          d          |r|st          d          |                     ||          }|                     d          }|                                D ]@\  }}||v r7||                             |           ||                             |           At          j        t          |                                                    S )a  Returns a pandas.DataFrame object constructed from the trials.

        This function will look through all observed results of each trial
        and return the one corresponding to the passed ``metric`` and
        ``mode``: If ``mode=min``, it returns the result with the lowest
        *ever* observed ``metric`` for this trial (this is not necessarily
        the last)! For ``mode=max``, it's the highest, respectively. If
        ``metric=None`` or ``mode=None``, the last result will be returned.

        Args:
            metric: Key for trial info to order on. If None, uses last result.
            mode: One of [None, "min", "max"].

        Returns:
            pd.DataFrame: Constructed from a result dict of each trial.
        r'   *If set, `mode` has to be one of [min, max]z^If a `mode` is passed to `ExperimentAnalysis.dataframe(), you'll also have to pass a `metric`!)r   r   T)r   )logdir)	r-   _retrieve_rowsr<   itemsupdaterq   r   listvalues)r>   r   r   rowsall_configsr2   r   s          rA   	dataframezExperimentAnalysis.dataframeo  s    ,  	KD..IJJJ 	 	8  
 ""&t"<<**$*77'--// 	/ 	/LD&t||T
!!&)))T
!!!...|D//000rC   c                 z    p| j         pt          |j        j        j        }d |D             }fd|D             S )a  Get all checkpoints and a specified metric of a trial.

        Args:
            trial: The log directory of a trial, or a trial instance.
            metric: key for trial info to return, e.g. "mean_accuracy".
                "training_iteration" is used by default if no value was
                passed to ``self.default_metric``.

        Returns:
            List of [Checkpoint, metric] for all checkpoints of the trial.
        c                 *    g | ]}|j         |j        fS re   )
checkpointmetrics)rf   checkpoint_results     rA   rh   zIExperimentAnalysis._get_trial_checkpoints_with_metric.<locals>.<listcomp>  s4     
 
 
! )+<+DE
 
 
rC   c                 :    g | ]\  }}|t          |          fS re   )r   )rf   r   r   r   s      rA   rh   zIExperimentAnalysis._get_trial_checkpoints_with_metric.<locals>.<listcomp>  s=     
 
 
#
G +FG<<=
 
 
rC   )r#   r   run_metadatacheckpoint_managerbest_checkpoint_results)r>   r_   r   r   best_checkpointss     `  rA   "_get_trial_checkpoints_with_metricz5ExperimentAnalysis._get_trial_checkpoints_with_metric  su     D4.D2D 1I 	 
 
%<
 
 

 
 
 
'7
 
 
 	
rC   c                 @   |p| j         pt          }|                     |          }|                     ||          }t	          t          d |                    }|s t                              d| d           dS |dk    rdndt          |fd	          \  }}|S )
aJ  Gets best persistent checkpoint path of provided trial.

        Any checkpoints with an associated metric value of ``nan`` will be filtered out.

        Args:
            trial: The log directory of a trial, or a trial instance.
            metric: key of trial info to return, e.g. "mean_accuracy".
                "training_iteration" is used by default if no value was
                passed to ``self.default_metric``.
            mode: One of [min, max]. Defaults to ``self.default_mode``.

        Returns:
            A :class:`Checkpoint <ray.tune.Checkpoint>` object
        c                 .    t          | d                    S N   )r   )xs    rA   <lambda>z8ExperimentAnalysis.get_best_checkpoint.<locals>.<lambda>  s    !- rC   z)No checkpoints have been found for trial .Nr(   r   c                     | d         z  S r   re   )r   score_order_factors    rA   r   z8ExperimentAnalysis.get_best_checkpoint.<locals>.<lambda>  s    3E!3L rC   )key)	r#   r   _validate_moder   r   filterr   r   r)   )r>   r_   r   r   checkpoints_and_metricsr   _r   s          @rA   r   z&ExperimentAnalysis.get_best_checkpoint  s    ( D4.D2D""4(("&"I"I%QW"X"X #'--/FGG#
 #
 ' 	LLMUMMMNNN4#'5==RRa #)L)L)L)L
 
 
 rC   lastTscopefilter_nan_and_infc                 $   t          | j                  dk    r| j        d         S |                     |          }|                     |          }|dvr#t	          d                    ||                    d}d}| j        D ]q}||j        vr|dv r|j        |         |         }n|j        |         |         }|rt          |          rI||}|}P|dk    r||k     r|}|}a|dk    r
||k    r|}|}r|st          	                    d	           |S )
a  Retrieve the best trial object.

        Compares all trials' scores on ``metric``.
        If ``metric`` is not specified, ``self.default_metric`` will be used.
        If `mode` is not specified, ``self.default_mode`` will be used.
        These values are usually initialized by passing the ``metric`` and
        ``mode`` parameters to ``tune.run()``.

        Args:
            metric: Key for trial info to order on. Defaults to
                ``self.default_metric``.
            mode: One of [min, max]. Defaults to ``self.default_mode``.
            scope: One of [all, last, avg, last-5-avg, last-10-avg].
                If `scope=last`, only look at each trial's final step for
                `metric`, and compare across trials based on `mode=[min,max]`.
                If `scope=avg`, consider the simple average over all steps
                for `metric` and compare across trials based on
                `mode=[min,max]`. If `scope=last-5-avg` or `scope=last-10-avg`,
                consider the simple average over the last 5 or 10 steps for
                `metric` and compare across trials based on `mode=[min,max]`.
                If `scope=all`, find each trial's min/max score for `metric`
                based on `mode`, and compare trials based on `mode=[min,max]`.
            filter_nan_and_inf: If True (default), NaN or infinite
                values are disregarded and these trials are never selected as
                the best trial.

        Returns:
            The best trial for the provided metric. If no trials contain the provided
                metric, or if the value for the metric is NaN for all trials,
                then returns None.
        r   r   )allr   avg
last-5-avglast-10-avgzExperimentAnalysis: attempting to get best trial for metric {} for scope {} not in ["all", "last", "avg", "last-5-avg", "last-10-avg"]. If you didn't pass a `metric` parameter to `tune.run()`, you have to pass one when fetching the best trial.N)r   r   r   r   r)   r(   zGCould not find best trial. Did you pass the correct `metric` parameter?)
r   r"   _validate_metricr   r-   r7   metric_analysisr   r   r   )	r>   r   r   r   r   r   best_metric_scorer_   metric_scores	            rA   r   z!ExperimentAnalysis.get_best_trial  s   L t{q  ;q>!&&v..""4((KKKE FLVEF F   
 [ 	# 	#EU222DDD$4V<UC$4V<TB! mL&A&A  ($0!"
$5$D$D$0!"

%--&7,&F&F$0!"
 	NN   rC   c                 F    |                      |||          }|r|j        ndS )a.  Retrieve the best config corresponding to the trial.

        Compares all trials' scores on `metric`.
        If ``metric`` is not specified, ``self.default_metric`` will be used.
        If `mode` is not specified, ``self.default_mode`` will be used.
        These values are usually initialized by passing the ``metric`` and
        ``mode`` parameters to ``tune.run()``.

        Args:
            metric: Key for trial info to order on. Defaults to
                ``self.default_metric``.
            mode: One of [min, max]. Defaults to ``self.default_mode``.
            scope: One of [all, last, avg, last-5-avg, last-10-avg].
                If `scope=last`, only look at each trial's final step for
                `metric`, and compare across trials based on `mode=[min,max]`.
                If `scope=avg`, consider the simple average over all steps
                for `metric` and compare across trials based on
                `mode=[min,max]`. If `scope=last-5-avg` or `scope=last-10-avg`,
                consider the simple average over the last 5 or 10 steps for
                `metric` and compare across trials based on `mode=[min,max]`.
                If `scope=all`, find each trial's min/max score for `metric`
                based on `mode`, and compare trials based on `mode=[min,max]`.
        N)r   r   )r>   r   r   r   r   s        rA   r   z"ExperimentAnalysis.get_best_config4  s.    : ((u==
$.8z  D8rC   training_iterationr)   c                 j    |p|                      ||          }|                     |t          d          S )a  Gets the last checkpoint of the provided trial,
        i.e., with the highest "training_iteration".

        If no trial is specified, it loads the best trial according to the
        provided metric and mode (defaults to max. training iteration).

        Args:
            trial: If None, load the best trial automatically.
            metric: If no trial is specified, use this metric to identify
                the best trial and load the last checkpoint from this trial.
            mode: If no trial is specified, use the metric and this mode
                to identify the best trial and load the last checkpoint from it.

        Returns:
            Path for last checkpoint of trial
        r)   )r   r   r   )r>   r_   r   r   s       rA   get_last_checkpointz&ExperimentAnalysis.get_last_checkpointT  s7    & :,,VT::''/A5IIIrC   c                 D    |s| j         st          d          |p| j         S )NzjNo `metric` has been passed and  `default_metric` has not been set. Please specify the `metric` parameter.)r#   r-   )r>   r   s     rA   r   z#ExperimentAnalysis._validate_metricj  s<     	d1 	G   ,,,rC   c                 n    |s| j         st          d          |r|dvrt          d          |p| j         S )NzdNo `mode` has been passed and  `default_mode` has not been set. Please specify the `mode` parameter.r'   r   )r$   r-   )r>   r   s     rA   r   z!ExperimentAnalysis._validate_moder  s^     	D- 	E    	KD..IJJJ(t((rC   c                    ||dv sJ |r|sJ i }| j                                         D ]\  }}|j        r||vrd}nD|dk    r||                                         }n#|dk    r||                                         }nd}	 |j        |                                         ||<   |# t          $ r0 t          	                    d
                    |                     Y w xY w|S )N)r)   r(   r   r)   r(   z2Warning: Non-numerical value(s) encountered for {})r   r   emptyidxmaxidxminilocto_dict	TypeErrorr   r   r7   )r>   r   r   r   r2   r|   idxs          rA   r   z!ExperimentAnalysis._retrieve_rows|  s+    |t~5555!6!!!-3355 	 	HD"x Rj''))j''))WS\1133T

   HOOPTUU     s   "B&&7C C c                     | j                                         }dt          dt          fdfd|d         D             |d<   |S )zEnsure that trials are marked as stubs when pickling,
        so that they can be loaded later without the trainable
        being registered.
        r_   rD   c                     | j         r| S t          | j        d          }|                    |                                            |S )NTrH   )rI   r   trainable_name__setstate____getstate__)r_   
trial_copys     rA   make_stub_if_neededz<ExperimentAnalysis.__getstate__.<locals>.make_stub_if_needed  sL    z u3$???J##E$6$6$8$8999rC   c                 &    g | ]} |          S re   re   )rf   tr   s     rA   rh   z3ExperimentAnalysis.__getstate__.<locals>.<listcomp>  s%    KKKa..q11KKKrC   r"   )__dict__rP   r   )r>   stater   s     @rA   r   zExperimentAnalysis.__getstate__  sc    
 ""$$	u 	 	 	 	 	 LKKK5?KKKhrC   )F)NN)N)NNr   T)NNr   )Nr   r)   )0__name__
__module____qualname____doc__r
   r/   r1   PathLiker   pyarrowr+   
FileSystemr   r   rB   r9   r   r~   r   r:   boolr<   propertyr*   r   r   r   r   r   r   r   r   r   r   r   r   r	   r   r   r   r   r   r   r   r   r   r   r   re   rC   rA   r    r    #   sw        . ?C(,(,&*2/ 2/ 2/$)#r{*:$;2/ %WZ%:;	2/
 e%2/ !2/ sm2/ 2/ 2/ 2/hd5k    *E i    <c9n)=    4
 
d 
tCI 
 
 
 
" ( ( ( ( X( KE K K K XK$ LT L L L XL$ 
 
 
 
 X
< ?	 ? ? ? X?" +T + + + X+$8 8 8 J	 J J J XJ$ Lc4i L L L XL 
I 
 
 
 X
 &$sI~"6 & & & X& CG%1 %1sm%12:3-%1	%1 %1 %1 %1P 59
 

$,SM
	eJ&'	(
 
 
 
B !%"	& && & sm	&
 
*	& & & &T !%"#'V VV smV 	V
 !V 
%V V V Vt !%"	9 99 sm9 	9
 
$9 9 9 9B =BJ J	*	J J J J,-s -s - - - -)3 )3 ) ) ) ) CG sm2:3-	c3h   6d38n      rC   r    )6rP   rt   rK   loggingr1   numbersr   pathlibr   typingr   r   r   r   r	   r
   
pyarrow.fsr  ray.air.constantsr   r   r   ray.train._internal.storager   r   ray.tuner   #ray.tune.execution.experiment_stater   "ray.tune.execution.tune_controllerr   ray.tune.experimentr   ray.tune.resultr   r   ray.tune.utilsr   ray.tune.utils.serializationr   ray.tune.utils.utilr   r   r   ray.util.annotationsr   pandasrq   r   ImportError	getLoggerr  r   r    re   rC   rA   <module>r     s5    				   				             : : : : : : : : : : : : : : : :     V V V V V V V V V V K K K K K K K K       R R R R R R = = = = = = % % % % % % 9 9 9 9 9 9 9 9 ' ' ' ' ' ' < < < < < < I I I I I I I I I I * * * * * *          	BIII
 
	8	$	$ VB
 B
 B
 B
 B
 B
 B
 B
 B
 B
s   
B 	BB