
    -ji                        % S SK Jr  S SKrS SKrS SKJr  S SKJr  \R                  " \	5      r
\(       a  S SKJr  S SKJr   " S S5      r\(       a  S S	KJr  \" \" S
5      5      rS\S'   gg)    )annotationsN)TYPE_CHECKING)ArtifactNotFound)BinaryIO)ArtifactStorec                  n    \ rS rSrSrSSSSS.           SS jjrSS	 jrSS
 jrSS jrSS jr	Sr
g)Backoff   a  An artifact store's middleware for exponential backoff.

Example:
   .. code-block:: python

       import optuna
       from optuna.artifacts import upload_artifact
       from optuna.artifacts import Boto3ArtifactStore
       from optuna.artifacts import Backoff


       artifact_store = Backoff(Boto3ArtifactStore("my-bucket"))


       def objective(trial: optuna.Trial) -> float:
           ... = trial.suggest_float("x", -10, 10)
           file_path = generate_example(...)
           upload_artifact(
               artifact_store=artifact_store,
               file_path=file_path,
               study_or_trial=trial,
           )
           return ...

      g?   )max_retries
multiplier	min_delay	max_delayc               ~    Xl         US:  d   eUS:  d   eUS:  d   eXT:  d   eX l        X0l        X@l        XPl        g )Nr   )_backend_max_retries_multiplier
_min_delay
_max_delay)selfbackendr   r   r   r   s         S/home/james-whalen/.local/lib/python3.13/site-packages/optuna/artifacts/_backoff.py__init__Backoff.__init__-   sO      QA~~1}}$$$'%##    c                b    [        U R                  U R                  U-  -  U R                  5      $ )N)minr   r   r   )r   n_retrys     r   _get_sleep_secsBackoff._get_sleep_secsB   s'    4??T%5%5w%>>PPr   c                j   [        U R                  5       H  n U R                  R                  U5      s  $     S5       e! [         a    e [
         a7  nX R                  S-
  :X  a  e [        R                  SU SU 3US9   S nAOS nAff = f[        R                  " U R                  U5      5        M  )N   Failed to open artifact=	 n_retry=exc_infozmust not reach here)ranger   r   open_readerr   	Exception_loggererrortimesleepr!   r   artifact_idies       r   r*   Backoff.open_readerE   s    t(()Ad}}00== * 	,++u $  d))A--MM$<[MSTRU"VabMc	d
 JJt++A./s   A  B-BBc                   [        U R                  5       H  n U R                  R                  X5          g    g ! [         a    e [
         a7  nX0R                  S-
  :X  a  e [        R                  SU SU 3US9   S nAOS nAff = fUR                  S5        [        R                  " U R                  U5      5        M  )Nr$   r%   r&   r'   r   )r)   r   r   writer   r+   r,   r-   seekr.   r/   r!   )r   r1   content_bodyr2   r3   s        r   r6   Backoff.writeS   s    t(()A	d##K> * $  d))A--MM$<[MSTRU"VabMc	d
 a JJt++A./s   :B-B  Bc                T   [        U R                  5       HD  n U R                  R                  U5        [        R                  " U R                  U5      5        MF     g ! [         a    e [
         a4  nX R                  S-
  :X  a  e [        R                  SU 3US9   S nANmS nAff = f)Nr$   zFailed to delete artifact=r'   )r)   r   r   remover   r+   r,   r-   r.   r/   r!   r0   s       r   r;   Backoff.removeb   s    t(()AZ$$[1 JJt++A./ * $  Z))A--MM$>{m"LWXMY	Zs   AB'3*B""B')r   r   r   r   r   N)r   r   r   intr   floatr   r>   r   r>   returnNone)r    r=   r?   r>   )r1   strr?   r   )r1   rA   r8   r   r?   r@   )r1   rA   r?   r@   )__name__
__module____qualname____firstlineno____doc__r   r!   r*   r6   r;   __static_attributes__ r   r   r	   r	      si    : $$ 	$
 $ $ $ 
$*Q,00r   r	   )FileSystemArtifactStore.r   _)
__future__r   loggingr.   typingr   optuna.artifacts.exceptionsr   	getLoggerrB   r,   r   optuna.artifacts._protocolr   r	   optuna.artifactsrI   rK   __annotations__rH   r   r   <module>rT      sb    "     8 

H
% 8Z0 Z0z  96s;<A}< r   