
    &`ik                     $   	 d dl Z d dlmZ n# eef$ rZ ed          edZ[ww xY w	 d dlZd dlZn# eef$ rZ ed          edZ[ww xY w	 d dlm	Z	 n# e$ r dZ	Y nw xY wd dl
Z
d dlZd dlZd dlZd dlmZ d dlmZmZmZmZmZmZmZmZ d dlmZ d d	lmZmZmZ d d
lm Z  d dl!m"Z" erd dl#m$Z$  ej%        e&          Z'dZ( G d de          Z)	 d)dZ*dej+        j,        de-fdZ.	 d*dej+        j,        de-de-de/fdZ0	 d+de-dej+        j,        de-deee-                  ddf
dZ1de-ddde-deee-                  ddf
dZ2	 d+dej+        j,        de-deeej+        j3        ge/f                  dee-         fdZ4dej+        j,        de-de/fdZ5dej+        j,        de-de/fd Z6dej+        j,        de-ddfd!Z7	 d+d"ee-ej8        f         d#eej+        j,                 deej+        j,        e-f         fd$Z9 G d% d&e          Z:e" G d' d(                      Z;dS ),    N)LocalFileSystemzdfsspec is a required dependency of Ray Train and Ray Tune. Please install with: `pip install fsspec`zfpyarrow is a required dependency of Ray Train and Ray Tune. Please install with: `pip install pyarrow`)S3FileSystem)Path)TYPE_CHECKINGCallableDictListOptionalTupleTypeUnion)TempFileLock)
SyncConfigSyncer_BackgroundSyncer)_get_ray_train_session_dir)DeveloperAPI)
Checkpointz.validate_storage_markerc                   j     e Zd ZdZdedee         f fdZed             Z	dede
fdZd fd	Z xZS )_ExcludingLocalFilesystema  LocalFileSystem wrapper to exclude files according to patterns.

    Args:
        root_path: Root path to strip when matching with the exclude pattern.
            Ex: root_path="/tmp/a/b/c", exclude=["*a*"], will exclude
            /tmp/a/b/c/_a_.txt but not ALL of /tmp/a/*.
        exclude: List of patterns that are applied to files returned by
            ``self.find()``. If a file path matches this pattern, it will
            be excluded.

    	root_pathexcludec                 V     t                      j        di | || _        || _        d S N )super__init___exclude
_root_path)selfr   r   kwargs	__class__s       o/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/train/_internal/storage.pyr   z"_ExcludingLocalFilesystem.__init__A   s2    ""6"""#    c                     dS )N_excluding_localr   r    s    r#   fsidz_ExcludingLocalFilesystem.fsidF   s    !!r$   pathreturnc                 ,   t          |          }|                    | j                                                  }|g}|                                r|                    |dz              | j        D ] t          fd|D                       r dS !dS )zdReturn True if `path` (relative to `root_path`) matches any of the
        `self._exclude` patterns./c              3   B   K   | ]}t          j         |          V  d S N)fnmatch).0	candidateexcls     r#   	<genexpr>z<_ExcludingLocalFilesystem._should_exclude.<locals>.<genexpr>U   s/      VV	7?9d33VVVVVVr$   TF)r   relative_tor   as_posixis_dirappendr   any)r    r)   relative_pathmatch_candidatesr2   s       @r#   _should_excludez)_ExcludingLocalFilesystem._should_excludeJ   s     Dzz((99BBDD)?;;== 	9##MC$7888M 	 	DVVVVEUVVVVV ttur$   NFc                       t                      j        |f|||d|}|r  fd|                                D             S  fd|D             S )z+Call parent find() and exclude from result.)maxdepthwithdirsdetailc                 F    i | ]\  }}                     |          ||S r   r;   )r0   r)   outr    s      r#   
<dictcomp>z2_ExcludingLocalFilesystem.find.<locals>.<dictcomp>_   sC       D#++D11c  r$   c                 >    g | ]}                     |          |S r   rA   )r0   r)   r    s     r#   
<listcomp>z2_ExcludingLocalFilesystem.find.<locals>.<listcomp>e   s,    MMMT$2F2Ft2L2LMDMMMr$   )r   finditems)r    r)   r=   r>   r?   r!   pathsr"   s   `      r#   rF   z_ExcludingLocalFilesystem.findY   s    
#hv
 
