
    (^iO              	         d dl mZ d dlmZ d dlmZ d dlZd dlZd dlmZ 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 d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dl m!Z!  ejD                  e#      Z$dZ% G d de      Z&e!jN                  dddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ(y)    )annotations)Mapping)SequenceN)Any)cast)Dict)overload)distributions)logging)convert_positional_args)deprecated_func)JSONSerializable)-_convert_old_distribution_to_new_distribution)BaseDistribution)CategoricalChoiceType)CategoricalDistribution)FloatDistribution)IntDistribution)_SUGGEST_INT_POSITIONAL_ARGS)	BaseTrial)
TrialStatez Use suggest_float{args} instead.c                  N   e Zd ZdZdd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d<dZd=dZd=dZd=dZd>dZd?d	Z	dd
d	 	 	 	 	 	 	 	 	 	 	 d@dZ
 eddej                  d            dAd       Z eddej                  d            dAd       Z eddej                  d            dBd       Z eedd      dd
d	 	 	 	 	 	 	 	 	 	 	 dCd       ZedDd       ZedEd       ZedFd       ZedGd       ZedHd        Ze	 	 	 	 	 	 dId!       Z	 	 	 	 	 	 dId"ZdJd#ZdKd$ZdLd%Z ed&d      dLd'       ZdMd(ZdNd)Zed>d*       Zej<                  dOd+       ZedPd,       Zej<                  dQd-       ZdRd.Z dSd/Z! ee e!      Z"edTd0       Z#e#j<                  dUd1       Z#edVd2       Z$e$j<                  dWd3       Z$edXd4       Z%e%j<                  dYd5       Z%edVd6       Z&e&j<                  dZd7       Z&edVd8       Z'e'j<                  d[d9       Z'ed\d:       Z(ed]d;       Z)y)^FrozenTriala  Status and results of a :class:`~optuna.trial.Trial`.

    An object of this class has the same methods as :class:`~optuna.trial.Trial`, but is not
    associated with, nor has any references to a :class:`~optuna.study.Study`.

    It is therefore not possible to make persistent changes to a storage from this object by
    itself, for instance by using :func:`~optuna.trial.FrozenTrial.set_user_attr`.

    It will suggest the parameter values stored in :attr:`params` and will not sample values from
    any distributions.

    It can be passed to objective functions (see :func:`~optuna.study.Study.optimize`) and is
    useful for deploying optimization results.

    Example:

        Re-evaluate an objective function with parameter values optimized study.

        .. testcode::

            import optuna


            def objective(trial):
                x = trial.suggest_float("x", -1, 1)
                return x**2


            study = optuna.create_study()
            study.optimize(objective, n_trials=3)

            assert objective(study.best_trial) == study.best_value

    .. note::
        Instances are mutable, despite the name.
        For instance, :func:`~optuna.trial.FrozenTrial.set_user_attr` will update user attributes
        of objects in-place.


        Example:

            Overwritten attributes.

            .. testcode::

                import copy
                import datetime

                import optuna


                def objective(trial):
                    x = trial.suggest_float("x", -1, 1)

                    # this user attribute always differs
                    trial.set_user_attr("evaluation time", datetime.datetime.now())

                    return x**2


                study = optuna.create_study()
                study.optimize(objective, n_trials=3)

                best_trial = study.best_trial
                best_trial_copy = copy.deepcopy(best_trial)

                # re-evaluate
                objective(best_trial)

                # the user attribute is overwritten by re-evaluation
                assert best_trial.user_attrs != best_trial_copy.user_attrs

    .. note::
        Please refer to :class:`~optuna.trial.Trial` for details of methods and properties.


    Attributes:
        number:
            Unique and consecutive number of :class:`~optuna.trial.Trial` for each
            :class:`~optuna.study.Study`. Note that this field uses zero-based numbering.
        state:
            :class:`TrialState` of the :class:`~optuna.trial.Trial`.
        value:
            Objective value of the :class:`~optuna.trial.Trial`.
            ``value`` and ``values`` must not be specified at the same time.
        values:
            Sequence of objective values of the :class:`~optuna.trial.Trial`.
            The length is greater than 1 if the problem is multi-objective optimization.
            ``value`` and ``values`` must not be specified at the same time.
        datetime_start:
            Datetime where the :class:`~optuna.trial.Trial` started.
        datetime_complete:
            Datetime where the :class:`~optuna.trial.Trial` finished.
        params:
            Dictionary that contains suggested parameters.
        distributions:
            Dictionary that contains the distributions of :attr:`params`.
        user_attrs:
            Dictionary that contains the attributes of the :class:`~optuna.trial.Trial` set with
            :func:`optuna.trial.Trial.set_user_attr`.
        system_attrs:
            Dictionary that contains the attributes of the :class:`~optuna.trial.Trial` set with
            :func:`optuna.trial.Trial.set_system_attr`.
        intermediate_values:
            Intermediate objective values set with :func:`optuna.trial.Trial.report`.
    N)valuesc                   || _         || _        d | _        ||t        d      |	|g| _        n|t	        |      | _        || _        || _        || _        || _        |	| _	        |
