o
    8wi                     @   s2   d dl mZ d dlZd dlmZ G dd dZdS )    )OptionalN)_BaseProgressc                   @   s   e Zd ZdZdddZedefdd	Zejd
eddfdd	ZdddZ	de
fddZde
ddfddZd dee
 dede
fddZ	d!de
deddfddZde
deddfddZdddZdS )"_LoopzBasic Loops interface.trainer
pl.TrainerreturnNc                 C   s   d| _ d| _|| _d S NF)_restarting_loaded_from_state_dictr   )selfr    r   Y/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/pytorch_lightning/loops/loop.py__init__   s   
z_Loop.__init__c                 C   s   | j S )zDWhether the state of this loop was reloaded and it needs to restart.)r	   r   r   r   r   
restarting   s   z_Loop.restartingr   c                 C   s,   || _ t|  D ]
}t|tr||_q	dS )z7Connects this loop's restarting value and its children.N)r	   varsvalues
isinstancer   r   )r   r   loopr   r   r   r   !   s   
c                 C   s   d S )Nr   r   r   r   r   reset_restart_stage)   s   z_Loop.reset_restart_stagec                 C   s   i S )zCalled when saving a model checkpoint, use to persist loop state.

        Returns:
            The current loop state.

        r   r   r   r   r   on_save_checkpoint,   s   z_Loop.on_save_checkpoint
state_dictc                 C   s   dS )zACalled when loading a model checkpoint, use to reload loop state.Nr   )r   r   r   r   r   on_load_checkpoint5   s    z_Loop.on_load_checkpoint destinationprefixc                 C   sn   |du ri }|   ||d < | j D ]!\}}|| }t|tr'| ||< qt|tr4|||d  q|S )a?  The state dict is determined by the state and progress of this loop and all its children.

        Args:
            destination: An existing dictionary to update with this loop's state. By default a new dictionary
                is returned.
            prefix: A prefix for each key in the state dictionary

        Nr   .)r   __dict__itemsr   r   r   r   )r   r   r   kvkeyr   r   r   r   8   s   	

z_Loop.state_dictc                 C   sV   |  | | | j D ]\}}t|tr"|| || d  qd| _d| _dS )z2Loads the state of this loop and all its children.r   TN)	_load_from_state_dictcopyr   r   r   r   load_state_dictr   r
   )r   r   r   r   r    r   r   r   r$   N   s   

z_Loop.load_state_dictc                 C   sd   | j  D ]\}}|| }||vrqt|tr|||  q|d |v r0| ||d   d S d S )Nr   )r   r   r   r   r$   r   )r   r   r   r   r    r!   r   r   r   r"   [   s   
z_Loop._load_from_state_dictc                 C   s   d| _ d| _|   d S r   )r	   r
   r   r   r   r   r   on_iteration_donef   s   z_Loop.on_iteration_done)r   r   r   N)r   N)Nr   )r   )__name__
__module____qualname____doc__r   propertyboolr   setterr   dictr   r   r   strr   r$   r"   r%   r   r   r   r   r      s*    

	
r   )typingr   pytorch_lightningpl pytorch_lightning.loops.progressr   r   r   r   r   r   <module>   s   