Ë
    þÍ:j  ã                  óÀ   — d dl mZ d dlmZ d dlmZ d dlZd dlmZ d dlm	Z	 d dlm
Z
 erd dlmZ  e	d	«       G d
„ d«      «       Z eddd¬«       G d„ de«      «       Zy)é    )Úannotations)ÚAny)ÚTYPE_CHECKINGN)Údeprecated_class)Úexperimental_class)Úexperimental_func)ÚFrozenTrialú2.8.0c                  ó~   — e Zd ZdZ	 d		 	 	 	 	 d
d„Zdd„Ze ed«      dd„«       «       Ze ed«      dd„«       «       Z	y)Ú RetryHeartbeatStaleTrialCallbackaÐ  Retry a heartbeat-stale trial up to a maximum number of times.

    When a running trial becomes stale due to the heartbeat mechanism, this callback can be
    used with a class in :mod:`optuna.storages` to recreate the trial in ``TrialState.WAITING``
    to queue up the trial to be run again.

    The original stale trial can be identified by the
    :func:`~optuna.storages.RetryHeartbeatStaleTrialCallback.retried_trial_number` function.
    Even if repetitive failure occurs (a retried trial becomes stale again), this method returns
    the number of the original trial. To get a full list including the numbers of the retried
    trials as well as their original trial, call the
    :func:`~optuna.storages.RetryHeartbeatStaleTrialCallback.retry_history` function.

    This callback is helpful in environments where running trials may become stale due to external
    conditions, such as worker preemption or unexpected process termination.

    Usage:

        .. testcode::

            import optuna
            from optuna.storages import RetryHeartbeatStaleTrialCallback

            storage = optuna.storages.RDBStorage(
                url="sqlite:///:memory:",
                heartbeat_interval=60,
                grace_period=120,
                heartbeat_stale_trial_callback=RetryHeartbeatStaleTrialCallback(max_retry=3),
            )

            study = optuna.create_study(
                storage=storage,
            )

    .. seealso::
        See :class:`~optuna.storages.RDBStorage`.

    Args:
        max_retry:
            The max number of times a trial can be retried. Must be set to :obj:`None` or an
            integer. If set to the default value of :obj:`None` will retry indefinitely.
            If set to an integer, will only retry that many times.
        inherit_intermediate_values:
            Option to inherit `trial.intermediate_values` reported by
            :func:`optuna.trial.Trial.report` from the failed trial. Default is :obj:`False`.
    Nc                ó    — || _         || _        y )N)Ú
_max_retryÚ_inherit_intermediate_values)ÚselfÚ	max_retryÚinherit_intermediate_valuess      úo/home/mcse/projects/srt_converter/srt-converter-venv/lib/python3.12/site-packages/optuna/storages/_callbacks.pyÚ__init__z)RetryHeartbeatStaleTrialCallback.__init__A   s   € ð $ˆŒØ,GˆÕ)ó    c           
     óÊ  — |j                   g dœ|j                  ¥}|d   j                  |j                   «       | j                  �| j                  t	        |d   «      k  ry |j                  t        j                  t        j                  j                  j                  |j                  |j                  |j                  || j                  r|j                  nd ¬«      «       y )N)Úfailed_trialÚretry_historyr   )ÚstateÚparamsÚdistributionsÚ
user_attrsÚsystem_attrsÚintermediate_values)Únumberr   Úappendr   ÚlenÚ	add_trialÚoptunaÚcreate_trialÚtrialÚ
TrialStateÚWAITINGr   r   r   r   r   )r   Ústudyr%   r   s       r   Ú__call__z)RetryHeartbeatStaleTrialCallback.__call__G   s¼   € à!ŸL™LØñ(
ð × Ñ ð(
ˆð
 	�_Ñ%×,Ñ,¨U¯\©\Ô:Ø�?‰?Ð&Ø�‰¤ \°/Ñ%BÓ!CÒCØà�‰Ü×ÑÜ—l‘l×-Ñ-×5Ñ5Ø—|‘|Ø#×1Ñ1Ø ×+Ñ+Ø)à15×1RÒ1R�E×-Ò-ÐX\ô	õ	
r   r
   c                ó:   — | j                   j                  dd«      S )a
  Return the number of the original trial being retried.

        Args:
            trial:
                The trial object.

        Returns:
            The number of the first failed trial. If not retry of a previous trial,
            returns :obj:`None`.
        r   N©r   Úget©r%   s    r   Úretried_trial_numberz5RetryHeartbeatStaleTrialCallback.retried_trial_number_   s   € ð ×!Ñ!×%Ñ% n°dÓ;Ð;r   z3.0.0c                ó:   — | j                   j                  dg «      S )at  Return the list of retried trial numbers with respect to the specified trial.

        Args:
            trial:
                The trial object.

        Returns:
            A list of trial numbers in ascending order of the series of retried trials.
            The first item of the list indicates the original trial which is identical
            to the :func:`~optuna.storages.RetryHeartbeatStaleTrialCallback.retried_trial_number`,
            and the last item is the one right before the specified trial in the retry series.
            If the specified trial is not a retry of any trial, returns an empty list.
        r   r+   r-   s    r   r   z.RetryHeartbeatStaleTrialCallback.retry_historyo   s   € ð  ×!Ñ!×%Ñ% o°rÓ:Ð:r   )NF)r   ú
int | Noner   ÚboolÚreturnÚNone)r(   z'optuna.study.Study'r%   r	   r2   r3   )r%   r	   r2   r0   )r%   r	   r2   z	list[int])
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r)   Ústaticmethodr   r.   r   © r   r   r   r      sw   „ ñ-ð` QVðHØ#ðHØIMðHà	óHó
ð0 Ù�wÓò<ó  ó ð<ð Ù�wÓò;ó  ó ñ;r   r   z4.9.0z6.0.0z/Use `RetryHeartbeatStaleTrialCallback` instead.)Útextc                  ó   — e Zd ZdZy)ÚRetryFailedTrialCallbackz•Deprecated alias of :class:`~optuna.storages.RetryHeartbeatStaleTrialCallback`.

    Deprecated in v4.9.0. This class will be removed in v6.0.0.
    N)r4   r5   r6   r7   r9   r   r   r<   r<   ‚   s   „ ñð
 	r   r<   )Ú
__future__r   Útypingr   r   r#   Úoptuna._deprecatedr   Úoptuna._experimentalr   r   Úoptuna.trialr	   r   r<   r9   r   r   ú<module>rB      sn   ðÝ "å Ý  ã Ý /Ý 3Ý 2ñ Ý(ñ �GÓ÷n;ð n;ó ðn;ñb ØØØ	:ôô
	Ð?ó 	óñ
	r   