IO
 
  	N   !&    NMMMUMMMMr$   )NFF)__name__
__module____qualname____doc__r   r	   strr   propertyr(   boolr;   rF   __classcell__r"   s   @r#   r   r   4   s        
 
$$ $c $ $ $ $ $ $
 " " X"C D    N N N N N N N N N Nr$   r   c                     t           r5t          |t          j        j                   r|                    dd           |                    dd           t          j        j        | |f||d|S )Nuse_threadsF
chunk_sizei   source_filesystemdestination_filesystem)r   
isinstancepyarrowfs
setdefault
copy_files)sourcedestinationrV   rW   r!   s        r#   _pyarrow_fs_copy_filesr_   h   s      0
#97:;RSS 0 	-/// l$4555:  ,5	 
   r$   rZ   fs_pathc                     t          | |          }	 |r|                     |           d S |                     |           d S # t          $ r% t                              d|  d| d           Y d S w xY w)Nz(Caught exception when deleting path at (, ):)_is_directory
delete_dirdelete_file	Exceptionlogger	exception)rZ   r`   r6   s      r#   _delete_fs_pathrj      s    2w''FW 	$MM'"""""NN7##### W W WUBUU'UUUVVVVVVWs   A A +A10A1T
local_pathfilelockc                 4   t          |                                          }|                                }t          | |          r|                    dd           n|j                            dd           	 |r\t          t          j        	                    |           d          5  t          |||            ddd           dS # 1 swxY w Y   dS t          |||            dS # t          $ r}|st          j        |d           |d}~ww xY w)aW  Downloads a directory or file from (fs, fs_path) to a local path.

    If fs_path points to a directory:
    - The full directory contents are downloaded directly into `local_path`,
      rather than to a subdirectory of `local_path`.

    If fs_path points to a file:
    - The file is downloaded to `local_path`, which is expected to be a file path.

    If the download fails, the `local_path` contents are
    cleaned up before raising, if the directory did not previously exist.

    NOTE: This method creates `local_path`'s parent directories if they do not
    already exist. If the download fails, this does NOT clean up all the parent
    directories that were created.

    Args:
        fs: The filesystem to download from.
        fs_path: The filesystem path (either a directory or a file) to download.
        local_path: The local path to download to.
        filelock: Whether to require a file lock before downloading, useful for
            multiple downloads to the same directory that may be happening in parallel.

    Raises:
        FileNotFoundError: if (fs, fs_path) doesn't exist.
    rZ   r`   T)parentsexist_okz.lock)rV   N)ignore_errors)r   resolveexistsrd   mkdirparentr   osr)   normpathr_   rg   shutilrmtree)rZ   r`   rk   rl   _local_pathexists_beforees          r#   _download_from_fs_pathr}      s   B z""**,,K&&((MG,,, >$6666   ===
 	N!1!1*!=!=DDDEE R R&w
bQQQQR R R R R R R R R R R R R R R R R R #7J"MMMMMM    	:M*D9999	sB   <1C. -C C. CC. CC. C. .
D8DDr   r*   c                 z    |s%t          ||           t          | ||           dS t          | |||           dS )a]  Uploads a local directory or file to (fs, fs_path).

    NOTE: This will create all necessary parent directories at the destination.

    Args:
        local_path: The local path to upload.
        fs: The filesystem to upload to.
        fs_path: The filesystem path where the dir/file will be uploaded to.
        exclude: A list of filename matches to exclude from upload. This includes
            all files under subdirectories as well.
            This pattern will match with the relative paths of all files under
            `local_path`.
            Ex: ["*.png"] to exclude all .png images.
    rn   )rW   Nrk   rZ   r`   r   )_create_directoryr_   "_upload_to_uri_with_exclude_fsspecr   s       r#   _upload_to_fs_pathr      se    *   	R1111z72NNNN&"gw     r$   z
