
      i               	          d Z ddlZddlZddlZddlmZ ddlmZ ddlm	Z	m
Z
 ddlmZ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  G d dee      Z G d de      Zdej6                  fde
e	   dee	   dee
e   gef   defdZy)z.Abstract base class used to build new loggers.    N)ABC)defaultdict)MappingSequence)AnyCallableOptional)override)Logger)_DummyExperiment)rank_zero_experiment)ModelCheckpointc                   <    e Zd ZdZdeddfdZedee   fd       Z	y)r   z"Base class for experiment loggers.checkpoint_callbackreturnNc                      y)zCalled after model checkpoint callback saves a new checkpoint.

        Args:
            checkpoint_callback: the model checkpoint callback instance

        N )selfr   s     u/Volumes/fast/ai/experiments/voice-extract-mac/.venv/lib/python3.12/site-packages/pytorch_lightning/loggers/logger.pyafter_save_checkpointzLogger.after_save_checkpoint#   s     	    c                      y)zvReturn the root directory where experiment logs get saved, or `None` if the logger does not save data
        locally.Nr   r   s    r   save_dirzLogger.save_dir,   s     r   )
__name__
__module____qualname____doc__r   r   propertyr	   strr   r   r   r   r   r       s7    , T  (3-  r   r   c                        e Zd ZdZd fdZedefd       Zede	de	ddfd       Z
ede	de	ddfd	       Zeedefd
              Zeedefd              Zdedd fdZdedefdZ xZS )DummyLoggerzDummy logger for internal use.

    It is useful if we want to disable user's logger for a feature, but still ensure that user code can run

    r   Nc                 @    t         |           t               | _        y N)super__init__DummyExperiment_experiment)r   	__class__s    r   r&   zDummyLogger.__init__:   s    *,r   c                     | j                   S )z9Return the experiment object associated with this logger.)r(   r   s    r   
experimentzDummyLogger.experiment>   s     r   argskwargsc                      y r$   r   r   r,   r-   s      r   log_metricszDummyLogger.log_metricsC       r   c                      y r$   r   r/   s      r   log_hyperparamszDummyLogger.log_hyperparamsG   r1   r   c                      y)zReturn the experiment name. r   r   s    r   namezDummyLogger.nameK        r   c                      y)zReturn the experiment version.r5   r   r   s    r   versionzDummyLogger.versionQ   r7   r   idxc                     | S r$   r   )r   r:   s     r   __getitem__zDummyLogger.__getitem__W   s    r   r6   c                 *    dt         dt         ddfd}|S )zUAllows the DummyLogger to be called with arbitrary methods, to avoid AttributeErrors.r,   r-   r   Nc                       y r$   r   )r,   r-   s     r   methodz'DummyLogger.__getattr__.<locals>.method^   s    r   )r   )r   r6   r?   s      r   __getattr__zDummyLogger.__getattr__[   s#    	# 	 	 	 r   )r   N)r   r   r   r   r&   r   r'   r+   r
   r   r0   r3   r    r6   r9   intr<   r   r@   __classcell__)r)   s   @r   r"   r"   3   s    -  O          S C D   c       s }   r   r"   dictsagg_key_funcsdefault_funcr   c                    |xs i }t        t        j                  t        j                  | D cg c]  }t        |j                                c}            }t        t              }|D ]u  }|j                  |      }| D cg c]  }|j                  |       c}D 	cg c]  }	|	|		 }
}	t        |
d   t              rt        |
||      ||<   g |xs ||
      ||<   w t        |      S c c}w c c}w c c}	w )a#  Merge a sequence with dictionaries into one dictionary by aggregating the same keys with some given function.

    Args:
        dicts:
            Sequence of dictionaries to be merged.
        agg_key_funcs:
            Mapping from key name to function. This function will aggregate a
            list of values, obtained from the same key of all dictionaries.
            If some key has no specified aggregation function, the default one
            will be used. Default is: ``None`` (all keys will be aggregated by the
            default function).
        default_func:
            Default function to aggregate keys, which are not presented in the
            `agg_key_funcs` map.

    Returns:
        Dictionary with merged values.

    Examples:
        >>> import pprint
        >>> d1 = {'a': 1.7, 'b': 2.0, 'c': 1, 'd': {'d1': 1, 'd3': 3}}
        >>> d2 = {'a': 1.1, 'b': 2.2, 'v': 1, 'd': {'d1': 2, 'd2': 3}}
        >>> d3 = {'a': 1.1, 'v': 2.3, 'd': {'d3': 3, 'd4': {'d5': 1}}}
        >>> dflt_func = min
        >>> agg_funcs = {'a': statistics.mean, 'v': max, 'd': {'d1': sum}}
        >>> pprint.pprint(merge_dicts([d1, d2, d3], agg_funcs, dflt_func))
        {'a': 1.3,
         'b': 2.0,
         'c': 1,
         'd': {'d1': 3, 'd2': 3, 'd3': 3, 'd4': {'d5': 1}},
         'v': 2.3}

    r   )list	functoolsreduceoperatoror_setkeysr   dictget
isinstancemerge_dicts)rC   rD   rE   drM   d_outkfnd_invvalues_to_aggs              r   rQ   rQ   e   s    L "'RM	  u/Mu!AFFHu/MNODd#Eq!=B$CUTTXXa[U$CU$Cqq}$CUmA&-"="lCE!H**lM:E!H  ; 0N %DUs    C-C2C7'C7)r   rH   rJ   
statisticsabcr   collectionsr   collections.abcr   r   typingr   r   r	   typing_extensionsr
   lightning_fabric.loggersr   FabricLoggerlightning_fabric.loggers.loggerr   r'   r   ,pytorch_lightning.callbacks.model_checkpointr   r"   meanfloatrN   rQ   r   r   r   <module>re      s    5     # - * * & ; O @ H\3 &.& .h (,7A2G2G$2 HUO,e342 
	2r   