o
    §ôj˜  ã                   @   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   úr/var/www/html/academy/tools/voices/clone/cosy-venv/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   )z„Return 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   )z©Record 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 )z´Do 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