pyarrow.fsc                     t          | |          }t          j                            |          }t          j                            |          }t          ||           t          | |||           d S )N)r   r   rn   rU   )r   rY   rZ   FSSpecHandlerPyFileSystemr   r_   )rk   rZ   r`   r   local_fshandler	source_fss          r#   r   r      s~     ):wOOOHj&&x00G
''00IW----GyQS     r$   file_filterc                     d t           j                            dd          }fd|                     |          D             S )zReturns the list of filenames at (fs, fs_path), similar to os.listdir.

    If the path doesn't exist, returns an empty list.
    Nc                     dS )NTr   )xs    r#   <lambda>z"_list_at_fs_path.<locals>.<lambda>   s     r$   TF)allow_not_found	recursivec                     g | ]Y} |          t           j                            |j                            d                               d                     ZS )r,   )start)rv   r)   relpathlstrip)r0   	file_infor   r`   s     r#   rE   z$_list_at_fs_path.<locals>.<listcomp>   sg       ;y!!
	--c22'..:M:MNN  r$   )rY   rZ   FileSelectorget_file_info)rZ   r`   r   selectors    `` r#   _list_at_fs_pathr      sn     $nz&&wPU&VVH    ))(33   r$   c                 j    |                      |          }|j        t          j        j        j        k    S )z%Returns True if (fs, fs_path) exists.)r   typerY   rZ   FileTypeNotFound)rZ   r`   valids      r#   _exists_at_fs_pathr     s,     W%%E:,555r$   c                     |                      |          }|j        t          j        j        j        k    rt          d|  d| d          |j         S )z~Checks if (fs, fs_path) is a directory or a file.

    Raises:
        FileNotFoundError: if (fs, fs_path) doesn't exist.
    zPath not found: (rb   ))r   r   rY   rZ   r   r   FileNotFoundErroris_file)rZ   r`   r   s      r#   rd   rd   
  sZ       ))I~,555 DB D D' D D DEEE   r$   c                     	 |                      |           dS # t          $ r% t                              d|  d| d           Y dS w xY w)aW  Create directory at (fs, fs_path).

    Some external filesystems require directories to already exist, or at least
    the `netloc` to be created (e.g. PyArrows ``mock://`` filesystem).

    Generally this should be done before and outside of Ray applications. This
    utility is thus primarily used in testing, e.g. of ``mock://` URIs.
    z-Caught exception when creating directory at (rb   rc   N)
create_dirrg   rh   ri   rn   s     r#   r   r     sw    

g 
 
 
MBMM'MMM	
 	
 	
 	
 	
 	

s    +AAstorage_pathstorage_filesystemc                 t    t          |           } |r|| fS t          j        j                            |           S )a  Returns the fs and path from a storage path and an optional custom fs.

    Args:
        storage_path: A storage path or URI. (ex: s3://bucket/path or /tmp/ray_results)
        storage_filesystem: A custom filesystem to use. If not provided,
            this will be auto-resolved by pyarrow. If provided, the storage_path
            is assumed to be prefix-stripped already, and must be a valid path
            on the filesystem.
    )rM   rY   rZ   
