
    &`i                        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 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 erd dlmZ  ej        e          ZdZd	Z ee                    d
d                    e G d d
e j                                          Z e G d de                      Z!e G d de!                      Z" G d dej#                  Z$edde
ee%                  fd            Z&dS )    N)Path)TYPE_CHECKINGDictIterableListOptionalSetType)SafeFallbackEncoder)Callback)
DeprecatedDeveloperAPI	PublicAPI)Trial   zdThe `{old} interface is deprecated in favor of the `{new}` interface and will be removed in Ray 2.7.Loggerzray.tune.logger.LoggerCallback)oldnew)messagec                   R    e Zd ZdZddededed         fdZd Zd	 Z	d
 Z
d Zd ZdS )r   a  Logging interface for ray.tune.

    By default, the UnifiedLogger implementation is used which logs results in
    multiple formats (TensorBoard, rllab/viskit, plain json, custom loggers)
    at once.

    Arguments:
        config: Configuration passed to all logger creators.
        logdir: Directory for all logger creators to log to.
        trial: Trial object for the logger to access.
    Nconfiglogdirtrialr   c                 X    || _         || _        || _        |                                  d S N)r   r   r   _init)selfr   r   r   s       j/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/tune/logger/logger.py__init__zLogger.__init__0   s(    


    c                     d S r    r   s    r   r   zLogger._init6   s    r    c                     t           )z/Given a result, appends it to the existing log.)NotImplementedError)r   results     r   	on_resultzLogger.on_result9   s
     "!r    c                     dS )zUpdates the config for logger.Nr"   )r   r   s     r   update_configzLogger.update_config>   	     	r    c                     dS )z+Releases all resources used by this logger.Nr"   r#   s    r   closezLogger.closeC   r*   r    c                     dS )z#Flushes all disk writes to storage.Nr"   r#   s    r   flushzLogger.flushH   r*   r    r   )__name__
__module____qualname____doc__r   strr   r   r   r'   r)   r,   r.   r"   r    r   r   r      s        
 
 t S '9J      " " "
  
  
    r    c                   (   e Zd ZdZddZddZddZdedddefd	Z	ddd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eded         ddfdZdeded         ddfdZdeded         ddfdZdeddddfdZdS )LoggerCallbacka  Base class for experiment-level logger callbacks

    This base class defines a general interface for logging events,
    like trial starts, restores, ends, checkpoint saves, and receiving
    trial results.

    Callbacks implementing this interface should make sure that logging
    utilities are cleaned up properly on trial termination, i.e. when
    ``log_trial_end`` is received. This includes e.g. closing files.
    r   r   c                     dS )z\Handle logging when a trial starts.

        Args:
            trial: Trial object.
        Nr"   r   r   s     r   log_trial_startzLoggerCallback.log_trial_start[   	     	r    c                     dS )z^Handle logging when a trial restores.

        Args:
            trial: Trial object.
        Nr"   r7   s     r   log_trial_restorez LoggerCallback.log_trial_restorec   r9   r    c                     dS )zhHandle logging when a trial saves a checkpoint.

        Args:
            trial: Trial object.
        Nr"   r7   s     r   log_trial_savezLoggerCallback.log_trial_savek   r9   r    	iterationr&   c                     dS )zHandle logging when a trial reports a result.

        Args:
            trial: Trial object.
            result: Result dictionary.
        Nr"   )r   r>   r   r&   s       r   log_trial_resultzLoggerCallback.log_trial_results   s	     	r    Ffailedc                     dS )zHandle logging when a trial ends.

        Args:
            trial: Trial object.
            failed: True if the Trial finished gracefully, False if
                it failed (e.g. when it raised an exception).
        Nr"   )r   r   rA   s      r   log_trial_endzLoggerCallback.log_trial_end|   s	     	r    trialsc                 4    |                      |||           d S r   )r@   )r   r>   rD   r   r&   infos         r   on_trial_resultzLoggerCallback.on_trial_result   s"     	i77777r    c                 0    |                      |           d S r   )r8   r   r>   rD   r   rF   s        r   on_trial_startzLoggerCallback.on_trial_start   s     	U#####r    c                 0    |                      |           d S r   )r;   rI   s        r   on_trial_restorezLoggerCallback.on_trial_restore   s     	u%%%%%r    c                 0    |                      |           d S r   )r=   rI   s        r   on_trial_savezLoggerCallback.on_trial_save   s     	E"""""r    c                 4    |                      |d           d S )NFrA   rC   rI   s        r   on_trial_completez LoggerCallback.on_trial_complete   s#     	5/////r    c                 4    |                      |d           d S )NTrP   rQ   rI   s        r   on_trial_errorzLoggerCallback.on_trial_error   s#     	5.....r    	file_namereturnNc                    |j         sd S t          |j        |                                          }t          |j        j        |                                          }	 t          j                            |||j        j	                   t                              d| d|            d S # t          $ r! t                              d|            Y d S t          $ r! t                              d|            Y d S w xY w)N)source_filesystemzCopied z to zRemote file not found: zError downloading )