| _
        || _        || _        y )Nz)Specify only one of `value` and `values`.)_numberstate_values
ValueErrorlist_datetime_startdatetime_complete_params_user_attrs_system_attrsintermediate_values_distributions	_trial_id)selfnumberr   valuedatetime_startr"   paramsr
   
user_attrssystem_attrsr&   trial_idr   s                U/var/www/html/hubwallet-dev/venv/lib/python3.12/site-packages/optuna/trial/_frozen.py__init__zFrozenTrial.__init__   s      
+/!3HII!7DL<DL-!2%)#6 +!    c                `    t        |t              st        S |j                  | j                  k(  S N)
isinstancer   NotImplemented__dict__r)   others     r1   __eq__zFrozenTrial.__eq__   s%    %-!!~~..r3   c                `    t        |t              st        S | j                  |j                  k  S r5   r6   r   r7   r*   r9   s     r1   __lt__zFrozenTrial.__lt__   s%    %-!!{{U\\))r3   c                `    t        |t              st        S | j                  |j                  k  S r5   r=   r9   s     r1   __le__zFrozenTrial.__le__   s%    %-!!{{ell**r3   c                R     t        t         fd j                  D                    S )Nc              3  6   K   | ]  }t        |        y wr5   )getattr.0fieldr)   s     r1   	<genexpr>z'FrozenTrial.__hash__.<locals>.<genexpr>   s     J5'$.Js   )hashtupler8   r)   s   `r1   __hash__zFrozenTrial.__hash__   s    EJDMMJJKKr3   c                     dj                   j                  j                  dj                   fd j                  D              dz         S )Nz{cls}({kwargs})z, c           
   3     K   | ]@  }d j                  |j                  d      s|n|dd t        t        |                   B yw)z{field}={value}_   N)rF   r+   )format
startswithreprrC   rD   s     r1   rG   z'FrozenTrial.__repr__.<locals>.<genexpr>   sR      
 	 "((','7'7'<%%)wtU34 ) s   AA	z, value=None)clskwargs)rP   	__class____name__joinr8   rJ   s   `r1   __repr__zFrozenTrial.__repr__   sQ     ''''99 
 "]]   ( 

 
	
r3   F)steplogc          	     @    | j                  |t        ||||            S N)rZ   rY   )_suggestr   r)   namelowhighrY   rZ   s         r1   suggest_floatzFrozenTrial.suggest_float   s!     }}T#4S$Cd#STTr3   z3.0.0z6.0.0 )args)textc                (    | j                  |||      S r5   rb   r)   r_   r`   ra   s       r1   suggest_uniformzFrozenTrial.suggest_uniform   s    !!$T22r3   z(..., log=True)c                ,    | j                  |||d      S )NT)rZ   rg   rh   s       r1   suggest_loguniformzFrozenTrial.suggest_loguniform   s    !!$Tt!<<r3   z(..., step=...)c                ,    | j                  ||||      S )N)rY   rg   )r)   r_   r`   ra   qs        r1   suggest_discrete_uniformz$FrozenTrial.suggest_discrete_uniform   s    !!$T!::r3   z3.5.0z5.0.0)previous_positional_arg_namesdeprecated_versionremoved_versionrO   c               R    t        | j                  |t        ||||                  S r\   )intr]   r   r^   s         r1   suggest_intzFrozenTrial.suggest_int   s&     4==sDcPT'UVWWr3   c                     y r5    r)   r_   choicess      r1   suggest_categoricalzFrozenTrial.suggest_categorical       ORr3   c                     y r5   rv   rw   s      r1   ry   zFrozenTrial.suggest_categorical   rz   r3   c                     y r5   rv   rw   s      r1   ry   zFrozenTrial.suggest_categorical       MPr3   c                     y r5   rv   rw   s      r1   ry   zFrozenTrial.suggest_categorical   s    QTr3   c                     y r5   rv   rw   s      r1   ry   zFrozenTrial.suggest_categorical   r}   r3   c                     y r5   rv   rw   s      r1   ry   zFrozenTrial.suggest_categorical   s     !$r3   c                :    | j                  |t        |            S )N)rx   )r]   r   rw   s      r1   ry   zFrozenTrial.suggest_categorical  s     }}T#:7#KLLr3   c                     y)a  Interface of report function.

        Since :class:`~optuna.trial.FrozenTrial` is not pruned,
        this report function does nothing.

        .. seealso::
            Please refer to :func:`~optuna.trial.FrozenTrial.should_prune`.

        Args:
            value:
                A value returned from the objective function.
            step:
                Step of the trial (e.g., Epoch of neural network training). Note that pruners
                assume that ``step`` starts at zero. For example,
                :class:`~optuna.pruners.MedianPruner` simply checks if ``step`` is less than
                ``n_warmup_steps`` as the warmup mechanism.
        Nrv   )r)   r+   rY   s      r1   reportzFrozenTrial.report
  s    & 	r3   c                     y)a'  Suggest whether the trial should be pruned or not.

        The suggestion is always :obj:`False` regardless of a pruning algorithm.

        .. note::
            :class:`~optuna.trial.FrozenTrial` only samples one combination of parameters.

        Returns:
            :obj:`False`.
        Frv   rJ   s    r1   should_prunezFrozenTrial.should_prune  s     r3   c                "    || j                   |<   y r5   r$   r)   keyr+   s      r1   set_user_attrzFrozenTrial.set_user_attr-  s     %r3   z3.1.0c                "    || j                   |<   y r5   r%   r   s      r1   set_system_attrzFrozenTrial.set_system_attr0  s    "'3r3   c           	     \   | j                   t        j                  k7  r| j                  t	        d      | j                   j                         r| j                  "t	        d      | j                  t	        d      | j                   t        j                  k(  r%| j                  t	        d| j                   d      | j                   t        j                  k(  r>| j                  t	        d      t        d | j                  D              rt	        d      t        | j                  j                               t        | j                  j                               k7  r]t	        d	j                  t        | j                  j                               t        | j                  j                                           | j                  j!                         D ]R  \  }}| j                  |   }|j#                  |      }|j%                  |      r8t	        d
j                  |||             y )NzK`datetime_start` is supposed to be set when the trial state is not waiting.z?`datetime_complete` is supposed to be set for a finished trial.zC`datetime_complete` is supposed to be None for an unfinished trial.z2values should be None for a failed trial, but got .z*values should be set for a complete trial.c              3  F   K   | ]  }t        j                  |        y wr5   )mathisnan)rE   xs     r1   rG   z(FrozenTrial._validate.<locals>.<genexpr>H  s     9qTZZ]9s   !zvalues should not contain NaN.z0Inconsistent parameters {} and distributions {}.zFThe value {} of parameter '{}' isn't contained in the distribution {}.)r   r   WAITINGr,   r   is_finishedr"   FAILr   COMPLETEanysetr-   keysr
   rP   itemsto_internal_repr	_contains)r)   
param_nameparam_valuedistributionparam_value_in_internal_reprs        r1   	_validatezFrozenTrial._validate4  s   ::+++0C0C0K]  ::!!#%%- !bcc%%1 Y  ::(T\\-EQRVR^R^Q__`abb::,,,||# !MNN9DLL99 !ABBt{{!"c$*<*<*A*A*C&DDBII((*+S1C1C1H1H1J-K  (,{{'8'8': 	#J--j9L+7+H+H+U())*FG  &j,G 	r3   c                   || j                   vrt        dj                  |            | j                   |   }|j                  |      }|j	                  |      s&t        j                  dj                  |||             || j                  v r#t        j                  | j                  |   |       || j                  |<   |S )NzjThe value of the parameter '{}' is not found. Please set it at the construction of the FrozenTrial object.zNThe value {} of the parameter '{}' is out of the range of the distribution {}.)
r#   r   rP   r   r   warningswarnr'   r
    check_distribution_compatibility)r)   r_   r   r+   r   s        r1   r]   zFrozenTrial._suggest\  s    t||#>>DfTl 
 T"'3'D'DU'K$%%&BCMM44:F5$4U
 4&&&::4;N;Nt;TVbc$0D!r3   c                    | j                   S r5   r   rJ   s    r1   r*   zFrozenTrial.numberr      ||r3   c                    || _         y r5   r   r)   r+   s     r1   r*   zFrozenTrial.numberv  s	    r3   c                    | j                   2t        | j                         dkD  rt        d      | j                   d   S y )NrO   DThis attribute is not available during multi-objective optimization.r   r   lenRuntimeErrorrJ   s    r1   r+   zFrozenTrial.valuez  s@    <<#4<< 1$"Z  <<?"r3   c                    | j                   #t        | j                         dkD  rt        d      |	|g| _         y d | _         y )NrO   r   r   r)   vs     r1   r+   zFrozenTrial.value  sD    <<#4<< 1$"Z  =3DLDLr3   c                    | j                   S r5   )r   rJ   s    r1   _get_valueszFrozenTrial._get_values  s    ||r3   c                8    |t        |      | _        y d | _        y r5   )r    r   r   s     r1   _set_valueszFrozenTrial._set_values  s    =7DLDLr3   c                    | j                   S r5   r!   rJ   s    r1   r,   zFrozenTrial.datetime_start  s    ###r3   c                    || _         y r5   r   r   s     r1   r,   zFrozenTrial.datetime_start  s
    $r3   c                    | j                   S r5   r#   rJ   s    r1   r-   zFrozenTrial.params  r   r3   c                    || _         y r5   r   )r)   r-   s     r1   r-   zFrozenTrial.params  s	    r3   c                    | j                   S r5   r'   rJ   s    r1   r
   zFrozenTrial.distributions  s    """r3   c                    || _         y r5   r   r   s     r1   r
   zFrozenTrial.distributions  s
    #r3   c                    | j                   S r5   r   rJ   s    r1   r.   zFrozenTrial.user_attrs  s    r3   c                    || _         y r5   r   r   s     r1   r.   zFrozenTrial.user_attrs  s
     r3   c                    | j                   S r5   r   rJ   s    r1   r/   zFrozenTrial.system_attrs  s    !!!r3   c                H    t        t        t        t        f   |      | _        y r5   )r   r   strr   r%   r   s     r1   r/   zFrozenTrial.system_attrs  s    !$sCx.%8r3   c                z    t        | j                        dk(  ryt        | j                  j                               S )zReturn the maximum step of :attr:`intermediate_values` in the trial.

        Returns:
            The maximum step of intermediates.
        r   N)r   r&   maxr   rJ   s    r1   	last_stepzFrozenTrial.last_step  s4     t''(A-t//44677r3   c                f    | j                   r%| j                  r| j                  | j                   z
  S y)ziReturn the elapsed time taken to complete the trial.

        Returns:
            The duration.
        N)r,   r"   rJ   s    r1   durationzFrozenTrial.duration  s/     4#9#9))D,?,???r3   )r*   rs   r   r   r+   float | Noner,   datetime.datetime | Noner"   r   r-   dict[str, Any]r
   dict[str, BaseDistribution]r.   r   r/   r   r&   zdict[int, float]r0   rs   r   Sequence[float] | NonereturnNone)r:   r   r   bool)r   rs   )r   r   )r_   r   r`   floatra   r   rY   r   rZ   r   r   r   )r_   r   r`   r   ra   r   r   r   )
r_   r   r`   r   ra   r   rm   r   r   r   )r_   r   r`   rs   ra   rs   rY   rs   rZ   r   r   rs   )r_   r   rx   zSequence[None]r   r   )r_   r   rx   zSequence[bool]r   r   )r_   r   rx   zSequence[int]r   rs   )r_   r   rx   zSequence[float]r   r   )r_   r   rx   zSequence[str]r   r   )r_   r   rx   zSequence[CategoricalChoiceType]r   r   )r+   r   rY   rs   r   r   )r   r   )r   r   r+   r   r   r   )r   r   )r_   r   r   r   r   r   )r+   rs   r   r   )r   r   )r   r   r   r   )r   zlist[float] | None)r   r   r   r   )r   r   )r+   r   r   r   )r   r   )r-   r   r   r   )r   r   )r+   r   r   r   )r+   r   r   r   )r+   zMapping[str, JSONSerializable]r   r   )r   z
int | None)r   zdatetime.timedelta | None)*rV   
__module____qualname____doc__r2   r;   r>   r@   rK   rX   rb   r   _suggest_deprecated_msgrP   ri   rk   rn   r   r   rt   r	   ry   r   r   r   r   r   r]   propertyr*   setterr+   r   r   r   r,   r-   r
   r.   r/   r   r   rv   r3   r1   r   r   !   s)   ir *. " "  " 	 "
 1 " 4 "  " 3 " # " % " . "  " ' " 
 "D/
*+L
& "	U	U 	U 		U 	U 	U 
	U Wg,C,J,JPR,J,ST3 U3 Wg,C,J,JPa,J,bc= d= Wg,C,J,JPa,J,bc; d; &B" >?EXX!X),X7:XEIX	X
X
 R RR RP PT TP P$$"A$	$ $MM"AM	M
*& Wg&( '(&P,   ]]    \\
  
   k;/F$ $ % %   ]]  # # $ $     ! ! " " 9 9 
8 
8 
 
r3   r   )r   r+   r   r-   r
   r.   r/   r&   c                   |xs i }|xs i } |j                          D 	ci c]  \  }}	|t        |	       }}}	|xs i }|xs i }|xs i }| t        j                  k(  rd}
nt        j                  j                         }
| j                         r|
}nd}t        dd| |||
||||||      }|j                          |S c c}	}w )a  Create a new :class:`~optuna.trial.FrozenTrial`.

    Example:

        .. testcode::

            import optuna
            from optuna.distributions import CategoricalDistribution
            from optuna.distributions import FloatDistribution

            trial = optuna.trial.create_trial(
                params={"x": 1.0, "y": 0},
                distributions={
                    "x": FloatDistribution(0, 10),
                    "y": CategoricalDistribution([-1, 0, 1]),
                },
                value=5.0,
            )

            assert isinstance(trial, optuna.trial.FrozenTrial)
            assert trial.value == 5.0
            assert trial.params == {"x": 1.0, "y": 0}

    .. seealso::

        See :func:`~optuna.study.Study.add_trial` for how this function can be used to create a
        study from existing trials.

    .. note::

        Please note that this is a low-level API. In general, trials that are passed to objective
        functions are created inside :func:`~optuna.study.Study.optimize`.

    .. note::
        When ``state`` is :class:`TrialState.COMPLETE`, the following parameters are
        required:

        * ``params``
        * ``distributions``
        * ``value`` or ``values``

    Args:
        state:
            Trial state.
        value:
            Trial objective value. Must be specified if ``state`` is :class:`TrialState.COMPLETE`.
            ``value`` and ``values`` must not be specified at the same time.
        values:
            Sequence of the trial objective values. The length is greater than 1 if the problem is
            multi-objective optimization.
            Must be specified if ``state`` is :class:`TrialState.COMPLETE`.
            ``value`` and ``values`` must not be specified at the same time.
        params:
            Dictionary with suggested parameters of the trial.
        distributions:
            Dictionary with parameter distributions of the trial.
        user_attrs:
            Dictionary with user attributes.
        system_attrs:
            Dictionary with system attributes. Should not have to be used for most users.
        intermediate_values:
            Dictionary with intermediate objective values of the trial.

    Returns:
        Created trial.
    N)r*   r0   r   r+   r   r,   r"   r-   r
   r.   r/   r&   )	r   r   r   r   datetimenowr   r   r   )r   r+   r   r-   r
   r.   r/   r&   r   distr,   r"   trials                r1   create_trialr     s    \ \rF!'RM -,,.C 	:4@@M  !rJ%2L-3
"""!**..06D %+#!/E 
OOLGs   B>)r   r   r+   r   r   r   r-   dict[str, Any] | Noner
   z"dict[str, BaseDistribution] | Noner.   r   r/   r   r&   zdict[int, float] | Noner   r   ))
__future__r   collections.abcr   r   r   r   typingr   r   r   r	   r   optunar
   r   optuna._convert_positional_argsr   optuna._deprecatedr   optuna._typingr   optuna.distributionsr   r   r   r   r   r   optuna.trial._baser   r   optuna.trial._stater   
get_loggerrV   _loggerr   r   r   r   rv   r3   r1   <module>r      s    " # $           C . + N 1 6 8 2 0 ; ( * '

X
&< ~) ~F #++%)$(8<(,*.37ss s #	s
 "s 6s &s (s 1s sr3   