
    (^io                       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	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gZej4                  j7                  e      ZddZ e       r$d dlZ e jB                  jD                  jF                  Z$	 	 	 	 	 	 	 	 ddZ%ddZ&ddZ'ddZ(	 	 	 	 	 	 ddZ)	 	 d	 	 	 	 	 	 	 ddZ*d dZ+d!dZ,d"dZ-y)#    )annotations)Callable)SequenceN)Any)cast)CategoricalDistribution)FloatDistribution)IntDistribution)Study)StudyDirection)FrozenTrial)_plotly_importsis_availablec                 >    t         j                  j                         S )a  Returns whether visualization with plotly is available or not.

    .. note::

        :mod:`~optuna.visualization` module depends on plotly version 4.0.0 or higher. If a
        supported version of plotly isn't installed in your environment, this function will return
        :obj:`False`. In such case, please execute ``$ pip install -U plotly>=4.0.0`` to install
        plotly.

    Returns:
        :obj:`True` if visualization with plotly is available, :obj:`False` otherwise.
    )r   _importsis_successful     \/var/www/html/hubwallet-dev/venv/lib/python3.12/site-packages/optuna/visualization/_utils.pyr   r      s     ##1133r   c                    t        | t              r| g}n| }|t        d |D              rt        d      ||dk(  rt	        j
                  d       y y y )Nc              3  <   K   | ]  }|j                           y wN)_is_multi_objective).0studys     r   	<genexpr>z#_check_plot_args.<locals>.<genexpr><   s     Oee779Os   z[If the `study` is being used for multi-objective optimization, please specify the `target`.zObjective ValuezQ`target` is specified, but `target_name` is the default value, 'Objective Value'.)
isinstancer   any
ValueErrorwarningswarn)r   targettarget_namestudiess       r   _check_plot_argsr%   1   se     %'~#OwOO+
 	

 k->>_	
 ?r   c                    | D ]E  }||j                   vr|j                  |   }t        |t        t        f      xr |j
                  c S  y)NF)paramsdistributionsr   r	   r
   logtrialsparamtrialdists       r   _is_log_scaler/   H   sS     S$""5)$!2O DER$((R	S
 r   c                    | D ]l  }||j                   vr|j                  |   }t        |t        t        f      r yt        |t
              rt        d |j                  D              c S J d        y)NTc              3  n   K   | ]-  }t        |t        t        f      xr t        |t                / y wr   )r   intfloatbool)r   vs     r   r   z _is_numerical.<locals>.<genexpr>Z   s2      LM
1sEl+GJq$4G0GGs   35zShould not reach.)r'   r(   r   r
   r	   r   allchoicesr*   s       r   _is_numericalr8   Q   s     .$""5)d_.?@A56 QUQ]Q]   .--5. r   c                    | D cg c]   }||j                   v s|j                   |   " }}t        | |      r|S t        t        t        |            S c c}w r   )r'   r8   listmapstr)r+   p_nametvaluess       r   _get_param_valuesr@   b   sP    (.E1&AHH2DahhvEFEVV$C !! Fs
   AAc                    t               }| D ]B  }|D ];  }||j                  j                         vs |j                  |j                          B D |S )a  Utility function for ``plot_parallel_coordinate``.

    If trial's parameters do not contain a parameter in ``used_param_names``,
    ``plot_parallel_coordinate`` methods do not use such trials.

    Args:
        trials:
            List of ``FrozenTrial``s.
        used_param_names:
            The parameter names used in ``plot_parallel_coordinate``.

    Returns:
        A set of invalid trial numbers.
    )setr'   keysaddnumber)r+   used_param_namesskipped_trial_numbersr-   
used_params        r   _get_skipped_trial_numbersrI   i   s\    $  E * 	J!2!2!44%))%,,7	
 ! r   c           
     p   |dd}|}g }| D ]c  } ||      }	 t        |      }t        j                  |      s'|s/t        j                  d|j
                   d       S|j                  |       e |S # t        t        f$ r1 t        j                  d|j
                   dt        |       d        w xY w)Nc                6    t        t        | j                        S r   )r   r3   value)r>   s    r   _targetz"_filter_nonfinite.<locals>._target   s    qww''r   Trialz's target value z could not be cast to float.zTrial zG is omitted in visualization because its objective value is inf or nan.)r>   r   returnr3   )r3   r   	TypeErrorr    r!   rE   reprnpisfinite_loggerwarningappend)r+   r"   with_messagerM   filtered_trialsr-   rL   s          r   _filter_nonfiniterY      s     ~	( )+O *u		%LE {{5!U\\N +A A
 ""5)-*0 % 
 	 MM~%5d5k]B^_ 	s   A55A B5c                H    |d uxs | j                   t        j                  k(  S r   )	directionr   MINIMIZE)r   r"   s     r   _is_reverse_scaler]      s!    KN4K4K!KKr   c                f    	 t        j                  |        | S # t        $ r t        |       cY S w xY wr   )jsondumpsrP   r<   )rL   s    r   _make_json_compatiblera      s1    

5 5zs    00c                $   | j                   j                         D ci c]  \  }}|t        |       }}}|rd|ini }t        j                  | j
                  | j                  | j                  d|d      }|j                  dd      S c c}}w )N
user_attrs)rE   r?   r'      )indent
z<br>)	rc   itemsra   r_   r`   rE   r?   r'   replace)r-   keyrL   rc   user_attrs_dicttexts         r   _make_hovertextrl      s    FKFVFVF\F\F^_
U#,U33_J_4>|Z0BO::llllll	
 		
 D <<f%% `s   B)rO   r4   )r   zStudy | Sequence[Study]r"   %Callable[[FrozenTrial], float] | Noner#   r<   rO   None)r+   list[FrozenTrial]r,   r<   rO   r4   )r+   ro   r=   r<   rO   z	list[Any])r+   ro   rF   zSequence[str]rO   zset[int])NT)r+   ro   r"   rm   rW   r4   rO   ro   )r   r   r"   rm   rO   r4   )rL   r   rO   r   )r-   r   rO   r<   ).
__future__r   collections.abcr   r   r_   typingr   r   r    numpyrR   optunaoptuna.distributionsr   r	   r
   optuna.studyr   optuna.study._study_directionr   optuna.trialr   optuna.visualizationr   __all__logging
get_logger__name__rT   r   plotly.colorsplotlycolors
sequentialBluesCOLOR_SCALEr%   r/   r8   r@   rI   rY   r]   ra   rl   r   r   r   <module>r      s   " $ $       8 2 0  8 $ 0 

..
#
#H
-4" >--**00K
"
1
 
 
	
.""!!1>!!: 59))1) ) 	)XL&r   