checkpointr   
local_pathas_posixstoragetrial_fs_pathpyarrowfs
copy_filesstorage_filesystemloggerdebugFileNotFoundErrorwarning	Exception	exception)r   rU   r   
local_fileremote_files        r   _restore_from_remotez#LoggerCallback._restore_from_remote   s.    	 F%*I66??AA
5=6	BBKKMM
	AJ!!"'-"B "   
 LL@;@@J@@AAAAA  	D 	D 	DNNB[BBCCCCCC 	A 	A 	A?+??@@@@@@	As   AB, ,'D &D ?D r   r   F)r/   r0   r1   r2   r8   r;   r=   intr   r@   boolrC   r   rG   rJ   rL   rN   rR   rT   r3   rj   r"   r    r   r5   r5   N   s
       	 	         # g t     7 D    88 W8 	8
 8 8 8 8$$&*7m$<C$ $ $ $
&&&*7m&<C& & & &
##&*7m#<C# # # #
00&*7m0<C0 0 0 0
//&*7m/<C/ / / /
Ac A' Ad A A A A A Ar    r5   c                   t    e Zd ZdZdeee                  fdZddZddZ	ddZ
d	eddd
efdZddddefdZdS )LegacyLoggerCallbacka  Supports logging to trial-specific `Logger` classes.

    Previously, Ray Tune logging was handled via `Logger` classes that have
    been instantiated per-trial. This callback is a fallback to these
    `Logger`-classes, instantiating each `Logger` class for each trial
    and logging to them.

    Args:
        logger_classes: Logger classes that should
            be instantiated for each trial.

    logger_classesc                 <    t          |          | _        i | _        d S r   )listrq   _class_trial_loggers)r   rq   s     r   r   zLegacyLoggerCallback.__init__   s     ">22OQ!!!r    r   r   c                     |                                  | j        D ]G}| j                            |i           }||vr ||j        |j        |          }|||<   || j        |<   Hd S r   )init_local_pathrq   rt   getr   rZ   )r   r   logger_classtrial_loggersrb   s        r   r8   z$LegacyLoggerCallback.log_trial_start   s     / 	D 	DL 599,KKMM))%elE4DeLL'-e$6CD%l33	D 	Dr    c                     | j                                         D ]#\  }}||v r||                                          $d S r   rt   itemsr.   r   r   rx   ry   s       r   r;   z&LegacyLoggerCallback.log_trial_restore   R    +/+D+J+J+L+L 	- 	-'L-%%e$**,,,	- 	-r    c                     | j                                         D ]#\  }}||v r||                                          $d S r   r{   r}   s       r   r=   z#LegacyLoggerCallback.log_trial_save   r~   r    r>   r&   c                     | j                                         D ]$\  }}||v r||                             |           %d S r   )rt   r|   r'   )r   r>   r   r&   rx   ry   s         r   r@   z%LegacyLoggerCallback.log_trial_result   sT    +/+D+J+J+L+L 	7 	7'L-%%e$..v666	7 	7r    FrA   c                     | j                                         D ]#\  }}||v r||                                          $d S r   )rt   r|   r,   )r   r   rA   rx   ry   s        r   rC   z"LegacyLoggerCallback.log_trial_end   r~   r    Nrk   rl   )r/   r0   r1   r2   r   r
   r   r   r8   r;   r=   rm   r   r@   rn   rC   r"   r    r   rp   rp      s         RxV'= R R R RD D D D- - - -
- - - -
7# 7g 7t 7 7 7 7
- -7 -D - - - - - -r    rp   c                         e Zd Zd fd	Z xZS )
_RayDumperNc                     t          |          t          k    r$t                                          ||d          S t                                          |||          S )NT)
flow_style)len_SEQUENCE_LEN_FLOW_STYLEsuperrepresent_sequence)r   tagsequencer   	__class__s       r   r   z_RayDumper.represent_sequence   sS    x==33377--c8-MMMww))#xJ)OOOr    r   )r/   r0   r1   r   __classcell__)r   s   @r   r   r      sG        P P P P P P P P P Pr    r   excludec                 f   |                                  } |                     d            |                     d            i }|                                 D ]\  }}||||vr|||<   t          j        |t
                    }t          j        t          j        |          t          d          S )N)r   )
hist_stats)clsF)Dumperdefault_flow_style)
copyupdater|   jsondumpsr   yamldumploadsr   )r&   r   outkvcleaneds         r   pretty_printr      s    [[]]F
MMM
MMTM"""
C  1=go'1A1ACFj"5666G9TZ((PUVVVVr    r   )'abcr   loggingpathlibr   typingr   r   r   r   r   r	   r
   r^   r   ray.air._internal.jsonr   ray.tune.callbackr   ray.util.annotationsr   r   r   ray.tune.experiment.trialr   	getLoggerr/   rb   r   _LOGGER_DEPRECATION_WARNINGformatABCr   r5   rp   
SafeDumperr   r3   r   r"   r    r   <module>r      sj   



         K K K K K K K K K K K K K K K K K K   6 6 6 6 6 6 & & & & & & D D D D D D D D D D 0//////		8	$	$  8  '..: /    
 ( ( ( ( (SW ( (  (V mA mA mA mA mAX mA mA mA` .- .- .- .- .-> .- .- .-bP P P P P P P P 
W 
W(3s8"4 
W 
W 
W 
W 
W 
Wr    