o
    zi                     @   s   d 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mZmZ ddlmZ ddlmZ ddlmZ G d	d
 d
eZde
de
fddZG dd dZdS )z.Abstract base class used to build new loggers.    )ABCabstractmethod)	Namespace)wraps)AnyCallableDictOptionalUnion)Tensor)Module)rank_zero_onlyc                	   @   s  e Zd ZdZeedee fddZeedee	e
ef  fddZedee fddZedee fd	d
ZedefddZed deeef dee
 ddfddZede	eeef ef dededdfddZd dedee ddfddZd!ddZdeddfddZdS )"Loggerz"Base class for experiment loggers.returnc                 C      dS )zReturn the experiment name.N selfr   r   S/home/ubuntu/.local/lib/python3.10/site-packages/lightning_fabric/loggers/logger.pyname       zLogger.namec                 C   r   )zReturn the experiment version.Nr   r   r   r   r   version#   r   zLogger.versionc                 C   r   )zReturn the root directory where all versions of an experiment get saved, or `None` if the logger does not
        save data locally.Nr   r   r   r   r   root_dir(      zLogger.root_dirc                 C   r   )z~Return directory the current version of the experiment gets saved, or `None` if the logger does not save
        data locally.Nr   r   r   r   r   log_dir.   r   zLogger.log_dirc                 C   r   )zRReturn the default separator used by the logger to group the data into subfolders./r   r   r   r   r   group_separator4   s   zLogger.group_separatorNmetricsstepc                 C   r   )a  Records metrics. This method logs metrics as soon as it received them.

        Args:
            metrics: Dictionary with metric names as keys and measured quantities as values
            step: Step number at which the metrics should be recorded

        Nr   )r   r   r   r   r   r   log_metrics9   s   	zLogger.log_metricsparamsargskwargsc                 O   r   )a?  Record hyperparameters.

        Args:
            params: :class:`~argparse.Namespace` or `Dict` containing the hyperparameters
            args: Optional positional arguments, depends on the specific logger being used
            kwargs: Optional keyword arguments, depends on the specific logger being used

        Nr   )r   r    r!   r"   r   r   r   log_hyperparamsD   r   zLogger.log_hyperparamsmodelinput_arrayc                 C   r   )zRecord model graph.

        Args:
            model: the model with an implementation of ``forward``.
            input_array: input passes to `model.forward`

        Nr   )r   r$   r%   r   r   r   	log_graphO   s   zLogger.log_graphc                 C   r   )zSave log data.Nr   r   r   r   r   saveY   r   zLogger.savestatusc                 C   s   |    dS )zDo any processing that is necessary to finalize an experiment.

        Args:
            status: Status that the experiment finished with (e.g. success, failed, aborted)

        N)r'   )r   r(   r   r   r   finalize\   s   zLogger.finalizeN)r   N)__name__
__module____qualname____doc__propertyr   r	   strr   r
   intr   r   r   r   r   floatr   r   r   r#   r   r   r&   r'   r)   r   r   r   r   r      s*    &
,


r   fnr   c                    s*   t  dtdtttf f fdd}|S )zIReturns the real experiment on rank 0 and otherwise the _DummyExperiment.r   r   c                    s   t jdkrt S  | S )a  
        Note:
            ``self`` is a custom logger instance. The loggers typically wrap an ``experiment`` method
            with a ``@rank_zero_experiment`` decorator.

            ``Union[Any, _DummyExperiment]`` is used because the wrapped hooks have several return
            types that are specific to the custom logger. The return type here can be considered as
            ``Union[return type of logger.experiment, _DummyExperiment]``.
        r   )r   rank_DummyExperimentr   r3   r   r   
experimenti   s   
z(rank_zero_experiment.<locals>.experiment)r   r   r
   r   r5   )r3   r7   r   r6   r   rank_zero_experimentf   s    r8   c                   @   s`   e Zd ZdZdededdfddZdedefd	d
Zdedd fddZ	dededdfddZ
dS )r5   zDummy experiment.r!   kwr   Nc                 O      d S r*   r   )r   r!   r9   r   r   r   nop~      z_DummyExperiment.nop_c                 C   s   | j S r*   )r;   )r   r=   r   r   r   __getattr__   s   z_DummyExperiment.__getattr__idxc                 C   s   | S r*   r   )r   r?   r   r   r   __getitem__   s   z_DummyExperiment.__getitem__r"   c                 O   r:   r*   r   )r   r!   r"   r   r   r   __setitem__   r<   z_DummyExperiment.__setitem__)r+   r,   r-   r.   r   r;   r   r>   r1   r@   rA   r   r   r   r   r5   {   s    r5   N)r.   abcr   r   argparser   	functoolsr   typingr   r   r   r	   r
   torchr   torch.nnr   $lightning_fabric.utilities.rank_zeror   r   r8   r5   r   r   r   r   <module>   s   K