
      i                     <    d dl mZ d dlmZ d dlmZ  G d d      Zy)    )OptionalN)_BaseProgressc                       e Zd ZdZddZedefd       Zej                  deddfd       Zedefd       Z	dd	Z
defd
ZdeddfdZddee   dedefdZ	 ddededdfdZdededdfdZddZy)_LoopzBasic Loops interface.returnNc                 <    d| _         d| _        d| _        || _        y NF)_restarting_loaded_from_state_dict_resuming_from_checkpointtrainer)selfr   s     q/Volumes/fast/ai/experiments/voice-extract-mac/.venv/lib/python3.12/site-packages/lightning/pytorch/loops/loop.py__init__z_Loop.__init__   s!     ',$).&    c                     | j                   S )zDWhether the state of this loop was reloaded and it needs to restart.)r
   r   s    r   
restartingz_Loop.restarting   s     r   r   c                 ~    || _         t        |       j                         D ]  }t        |t              s||_         y)z7Connects this loop's restarting value and its children.N)r
   varsvalues
isinstancer   r   )r   r   loops      r   r   z_Loop.restarting"   s4     &J%%'D$&", (r   c                     | j                   S )z>Indicates whether training is being resumed from a checkpoint.)r   r   s    r   is_resumingz_Loop.is_resuming*   s     ---r   c                      y )N r   s    r   reset_restart_stagez_Loop.reset_restart_stage/   s    r   c                     i S )zCalled when saving a model checkpoint, use to persist loop state.

        Returns:
            The current loop state.

        r   r   s    r   on_save_checkpointz_Loop.on_save_checkpoint2   s	     	r   
state_dictc                      y)zACalled when loading a model checkpoint, use to reload loop state.Nr   )r   r!   s     r   on_load_checkpointz_Loop.on_load_checkpoint;   s    r   destinationprefixc                    |i }| j                         ||dz   <   | j                  j                         D ]T  \  }}||z   }t        |t              r|j                         ||<   /t        |t              s@|j                  ||dz          V |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

        r!   .)r    __dict__itemsr   r   r!   r   )r   r$   r%   kvkeys         r   r!   z_Loop.state_dict>   s     K-1-D-D-FF\)*MM'')DAq1*C!]+#$<<>C Au%[#)4 * r   c                     | j                  |j                         |       | j                  j                         D ]<  \  }}t	        |t
              s|j                  |j                         ||z   dz          > d| _        d| _        d| _	        y)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+   s        r   r0   z_Loop.load_state_dictT   sy     	"":??#4f=MM'')DAq!U#!!*//"3VaZ#5EF * '+$)-&r   c                     | j                   j                         D ]4  \  }}||z   }||vrt        |t              s!|j	                  ||          6 |dz   |v r| j                  ||dz             y y )Nr!   )r(   r)   r   r   r0   r#   )r   r!   r%   r*   r+   r,   s         r   r.   z_Loop._load_from_state_dictb   sy    MM'')DAq1*C*$!]+!!*S/2 * L J.##Jv/D$EF /r   c                 N    d| _         d| _        d| _        | j                          y r	   )r
   r   r   r   r   s    r   on_iteration_donez_Loop.on_iteration_donem   s&     ',$).&  "r   )r   z
pl.Trainerr   N)r   N)N )r4   )__name__
__module____qualname____doc__r   propertyboolr   setterr   r   dictr    r#   r   strr!   r0   r.   r3   r   r   r   r   r      s       D     -T -d - - .T . .D PT Pd Phtn S RV 2 .. . 
	.	G 	Gc 	Gd 	G#r   r   )typingr   lightning.pytorchpytorchpl lightning.pytorch.loops.progressr   r   r   r   r   <module>rC      s      :]# ]#r   