
    Q-jO              	         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	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r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jF                  e$      Z%dZ& G d de      Z'ejP                  dddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ)y)    )annotationsN)Any)cast)overload)TYPE_CHECKING)distributions)logging)convert_positional_args)deprecated_func)optuna_warn)-_convert_old_distribution_to_new_distribution)CategoricalDistribution)FloatDistribution)IntDistribution)_SUGGEST_INT_POSITIONAL_ARGS)	BaseTrial)
TrialState)Mapping)Sequence)JSONSerializable)BaseDistribution)CategoricalChoiceTypez 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                b/Users/jameslopez/projects/TradingBot25/.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     r2   __eq__zFrozenTrial.__eq__   s%    %-!!~~..r4   c                `    t        |t              st        S | j                  |j                  k  S r6   r7   r   r8   r+   r:   s     r2   __lt__zFrozenTrial.__lt__   s%    %-!!{{U\\))r4   c                `    t        |t              st        S | j                  |j                  k  S r6   r>   r:   s     r2   __le__zFrozenTrial.__le__   s%    %-!!{{ell**r4   c                R     t        t         fd j                  D                    S )Nc              3  6   K   | ]  }t        |        y wr6   )getattr.0fieldr*   s     r2   	<genexpr>z'FrozenTrial.__hash__.<locals>.<genexpr>   s     JM5'$.Ms   )hashtupler9   r*   s   `r2   __hash__zFrozenTrial.__hash__   s    EJDMMJJKKr4   c                      j                   j                  }dj                   fd j                  D              dz   }| d| dS )Nz, c           	   3  ~   K   | ]4  }|j                  d       s|n|dd  dt        t        |              6 yw)_   N=)
startswithreprrD   rE   s     r2   rH   z'FrozenTrial.__repr__.<locals>.<genexpr>   sI      *E !& 0 0 5559EQtGTXZ_L`GaFbc*s   :=z, value=None())	__class____name__joinr9   )r*   clskwargss   `  r2   __repr__zFrozenTrial.__repr__   sS    nn%%II !]]  	 	 axq!!r4   F)steplogc          	     @    | j                  |t        ||||            S N)r]   r\   )_suggestr   r*   namelowhighr\   r]   s         r2   suggest_floatzFrozenTrial.suggest_float   s!     }}T#4S$Cd#STTr4   z3.0.0z6.0.0 )args)textc                (    | j                  |||      S r6   re   r*   rb   rc   rd   s       r2   suggest_uniformzFrozenTrial.suggest_uniform   s    !!$T22r4   z(..., log=True)c                ,    | j                  |||d      S )NT)r]   rj   rk   s       r2   suggest_loguniformzFrozenTrial.suggest_loguniform   s    !!$Tt!<<r4   z(..., step=...)c                ,    | j                  ||||      S )N)r\   rj   )r*   rb   rc   rd   qs        r2   suggest_discrete_uniformz$FrozenTrial.suggest_discrete_uniform   s    !!$T!::r4   z3.5.0z5.0.0)previous_positional_arg_namesdeprecated_versionremoved_versionrP   c               R    t        | j                  |t        ||||                  S r_   )intr`   r   ra   s         r2   suggest_intzFrozenTrial.suggest_int   s&     4==sDcPT'UVWWr4   c                     y r6    r*   rb   choicess      r2   suggest_categoricalzFrozenTrial.suggest_categorical       ORr4   c                     y r6   ry   rz   s      r2   r|   zFrozenTrial.suggest_categorical   r}   r4   c                     y r6   ry   rz   s      r2   r|   zFrozenTrial.suggest_categorical       MPr4   c                     y r6   ry   rz   s      r2   r|   zFrozenTrial.suggest_categorical   s    QTr4   c                     y r6   ry   rz   s      r2   r|   zFrozenTrial.suggest_categorical   r   r4   c                     y r6   ry   rz   s      r2   r|   zFrozenTrial.suggest_categorical  s     !$r4   c                :    | j                  |t        |            S )N)r{   )r`   r   rz   s      r2   r|   zFrozenTrial.suggest_categorical  s     }}T#:7#KLLr4   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.
        Nry   )r*   r,   r\   s      r2   reportzFrozenTrial.report  s    & 	r4   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`.
        Fry   rK   s    r2   should_prunezFrozenTrial.should_prune!  s     r4   c                "    || j                   |<   y r6   r%   r*   keyr,   s      r2   set_user_attrzFrozenTrial.set_user_attr/  s     %r4   z3.1.0c                "    || j                   |<   y r6   r&   r   s      r2   set_system_attrzFrozenTrial.set_system_attr2  s    "'3r4   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  rTt	        d	t        | j                  j                                d
t        | j                  j                                d      | j                  j                         D ]K  \  }}| j                  |   }|j!                  |      }|j#                  |      r8t	        d| d| d| d       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r6   )mathisnan)rF   xs     r2   rH   z(FrozenTrial._validate.<locals>.<genexpr>J  s     9LqTZZ]Ls   !zvalues should not contain NaN.zInconsistent parameters z and distributions 
The value z of parameter 'z&' isn't contained in the distribution )r   r   WAITINGr-   r    is_finishedr#   FAILr   COMPLETEanysetr.   keysr   itemsto_internal_repr	_contains)r*   
param_nameparam_valuedistributionparam_value_in_internal_reprs        r2   	_validatezFrozenTrial._validate6  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*3t{{/?/?/A+B*C D!!$T%7%7%<%<%>!? @C 
 (,{{'8'8':#J--j9L+7+H+H+U())*FG  _ZL I((4~Q8  (;r4   c           	     L   || j                   vrt        d| d      | j                   |   }|j                  |      }|j                  |      st	        d| d| d| d       || j
                  v r#t        j                  | j
                  |   |       || j
                  |<   |S )NzThe value of the parameter 'zL' is not found. Please set it at the construction of the FrozenTrial object.r   z of the parameter 'z*' is out of the range of the distribution r   )r$   r    r   r   r   r(   r    check_distribution_compatibility)r*   rb   r   r,   r   s        r2   r`   zFrozenTrial._suggest]  s    t||#.tf 5O P 
 T"'3'D'DU'K$%%&BCUG#6tf =11=aA
 4&&&::4;N;Nt;TVbc$0D!r4   c                    | j                   S r6   r   rK   s    r2   r+   zFrozenTrial.numbers      ||r4   c                    || _         y r6   r   r*   r,   s     r2   r+   zFrozenTrial.numberw  s	    r4   c                    | j                   2t        | j                         dkD  rt        d      | j                   d   S y )NrP   DThis attribute is not available during multi-objective optimization.r   r   lenRuntimeErrorrK   s    r2   r,   zFrozenTrial.value{  s@    <<#4<< 1$"Z  <<?"r4   c                    | j                   #t        | j                         dkD  rt        d      |	|g| _         y d | _         y )NrP   r   r   r*   vs     r2   r,   zFrozenTrial.value  sD    <<#4<< 1$"Z  =3DLDLr4   c                    | j                   S r6   )r   rK   s    r2   _get_valueszFrozenTrial._get_values  s    ||r4   c                8    |t        |      | _        y d | _        y r6   )r!   r   r   s     r2   _set_valueszFrozenTrial._set_values  s    =7DLDLr4   c                    | j                   S r6   r"   rK   s    r2   r-   zFrozenTrial.datetime_start  s    ###r4   c                    || _         y r6   r   r   s     r2   r-   zFrozenTrial.datetime_start  s
    $r4   c                    | j                   S r6   r$   rK   s    r2   r.   zFrozenTrial.params  r   r4   c                    || _         y r6   r   )r*   r.   s     r2   r.   zFrozenTrial.params  s	    r4   c                    | j                   S r6   r(   rK   s    r2   r   zFrozenTrial.distributions  s    """r4   c                    || _         y r6   r   r   s     r2   r   zFrozenTrial.distributions  s
    #r4   c                    | j                   S r6   r   rK   s    r2   r/   zFrozenTrial.user_attrs  s    r4   c                    || _         y r6   r   r   s     r2   r/   zFrozenTrial.user_attrs  s
     r4   c                    | j                   S r6   r   rK   s    r2   r0   zFrozenTrial.system_attrs  s    !!!r4   c                &    t        d|      | _        y )Ndict[str, Any])r   r&   r   s     r2   r0   zFrozenTrial.system_attrs  s    !"2E:r4   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   rK   s    r2   	last_stepzFrozenTrial.last_step  s4     t''(A-t//44677r4   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#   rK   s    r2   durationzFrozenTrial.duration  s/     4#9#9))D,?,???r4   )r+   rv   r   r   r,   float | Noner-   datetime.datetime | Noner#   r   r.   r   r   dict[str, BaseDistribution]r/   r   r0   r   r'   zdict[int, float]r1   rv   r   Sequence[float] | NonereturnNone)r;   r   r   bool)r   rv   )r   str)rb   r   rc   floatrd   r   r\   r   r]   r   r   r   )rb   r   rc   r   rd   r   r   r   )
rb   r   rc   r   rd   r   rp   r   r   r   )rb   r   rc   rv   rd   rv   r\   rv   r]   r   r   rv   )rb   r   r{   zSequence[None]r   r   )rb   r   r{   zSequence[bool]r   r   )rb   r   r{   zSequence[int]r   rv   )rb   r   r{   zSequence[float]r   r   )rb   r   r{   zSequence[str]r   r   )rb   r   r{   zSequence[CategoricalChoiceType]r   r   )r,   r   r\   rv   r   r   )r   r   )r   r   r,   r   r   r   )r   r   )rb   r   r   r   r   r   )r,   rv   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)*rW   
__module____qualname____doc__r3   r<   r?   rA   rL   r[   re   r   _suggest_deprecated_msgformatrl   rn   rq   r
   r   rw   r   r|   r   r   r   r   r   r`   propertyr+   setterr,   r   r   r   r-   r.   r   r/   r0   r   r   ry   r4   r2   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&( '(%N,   ]]    \\
  
   k;/F$ $ % %   ]]  # # $ $     ! ! " " ; ; 
8 
8 
 
r4   r   )r   r,   r   r.   r   r/   r0   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+   r1   r   r,   r   r-   r#   r.   r   r/   r0   r'   )	r   r   r   r   datetimenowr   r   r   )r   r,   r   r.   r   r/   r0   r'   r   distr-   r#   trials                r2   create_trialr     s    \ \rF!'RM -,,..IC 	:4@@.   !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   r0   r   r'   zdict[int, float] | Noner   r   )*
__future__r   r   r   typingr   r   r   r   optunar   r	   optuna._convert_positional_argsr
   optuna._deprecatedr   optuna._warningsr   optuna.distributionsr   r   r   r   optuna.trial._baser   r   optuna.trial._stater   collections.abcr   r   optuna._typingr   r   r   
get_loggerrW   _loggerr   r   r   r   ry   r4   r2   <module>r      s   "           C . ( N 8 2 0 ; ( * '(/5: '

X
&< {) {@ #++%)$(8<(,*.37ss s #	s
 "s 6s &s (s 1s sr4   