
    -ji-                    B   S SK Jr  S SKJr  S SKrS SKJr  S SKJr  S SKr	S SK
Jr  S SKJr  S SKJr  S S	KJr  S S
KJr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJr  \(       a  S SKJr  S SKJr  S SKJr  \ " S S5      5       r\" S5       " S S\5      5       rSS jr g)    )annotations)	dataclassN)Any)TYPE_CHECKING)experimental_class)BaseDistribution)CategoricalDistribution)FloatDistribution)IntDistribution)BaseSampler)LazyRandomState)create_trial)FrozenTrial)
TrialState)Iterable)Sequence)Studyc                      \ rS rSr% SrS\S'   SrS\S'   SrS\S	'   SS
 jrSS jr	SS jr
    SS jrSS jrSS jrSrg)	_TreeNode   N
str | None
param_namezdict[float, '_TreeNode'] | NonechildrenFbool
is_runningc                   U R                   c'  Xl        U Vs0 s H  o3[        5       _M     snU l         g U R                  U:w  a  [        SU R                   SU 35      eU R                   R	                  5       [        U5      :w  a;  [        S[        U R                   R	                  5       5       S[        U5       35      eg s  snf )Nzparam_name mismatch: z != zsearch_space mismatch: )r   r   r   
ValueErrorkeysset)selfr   search_spacevalues       V/home/james-whalen/.local/lib/python3.13/site-packages/optuna/samplers/_brute_force.pyexpand_TreeNode.expand*   s     == (O=IJ\EIK/\JDM*, #88Ij\!Z[[}}!!#s<'88 -c$--2D2D2F.G-HSQ]M^L_`  9	 Ks   Cc                    SU l         g )NTr   r    s    r#   set_running_TreeNode.set_running9   s	        c                (    U R                  S / 5        g N)r$   r(   s    r#   set_leaf_TreeNode.set_leaf<   s    D"r+   c                    U nU HF  u  p4nUR                  X45        UR                  c   eXRR                  ;  a    g UR                  U   nMH     U$ r-   )r$   r   )r    params_and_search_spacescurrent_noder   r!   r"   s         r#   add_path_TreeNode.add_path?   s`     /G+Je
9((444111'007L 0H r+   c                   ^ U R                   c  T(       a  U R                  (       a  S$ S$ [        U4S jU R                   R                  5        5       5      $ )Nr      c              3  D   >#    U  H  oR                  T5      v   M     g 7fr-   )count_unexpanded).0childexclude_runnings     r#   	<genexpr>-_TreeNode.count_unexpanded.<locals>.<genexpr>Q   s     cLb5--o>>Lbs    )r   r   sumvalues)r    r;   s    `r#   r8   _TreeNode.count_unexpandedL   s>    == 'DOO1BBcDMML`L`Lbcccr+   c                f  ^ U R                   c   e[        R                  " U R                   R                  5        Vs/ s H  o3R	                  U5      PM     sn[        R
                  S9m[        U4S j[        U R                   R                  5       5       5       5      (       aD  [        U R                   R                  5       5       H  u  pCUR                  (       d  M  STU'   M     TTR                  5       -  mUR                  [        U R                   R                  5       5      TS9$ s  snf )N)dtypec              3  h   >#    U  H'  u  pUR                   (       + =(       a    TU   S :  v   M)     g7f)r   Nr'   )r9   ir"   weightss      r#   r<   )_TreeNode.sample_child.<locals>.<genexpr>]   s3      
=    3WQZ!^3=s   /2g        )p)r   nparrayr?   r8   float64any	enumerater   r>   choicelistr   )r    rngr;   r:   rD   rE   s        @r#   sample_child_TreeNode.sample_childS   s    }}(((
 ((BF--BVBVBXYBX##O4BXY**
  
%dmm&:&:&<=
 
 

 &dmm&:&:&<=###!$GAJ > 	7;;= zz$t}}1134z@@ Zs   D.)r   r   r   )r   r   r!   zIterable[float]returnNone)rR   rS   )r1   z,Iterable[tuple[str, Iterable[float], float]]rR   z_TreeNode | None)r;   r   rR   int)rO   znp.random.RandomStater;   r   rR   float)__name__
__module____qualname____firstlineno__r   __annotations__r   r   r$   r)   r.   r3   r8   rP   __static_attributes__ r+   r#   r   r      sS     "J
!04H-4J(T	dAr+   r   z3.1.0c                      \ rS rSrSrSSS jjr      SS jr        SS jr\        SS j5       r	          SS jr
          SS	 jrS
rg)BruteForceSampleri   a  Sampler using brute force.

This sampler performs exhaustive search on the defined search space.

Example:

    .. testcode::

        import optuna


        def objective(trial):
            c = trial.suggest_categorical("c", ["float", "int"])
            if c == "float":
                return trial.suggest_float("x", 1, 3, step=0.5)
            elif c == "int":
                a = trial.suggest_int("a", 1, 3)
                b = trial.suggest_int("b", a, 3)
                return a + b


        study = optuna.create_study(sampler=optuna.samplers.BruteForceSampler())
        study.optimize(objective)

Note:
    The defined search space must be finite. Therefore, when using
    :class:`~optuna.distributions.FloatDistribution` or
    :func:`~optuna.trial.Trial.suggest_float`, ``step=None`` is not allowed.

Note:
    The sampler may fail to try the entire search space in when the suggestion ranges or
    parameters are changed in the same :class:`~optuna.study.Study`.

Args:
    seed:
        A seed to fix the order of trials as the search order randomly shuffled. Please note
        that it is not recommended using this option in distributed optimization settings since
        this option cannot ensure the order of trials and may increase the number of duplicate
        suggestions during distributed optimization.
    avoid_premature_stop:
        If :obj:`True`, the sampler performs a strict exhaustive search. Please note
        that enabling this option may increase the likelihood of duplicate sampling.
        When this option is not enabled (default), the sampler applies a looser criterion for
        determining when to stop the search, which may result in incomplete coverage of the
        search space. For more information, see https://github.com/optuna/optuna/issues/5780.
Nc                0    [        U5      U l        X l        g r-   )r   _rng_avoid_premature_stop)r    seedavoid_premature_stops      r#   __init__BruteForceSampler.__init__   s    #D)	%9"r+   c                    0 $ r-   r\   )r    studytrials      r#   infer_relative_search_space-BruteForceSampler.infer_relative_search_space   	     	r+   c                    0 $ r-   r\   )r    rh   ri   r!   s       r#   sample_relative!BruteForceSampler.sample_relative   rl   r+   c                b  ^^ U H  m[        U4S jTR                  5        5       5      (       d  M-  U R                  UU4S jTR                  R                  5        5       5      nUc  Mf  TR                  R                  5       (       a  UR                  5         M  UR                  5         M     g )Nc              3  x   >#    U  H/  u  pUTR                   ;   =(       a    TR                   U   U:H  v   M1     g 7fr-   )params)r9   rG   vri   s      r#   r<   3BruteForceSampler._populate_tree.<locals>.<genexpr>   s1     ]ndaqELL(AU\\!_-AAns   7:c              3     >#    U  H9  u  pUT;  d  M  U[        U5      UR                  TR                  U   5      4v   M;     g 7fr-   )_enumerate_candidatesto_internal_reprrr   )r9   r   param_distributionrr   ri   s      r#   r<   rt      sQ       ;V6
!/"-.@A*;;ELL<TU
 ;Vs
   A1A)allitemsr3   distributionsstateis_finishedr.   r)   )treetrialsrr   leafri   s     ` @r#   _populate_tree BruteForceSampler._populate_tree   s    
 E]flln]]]== ;@:M:M:S:S:U
D ;;**,,MMO$$&' r+   c                ~  ^ U R                   (       + nUR                  R                  UR                  S[        R
                  [        R                  [        R                  [        R                  4S9n[        5       n[        U5      nUR                  X85        U R                  UU4S jU 5       TR                  5        UR                  U5      S:X  a4  UR                  U R                   R"                  R%                  U5      5      $ UR                  UR'                  U R                   R"                  U5      5      $ )NFdeepcopystatesc              3  ^   >#    U  H"  oR                   TR                   :w  d  M  Uv   M$     g 7fr-   )number)r9   tri   s     r#   r<   7BruteForceSampler.sample_independent.<locals>.<genexpr>   s      "QfELL8P11fs   -	-r   )rb   _storageget_all_trials	_study_idr   COMPLETEPRUNEDRUNNINGFAILr   rv   r$   r   rr   r8   to_external_reprra   rO   rM   rP   )	r    rh   ri   r   rx   r;   r   r~   
candidatess	     `      r#   sample_independent$BruteForceSampler.sample_independent   s    #888
 ..OO##!!""	 / 	
 {*+=>
J+ 	D"Qf"QSXS_S_`  1Q6%66tyy}}7K7KJ7WXX%66!!$))--A r+   c                  ^^^ U R                   (       + nUR                  R                  UR                  S[        R
                  [        R                  [        R                  [        R                  4S9n[        5       nU R                  UUUU4S jU 5       0 5        UR                  U5      S:X  a  UR                  5         g g )NFr   c              3     >#    U  HA  nUR                   TR                   :w  a  UO[        TTTR                  TR                  S 9v   MC     g7f))r|   r?   rr   r{   N)r   r   rr   r{   )r9   r   r|   ri   r?   s     r#   r<   0BruteForceSampler.after_trial.<locals>.<genexpr>   sQ        A xx5<</ %#%$||&+&9&9	  s   A	Ar   )rb   r   r   r   r   r   r   r   r   r   r   r8   stop)r    rh   ri   r|   r?   r;   r   r~   s     ```   r#   after_trialBruteForceSampler.after_trial   s     #888
 ..OO##!!""	 / 	
 {   	
$   1Q6JJL 7r+   )rb   ra   )NF)rc   z
int | Nonerd   r   rR   rS   )rh   r   ri   r   rR   dict[str, BaseDistribution])rh   r   ri   r   r!   r   rR   dict[str, Any])r~   r   r   zIterable[FrozenTrial]rr   r   rR   rS   )
rh   r   ri   r   r   strrx   r   rR   r   )
rh   r   ri   r   r|   r   r?   zSequence[float] | NonerR   rS   )rV   rW   rX   rY   __doc__re   rj   rn   staticmethodr   r   r   r[   r\   r+   r#   r^   r^   i   s    -^:#.	$
#.>Y	
 ''!6'@N'	' '2"" " 	"
 -" 
"H** * 	*
 '* 
*r+   r^   c                   [        U [        5      (       a  U R                  c  [        S5      e[        R
                  " [        U R                  5      5      n[        R
                  " [        U R                  5      5      n[        R
                  " [        U R                  5      5      n/ nUnXR::  a%  UR                  [        U5      5        XS-  nXR::  a  M%  U$ [        U [        5      (       a7  [        [        U R                  U R                  S-   U R                  5      5      $ [        U [        5      (       a'  [        [        [        U R                   5      5      5      $ [        SU  S35      e)NzjFloatDistribution.step must be given for BruteForceSampler (otherwise, the search space will be infinite).r6   zUnknown distribution .)
isinstancer
   stepr   decimalDecimalr   lowhighappendrU   r   rN   ranger	   lenchoices)rx   r   r   r   retr"   s         r#   rv   rv     s9   $&788""*C  ooc"4"8"89:s#5#:#:;<s#5#:#:;<mJJuU|$ME m 
	&	8	8$((*<*A*AA*EGYG^G^_
 	
 
&(?	@	@E#0889:;;01C0DAFGGr+   )rx   r   rR   zSequence[float])!
__future__r   dataclassesr   r   typingr   r   numpyrH   optuna._experimentalr   optuna.distributionsr   r	   r
   r   optuna.samplersr   "optuna.samplers._lazy_random_stater   optuna.trialr   r   r   collections.abcr   r   optuna.studyr   r   r^   rv   r\   r+   r#   <module>r      s    " !      3 1 8 2 0 ' > % $ # ((" HA HA HAV Gf f fRHr+   