L i ddlmZddlZddlmZddlZddlmZerddlm Z  d d dZ GddZ d d d Z y)) annotationsN) TYPE_CHECKING)BaseDistribution)Studyctjjjtjjjtjjj g}|r3|j tjjjd}t|D]}|j|vr|dk(r|jdz}||jkDr||fS|jjs |j}a| tj|j}|jDcic]&\}}|jj||k(r||(}}}||fScc}}w)N)optunatrial TrialStateCOMPLETEWAITINGRUNNINGappendPRUNEDreversedstatenumber is_finishedcopy distributionsitemsget) trialsinclude_pruned search_spacecached_trial_numberstates_of_interestnext_cached_trial_numberr name distributions f/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/optuna/search_space/intersection.py _calculater#s_  (( '' '' !!&,,"9"9"@"@A!&!  ;;0 0  #r )',||a'7 $  -  1 11{{&&(',|| $   99U%8%89L '3&8&8&: "l""&&t, < ,   % 0 1 11  s+E8c$eZdZdZdddZdddZy)IntersectionSearchSpaceaA 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)selfrs r"__init__z IntersectionSearchSpace.__init__Ms!)+!AE%)-c|j|j|_n$|j|jk7r tdt|jd||j|j |j \|_|_|j xsi}tt|jd}tj|S)aReturns 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 |dSNrxs r"z3IntersectionSearchSpace.calculate..ts qtr-key) r) ValueErrorr# _get_trialsr*r(r'dictsortedrrr/)r+studyr0rs r" calculatez!IntersectionSearchSpace.calculateTs >> !"__DN ~~0 !\]]8B   u  B      % % 9 5D5 ))/R F<#5#5#7^LM }}\**r-NF)rboolreturnNone)r=rr0r@rAdict[str, BaseDistribution])__name__ __module__ __qualname____doc__r,r>r3r-r"r%r%:s$.!+r-r%czt||\}}|xsi}tt|jd}|S)aReturn 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 |dSr2r3r4s r"r6z+intersection_search_space..s 1Q4r-r7)r#r;r<r)rrr_s r"intersection_search_spacerKxs>8!8OL!%2L|113HIL r-)FNr) rlist[optuna.trial.FrozenTrial]rr@rz"dict[str, BaseDistribution] | NonerintrAz.tuple[dict[str, BaseDistribution] | None, int]r?)rrLrr@rArC) __future__rrtypingrr optuna.distributionsr optuna.studyrr#r%rKr3r-r"rRs" 1" !7;! )2 *)2)25)2 )2 4 )2X;+;+@! *!r-