
    (^i
                        d dl mZ d dlZd dlmZ d dlZd dlmZ erd dlm	Z	 	 	 	 d
	 	 	 	 	 	 	 	 	 ddZ
 G d d      Z	 d	 	 	 	 	 dd	Zy)    )annotationsN)TYPE_CHECKING)BaseDistribution)Studyc                   t         j                  j                  j                  t         j                  j                  j                  t         j                  j                  j
                  g}|r3|j                  t         j                  j                  j                         d}t        |       D ]  }|j                  |vr|dk(  r|j                  dz   }||j                  kD  r ||fS |j                  j                         s|j                  }a| t        j                  |j                        }|j                         D ci c]&  \  }}|j                  j                  |      |k(  r||( }}} ||fS c c}}w )N   )optunatrial
TrialStateCOMPLETEWAITINGRUNNINGappendPRUNEDreversedstatenumberis_finishedcopydistributionsitemsget)	trialsinclude_prunedsearch_spacecached_trial_numberstates_of_interestnext_cached_trial_numberr   namedistributions	            a/var/www/html/hubwallet-dev/venv/lib/python3.12/site-packages/optuna/search_space/intersection.py
_calculater#      s_    	(('''' !!&,,"9"9"@"@A!&! 
;;00#r)',||a'7$-  111 {{&&(',||$99U%8%89L '3&8&8&:
"l""&&t,< ,
 
%
0 111
s   +E8c                  $    e Zd ZdZdddZdddZy)IntersectionSearchSpacea  A class to calculate the intersection search space of a :class:`~optuna.study.Study`.

    Intersection search space contains the intersection of parameter distributions that have been
    suggested in the completed trials of the study so far.
    If there are multiple parameters that have the same name but different distributions,
    neither is included in the resulting search space
    (i.e., the parameters with dynamic value ranges are excluded).

    Note that an instance of this class is supposed to be used for only one study.
    If different studies are passed to
    :func:`~optuna.search_space.IntersectionSearchSpace.calculate`,
    a :obj:`ValueError` is raised.

    Args:
        include_pruned:
            Whether pruned trials should be included in the search space.
    c                <    d| _         d | _        d | _        || _        y )Nr   )_cached_trial_number_search_space	_study_id_include_pruned)selfr   s     r"   __init__z IntersectionSearchSpace.__init__M   s!    )+!AE%)-    c                   | j                   |j                   | _         n$| j                   |j                   k7  rt        d      t        |j                  d|      | j                  | j
                  | j                        \  | _        | _        | j
                  xs i }t        t        |j                         d             }t        j                  |      S )a  Returns the intersection search space of the :class:`~optuna.study.Study`.

        Args:
            study:
                A study with completed trials. The same study must be passed for one instance
                of this class through its lifetime.
            use_cache:
                An option to use cached trials for each trial.

        Returns:
            A dictionary containing the parameter names and parameter's distributions sorted by
            parameter names.
        z9`IntersectionSearchSpace` cannot handle multiple studies.F)deepcopy	use_cachec                    | d   S Nr    xs    r"   <lambda>z3IntersectionSearchSpace.calculate.<locals>.<lambda>t   s
    qt r-   key)r)   
ValueErrorr#   _get_trialsr*   r(   r'   dictsortedr   r   r/   )r+   studyr0   r   s       r"   	calculatez!IntersectionSearchSpace.calculateT   s     >>!"__DN ~~0 !\]]8Bu	B  %%	9
5D5 ))/RF<#5#5#7^LM}}\**r-   NF)r   boolreturnNone)r=   r   r0   r@   rA   dict[str, BaseDistribution])__name__
__module____qualname____doc__r,   r>   r3   r-   r"   r%   r%   :   s    $.!+r-   r%   c                z    t        | |      \  }}|xs i }t        t        |j                         d             }|S )a  Return the intersection search space of the given trials.

    Intersection search space contains the intersection of parameter distributions that have been
    suggested in the completed trials of the study so far.
    If there are multiple parameters that have the same name but different distributions,
    neither is included in the resulting search space
    (i.e., the parameters with dynamic value ranges are excluded).

    .. note::
        :class:`~optuna.search_space.IntersectionSearchSpace` provides the same functionality with
        a much faster way. Please consider using it if you want to reduce execution time
        as much as possible.

    Args:
        trials:
            A list of trials.
        include_pruned:
            Whether pruned trials should be included in the search space.

    Returns:
        A dictionary containing the parameter names and parameter's distributions sorted by
        parameter names.
    c                    | d   S r2   r3   r4   s    r"   r6   z+intersection_search_space.<locals>.<lambda>   s
    1Q4 r-   r7   )r#   r;   r<   r   )r   r   r   _s       r"   intersection_search_spacerK   x   s>    8 !8OL!%2L|113HILr-   )FNr   )
r   list[optuna.trial.FrozenTrial]r   r@   r   z"dict[str, BaseDistribution] | Noner   intrA   z.tuple[dict[str, BaseDistribution] | None, int]r?   )r   rL   r   r@   rA   rC   )
__future__r   r   typingr   r
   optuna.distributionsr   optuna.studyr   r#   r%   rK   r3   r-   r"   <module>rR      s    "     1 "
 !7;!	)2*)2)2 5)2 	)2
 4)2X;+ ;+@ !* !r-   