a
    d                     @   s   d dl mZ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 G dd deZG d	d
 d
eZG dd deedZG dd deedZeG dd dZdS )    )	dataclassfield)EnumEnumMeta)AnyListOptional)LightningEnum)_FaultTolerantMode)rank_zero_deprecationc                       sR   e Zd ZdZeed fddZeed fddZeeed fdd	Z  Z	S )
_DeprecationManagingEnumMetazEnum that calls `deprecate()` whenever a member is accessed.

    Adapted from: https://stackoverflow.com/a/62309159/208880
    )namereturnc                    s6   t  |}|dr |ds2t|tr2|  |S )N__)super__getattribute__
startswithendswith
isinstancer   	deprecate)clsr   obj	__class__ i/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/pytorch_lightning/trainer/states.pyr      s    z-_DeprecationManagingEnumMeta.__getattribute__c                    s   t  |}|  |S N)r   __getitem__r   )r   r   memberr   r   r   r   $   s    z(_DeprecationManagingEnumMeta.__getitem__)argskwargsr   c                    s(   t  j|i |}t|tr$|  |S r   )r   __call__r   r   r   )r   r   r    r   r   r   r   r!   )   s    
z%_DeprecationManagingEnumMeta.__call__)
__name__
__module____qualname____doc__strr   r   r   r!   __classcell__r   r   r   r   r      s   r   c                   @   s2   e Zd ZdZdZdZdZdZee	dddZ
d	S )
TrainerStatuszNEnum for the status of the :class:`~pytorch_lightning.trainer.trainer.Trainer`ZinitializingZrunningfinishedinterruptedr   c                 C   s   | | j | jfv S r   )FINISHEDINTERRUPTEDselfr   r   r   stopped8   s    zTrainerStatus.stoppedN)r"   r#   r$   r%   INITIALIZINGZRUNNINGr,   r-   propertyboolr0   r   r   r   r   r(   0   s   r(   c                   @   sH   e Zd ZdZdZdZdZdZdZddd	d
Z	e
ed  dddZdS )	TrainerFnz
    Enum for the user-facing functions of the :class:`~pytorch_lightning.trainer.trainer.Trainer`
    such as :meth:`~pytorch_lightning.trainer.trainer.Trainer.fit` and
    :meth:`~pytorch_lightning.trainer.trainer.Trainer.test`.
    ZfitvalidatetestpredicttuneNr+   c                 C   s    | | j krtd| j d d S )Nz`TrainerFn.>` has been deprecated in v1.8.0 and will be removed in v2.0.0.TUNINGr   r   r.   r   r   r   r   J   s    
zTrainerFn.deprecatec                 C   s   dd | D }|S )Nc                 S   s   g | ]}|d kr|qS r8   r   .0fnr   r   r   
<listcomp>R       z+TrainerFn._without_tune.<locals>.<listcomp>r   r   fnsr   r   r   _without_tuneP   s    zTrainerFn._without_tune)r"   r#   r$   r%   ZFITTING
VALIDATINGTESTING
PREDICTINGr;   r   classmethodr   rD   r   r   r   r   r4   =   s   r4   )	metaclassc                   @   st   e Zd ZdZdZdZdZdZdZdZ	e
edd	d
Ze
ee dddZddddZeed  dddZdS )RunningStagea`  Enum for the current running stage.

    This stage complements :class:`TrainerFn` by specifying the current running stage for each function.
    More than one running stage value can be set while a :class:`TrainerFn` is running:

        - ``TrainerFn.FITTING`` - ``RunningStage.{SANITY_CHECKING,TRAINING,VALIDATING}``
        - ``TrainerFn.VALIDATING`` - ``RunningStage.VALIDATING``
        - ``TrainerFn.TESTING`` - ``RunningStage.TESTING``
        - ``TrainerFn.PREDICTING`` - ``RunningStage.PREDICTING``
        - ``TrainerFn.TUNING`` - ``RunningStage.{TUNING,SANITY_CHECKING,TRAINING,VALIDATING}``
    ZtrainZsanity_checkr5   r6   r7   r8   r+   c                 C   s   | | j | jfv S r   )rE   rF   r.   r   r   r   
evaluatingj   s    zRunningStage.evaluatingc                 C   s"   | | j krd S | | jkrdS | jS )Nval)SANITY_CHECKINGrE   valuer.   r   r   r   dataloader_prefixn   s
    

zRunningStage.dataloader_prefixNc                 C   s    | | j krtd| j d d S )Nz`RunningStage.r9   r:   r.   r   r   r   r   v   s    
zRunningStage.deprecatec                 C   s   dd | D }|S )Nc                 S   s   g | ]}|d kr|qS r<   r   r=   r   r   r   r@   ~   rA   z.RunningStage._without_tune.<locals>.<listcomp>r   rB   r   r   r   rD   |   s    zRunningStage._without_tune)r"   r#   r$   r%   ZTRAININGrM   rE   rF   rG   r;   r2   r3   rK   r   r&   rO   r   rH   r   rD   r   r   r   r   rJ   V   s   rJ   c                   @   sx   e Zd ZU dZejZeed< dZe	e
 ed< dZe	e ed< eejdZeed< eedd	d
ZeedddZdS )TrainerStatez_Dataclass to encapsulate the current :class:`~pytorch_lightning.trainer.trainer.Trainer` state.statusNr?   stage)default_factory_fault_tolerant_moder+   c                 C   s   | j tjkS r   )rQ   r(   r,   r.   r   r   r   r)      s    zTrainerState.finishedc                 C   s   | j jS r   )rQ   r0   r.   r   r   r   r0      s    zTrainerState.stopped)r"   r#   r$   r%   r(   r1   rQ   __annotations__r?   r   r4   rR   rJ   r   r
   Zdetect_current_moderT   r2   r3   r)   r0   r   r   r   r   rP      s   
rP   N)Zdataclassesr   r   enumr   r   typingr   r   r   Zpytorch_lightning.utilitiesr	   Z!pytorch_lightning.utilities.enumsr
   Z%pytorch_lightning.utilities.rank_zeror   r   r(   r4   rJ   rP   r   r   r   r   <module>   s   ,