FileSystemfrom_uri)r   r   s     r#   get_fs_and_pathr   )  s=     |$$L 0!<//: )),777r$   c                        e Zd ZdZded         f fdZ	 ddededee         d	ee	e
f         fd
Zdeded	ee	e
f         fdZded	ee	e
f         fdZ xZS )_FilesystemSyncerz;Syncer between local filesystem and a `storage_filesystem`.r   zpyarrow.fs.FileSystemc                 H    || _          t                      j        di | d S r   )r   r   r   )r    r   r!   r"   s      r#   r   z_FilesystemSyncer.__init__A  s.    "4""6"""""r$   Nrk   urir   r*   c                 D    |}t           t          || j        ||          fS )Nr   )r   dictr   )r    rk   r   r   r`   s        r#   _sync_up_commandz"_FilesystemSyncer._sync_up_commandE  s7    
 %*	  
 	
r$   c                 B    |}t           t          | j        ||          fS )N)rZ   r`   rk   )r}   r   r   )r    r   rk   r`   s       r#   _sync_down_commandz$_FilesystemSyncer._sync_down_commandU  s2    "*%  
 	
r$   c                 @    |}t           t          | j        |          fS )Nrn   )rj   r   r   )r    r   r`   s      r#   _delete_commandz!_FilesystemSyncer._delete_command`  s"    (? Q Q QQQr$   r.   )rI   rJ   rK   rL   r
   r   rM   r	   r   r   r   r   r   r   rP   rQ   s   @r#   r   r   >  s       EE#84K+L # # # # # #
 DH
 

$'
2:4.
	x~	
 
 
 
 	
c 	
s 	
uXt^?T 	
 	
 	
 	
R3 R54+@ R R R R R R R Rr$   r   c                      e Zd ZdZ	 	 	 	 d#deeej        f         dedee	         dee
j        j                 dee         d	efd
Zd Zd Zd ZdefdZd$dZd%deddfdZedefd            ZdefdZedefd            Zedefd            Zedefd            Zedefd            Zedefd            Zedefd            Ze deee!e"f         defd             Z#e d!efd"            Z$dS )&StorageContexta#  Shared context that holds the source of truth for all paths and
    storage utilities, passed along from the driver to workers.

    This object defines a few types of paths:
    1. *_fs_path: A path on the `storage_filesystem`. This is a regular path
        which has been prefix-stripped by pyarrow.fs.FileSystem.from_uri and
        can be joined with `Path(...).as_posix()`.
    2. *_driver_staging_path: The temporary staging directory on the local filesystem
        where driver artifacts are saved to before persisting them to storage.
    3. trial_working_directory: The local filesystem path that the remote
        actors' working directories are moved to by default.
        This is separated from the driver staging path so that driver syncing
        does not implicitly upload the trial working directory, for trials on the
        driver node.

    Example with storage_path="mock:///bucket/path?param=1":

        >>> import ray
        >>> from ray.train._internal.storage import StorageContext
        >>> import os
        >>> _ = ray.init()
        >>> storage = StorageContext(
        ...     storage_path="mock://netloc/bucket/path?param=1",
        ...     experiment_dir_name="exp_name",
        ... )
        >>> storage.storage_filesystem   # Auto-resolved  # doctest: +ELLIPSIS
        <pyarrow._fs._MockFileSystem object...
        >>> storage.experiment_fs_path
        'bucket/path/exp_name'
        >>> storage.experiment_driver_staging_path  # doctest: +ELLIPSIS
        '/tmp/ray/session_.../artifacts/.../exp_name/driver_artifacts'
        >>> storage.trial_dir_name = "trial_dir"
        >>> storage.trial_fs_path
        'bucket/path/exp_name/trial_dir'
        >>> storage.trial_driver_staging_path  # doctest: +ELLIPSIS
        '/tmp/ray/session_.../artifacts/.../exp_name/driver_artifacts/trial_dir'
        >>> storage.trial_working_directory   # doctest: +ELLIPSIS
        '/tmp/ray/session_.../artifacts/.../exp_name/working_dirs/trial_dir'
        >>> storage.current_checkpoint_index = 1
        >>> storage.checkpoint_fs_path
        'bucket/path/exp_name/trial_dir/checkpoint_000001'
        >>> ray.shutdown()

    Example with storage_path="/tmp/ray_results":

        >>> from ray.train._internal.storage import StorageContext
        >>> storage = StorageContext(
        ...     storage_path="/tmp/ray_results",
        ...     experiment_dir_name="exp_name",
        ... )
        >>> storage.storage_fs_path
        '/tmp/ray_results'
        >>> storage.experiment_fs_path
        '/tmp/ray_results/exp_name'
        >>> storage.storage_filesystem   # Auto-resolved  # doctest: +ELLIPSIS
        <pyarrow._fs.LocalFileSystem object...

    Internal Usage Examples:
    - To copy files to the trial directory on the storage filesystem:

        pyarrow.fs.copy_files(
            local_dir,
            Path(storage.trial_fs_path, "subdir").as_posix(),
            destination_filesystem=storage.filesystem
        )

    .. warning::
        This is an experimental developer API and is subject to change
        without notice between versions.
    Nr   experiment_dir_namesync_configr   trial_dir_namecurrent_checkpoint_indexc                    ddl m} |d u| _        || _        || _        || _        |pt                      | _        t          ||          \  | _	        | _
        t          | j
                                                  | _
        t          | j	        | j        j        | j        j                  | _        |                                  |                                   |            | _        d S )Nr   date_str)r   sync_periodsync_timeout)ray.tune.utilsr   custom_fs_providedr   r   r   r   r   r   r   storage_fs_pathr   r5   r   r   r   syncer_create_validation_file_check_validation_file
_timestamp)r    r   r   r   r   r   r   r   s           r#   r   zStorageContext.__init__  s     	,+++++"4D"@ $7 ,(@%&6*,,8G,9
 9
5!5  $D$899BBDD/#6(4)6
 
 
 	$$&&&##%%% #(**r$   c                 b    d| j         j         d| j         d| j         d| j         d| j         dS )Nz&StorageContext<
  storage_filesystem='z',
  storage_fs_path='z',
  experiment_dir_name='z',
  trial_dir_name='z',
  current_checkpoint_index=z,
>)r   	type_namer   r   r   r   r'   s    r#   __str__zStorageContext.__str__  sj    %)%<%F "&"6  '+&>  "&!4	 
 +/*G  	
r$   c                    t          | j        t                                                    }| j                            | j                   | j                            |          5  	 ddd           dS # 1 swxY w Y   dS )a  On the creation of a storage context, create a validation file at the
        storage path to verify that the storage path can be written to.
        This validation file is also used to check whether the storage path is
        accessible by all nodes in the cluster.N)r   experiment_fs_path!_VALIDATE_STORAGE_MARKER_FILENAMEr5   r   r   open_output_streamr    
valid_files     r#   r   z&StorageContext._create_validation_file  s    
 #%F
 

(** 	 	**4+BCCC$77
CC 	 		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   &A55A9<A9c                     t          | j        t                                                    }t	          | j        |          st          d|  d          dS )z;Checks that the validation file exists at the storage path.rn   z>Unable to set up cluster storage with the following settings:
a  
Check that all nodes in the cluster have read/write access to the configured storage path. `RunConfig(storage_path)` should be set to a cloud storage URI or a shared filesystem path accessible by all nodes in your cluster ('s3://bucket' or '/mnt/nfs'). A local path on the head node is not accessible by worker nodes. See: https://docs.ray.io/en/latest/train/user-guides/persistent-storage.htmlN)r   r   r   r5   r   r   RuntimeErrorr   s     r#   r   z%StorageContext._check_validation_file  sw    #%F
 

(** 	 "T%<jQQQ 		_RV _ _ _  		 		r$   metricsc                 &    | xj         dz  c_         d S )N   )r   )r    r   s     r#   _update_checkpoint_indexz'StorageContext._update_checkpoint_index  s     	%%*%%%%r$   
checkpointr   r*   c                    t                               d                    |j        | j        |j        | j                             |                                  | j                            | j                   t          |j        | j        |j        | j                   |
                    | j        | j                  }t                               d|            |S )ap  Persists a given checkpoint to the current checkpoint path on the filesystem.

        "Current" is defined by the `current_checkpoint_index` attribute of the
        storage context.

        This method copies the checkpoint files to the storage location.
        It's up to the user to delete the original checkpoint files if desired.

        For example, the original directory is typically a local temp directory.

        Args:
            checkpoint: The checkpoint to persist to (fs, checkpoint_fs_path).

        Returns:
            Checkpoint: A Checkpoint pointing to the persisted checkpoint location.
        z_Copying checkpoint files to storage path:
({source_fs}, {source}) -> ({dest_fs}, {destination}))r]   r^   r   dest_fs)r]   r^   rV   rW   )
filesystemr)   z$Checkpoint successfully created at: )rh   debugformatr)   checkpoint_fs_pathr   r   r   r   r_   r"   info)r    r   persisted_checkpoints      r#   persist_current_checkpointz)StorageContext.persist_current_checkpoint  s    & 	DDJF! 3$//	 EK E E	
 	
 	
 	##%%%**4+BCCC?/(3#'#:		
 	
 	
 	
  *33.(  4  
  
 	Q;OQQRRR##r$   Fforcec                 |   | j         j        sdS t          t          j        | j                             }|rdS |rZ| j                                         | j                            | j        | j	                   | j                                         dS | j        
                    | j        | j	                   dS )aP  Persists all artifacts within `trial_local_dir` to storage.

        This method possibly launches a background task to sync the trial dir,
        depending on the `sync_period` + `sync_artifacts_on_checkpoint`
        settings of `SyncConfig`.

        `(local_fs, trial_working_dir) -> (storage_filesystem, trial_fs_path)`

        Args:
            force: If True, wait for a previous sync to finish, launch a new one,
                and wait for that one to finish. By the end of a `force=True` call, the
                latest version of the trial artifacts will be persisted.
        N)	local_dir
remote_dir)r   sync_artifactsr8   rv   scandirtrial_working_directoryr   waitsync_uptrial_fs_pathsync_up_if_needed)r    r   is_emptys      r#   persist_artifactsz StorageContext.persist_artifacts4  s     . 	F 2:d&BCCDDD 	F 		KK64CU      KK))64CU *     r$   c                 Z    t          | j        | j                                                  S )a  The path on the `storage_filesystem` to the experiment directory.

        NOTE: This does not have a URI prefix anymore, since it has been stripped
        by pyarrow.fs.FileSystem.from_uri already. The URI scheme information is
        kept in `storage_filesystem` instead.
        )r   r   r   r5   r'   s    r#   r   z!StorageContext.experiment_fs_pathU  s&     D($*BCCLLNNNr$   c                 t    t          t                      | j        | j                                                  S )zsThe Ray Train/Tune session local directory used to stage files
        before persisting to the storage filesystem.)r   r   r   r   r5   r'   s    r#   _get_session_pathz StorageContext._get_session_path_  s1     &(($/4;S
 

(**	r$   c                 j    t          |                                 d                                          S )a   The local filesystem path of the experiment directory on the driver node.

        The driver is the node where `Trainer.fit`/`Tuner.fit` is being called.

        This path is of the form:
        `/tmp/ray/session_<session_id>/artifacts/<ray-train-job-timestamp>/
        <experiment_dir_name>/driver_artifacts`

        This should be used as the temporary staging location for files *on the driver*
        before syncing them to `experiment_fs_path`.
        For example, the search algorithm should dump its state to this directory.
        See `trial_driver_staging_path` for writing trial-specific artifacts.

        The directory is synced to
        `{storage_path}/{experiment_dir_name}` periodically.
        See `_ExperimentCheckpointManager.checkpoint` for where that happens.
        driver_artifacts)r   r   r5   r'   s    r#   experiment_driver_staging_pathz-StorageContext.experiment_driver_staging_pathf  s-    & D**,,.@AAJJLLLr$   c                     | j         t          d          t          | j        | j                                                   S )zThe trial directory path on the `storage_filesystem`.

        Raises a ValueError if `trial_dir_name` is not set beforehand.
        NzBShould not access `trial_fs_path` without setting `trial_dir_name`)r   r   r   r   r5   r'   s    r#   r   zStorageContext.trial_fs_path{  sF     &T   D+T-@AAJJLLLr$   c                     | j         t          d          t          | j        | j                                                   S )aJ  The local filesystem path of the trial directory on the driver.

        The driver is the node where `Trainer.fit`/`Tuner.fit` is being called.

        This path is of the form:
        `/tmp/ray/session_<session_id>/artifacts/<ray-train-job-timestamp>/
        <experiment_dir_name>/driver_artifacts/<trial_dir_name>`

        This should be used as the temporary location for files on the driver
        before persisting them to `trial_fs_path`.

        For example, callbacks (e.g., JsonLoggerCallback) should write trial-specific
        logfiles within this directory.
        NzNShould not access `trial_driver_staging_path` without setting `trial_dir_name`)r   r   r   r   r5   r'   s    r#   trial_driver_staging_pathz(StorageContext.trial_driver_staging_path  sH      &3   D79LMMVVXXXr$   c                     | j         t          d          t          |                                 d| j                                                   S )a  The local filesystem path to trial working directory.

        This path is of the form:
        `/tmp/ray/session_<session_id>/artifacts/<ray-train-job-timestamp>/
        <experiment_dir_name>/working_dirs/<trial_dir_name>`

        Ray Train/Tune moves the remote actor's working directory to this path
        by default, unless disabled by `RAY_CHDIR_TO_TRIAL_DIR` environment variable.

        Writing files to this directory allows users to persist training artifacts
        if `SyncConfig(sync_artifacts=True)` is set.
        NzHCannot access `trial_working_directory` without setting `trial_dir_name`working_dirs)r   r   r   r   r5   r'   s    r#   r   z&StorageContext.trial_working_directory  sW     &+   ""$$nd6I
 

(**	r$   c                 Z    t          | j        | j                                                  S )a%  The current checkpoint directory path on the `storage_filesystem`.

        "Current" refers to the checkpoint that is currently being created/persisted.
        The user of this class is responsible for setting the `current_checkpoint_index`
        (e.g., incrementing when needed).
        )r   r   checkpoint_dir_namer5   r'   s    r#   r   z!StorageContext.checkpoint_fs_path  s&     D&(@AAJJLLLr$   c                 @    t                               | j                  S )zEThe current checkpoint directory name, based on the checkpoint index.)r   _make_checkpoint_dir_namer   r'   s    r#   r   z"StorageContext.checkpoint_dir_name  s     778UVVVr$   run_objc                     ddl m} ddlm} |                    |           }t          t          t          j        	                    dd                              r|}nd
                    | |                      }|S )Nr   )
Experimentr   TUNE_DISABLE_DATED_SUBDIRz{}_{})ray.tune.experimentr   r   r   get_trainable_namerO   intrv   environgetr   )r   r   r   run_identifierdir_names        r#   get_experiment_dir_namez&StorageContext.get_experiment_dir_name  s    222222++++++#66w??BJNN#>BBCCDD 	B%HH~~nhhjjAAHr$   indexc                     d| dS )z9Get the name of the checkpoint directory, given an index.checkpoint_06dr   )r
  s    r#   r   z(StorageContext._make_checkpoint_dir_name  s     )U((((r$   )NNNr   )r   r   r*   r   )F)%rI   rJ   rK   rL   r   rM   rv   PathLiker
   r   rY   rZ   r   r  r   r   r   r   r   r   r   rO   r   rN   r   r   r   r   r   r   r   r   staticmethodr   r   r	  r   r   r$   r#   r   r   e  s       E EV -1>B(,(*&% &%C,-&% !&% j)	&%
 %WZ%:;&% !&% #&&% &% &% &%P	
 	
 	

 
 
   + + + + +
0$ 0$ 0$ 0$d t     B OC O O O XO3     M M M M XM( 	Ms 	M 	M 	M X	M Y3 Y Y Y XY,     X, MC M M M XM WS W W W XW 
sHd/B)C 
 
 
 
 \
 ) ) ) ) \) ) )r$   r   )NN)Tr.   )<fsspecfsspec.implementations.localr   ImportErrorModuleNotFoundErrorr|   r   rY   
pyarrow.fsr   r/   loggingrv   rx   pathlibr   typingr   r   r   r	   r
   r   r   r   ray.air._internal.filelockr   ray.train._internal.syncerr   r   r   ray.train.constantsr   ray.util.annotationsr   ray.train._checkpointr   	getLoggerrI   rh   r   r   r_   rZ   r   rM   rj   rO   r}   r   r   FileInfor   r   rd   r   r  r   r   r   r   r$   r#   <module>r     s1  MMM<<<<<<<()   
,	4  NNN()   
,	5  '''''''   LLL   				        T T T T T T T T T T T T T T T T T T T T 3 3 3 3 3 3 L L L L L L L L L L : : : : : : - - - - - - 1000000 
	8	$	$ %? !1N 1N 1N 1N 1N 1N 1N 1Nj IM   0	W
- 	W 	W 	W 	W 	W  	2 2
22 2 	2 2 2 2r $(	 
  d3i 	
 
   B

%
03
>FtCy>Q
	
 
 
 
  DH 
 (GJ$7#8$#>?@ 
#Y	   (67:0 63 64 6 6 6 6!gj+ !c !d ! ! ! !
'*/ 
# 
$ 
 
 
 
& ;?8 8R[()8 !678 7: #%&8 8 8 8*$R $R $R $R $R) $R $R $RN n) n) n) n) n) n) n) n) n) n)s6   
 % %2 A
AA
A AA