o
    /wio                     @  sH  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jeZd:ddZe rrd dlZ e j!j"j#Z$d;ddZ%d<ddZ&d<d d!Z'd=d$d%Z(d>d)d*Z)		+d?d@d-d.Z*dAd0d1Z+dBd4d5Z,dCd8d9Z-dS )D    )annotations)Callable)SequenceN)Any)cast)CategoricalDistribution)FloatDistribution)IntDistribution)Study)StudyDirection)FrozenTrial)_plotly_importsis_availablereturnboolc                   C  s
   t 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 r   r   X/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/optuna/visualization/_utils.pyr      s   
studyStudy | Sequence[Study]target%Callable[[FrozenTrial], float] | Nonetarget_namestrNonec                 C  s^   t | tr	| g}n| }|d u rtdd |D rtd|d ur+|dkr-td d S d S d S )Nc                 s  s    | ]}|  V  qd S N)_is_multi_objective).0r   r   r   r   	<genexpr><   s    z#_check_plot_args.<locals>.<genexpr>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   r   r   studiesr   r   r   _check_plot_args1   s   
r&   trialslist[FrozenTrial]paramc                 C  s:   | D ]}||j vr
q|j| }t|ttfo|j  S dS )NF)paramsdistributionsr    r   r	   logr'   r)   trialdistr   r   r   _is_log_scaleH   s   

r0   c                 C  s`   | D ]+}||j vr
q|j| }t|ttfr dS t|tr*tdd |jD   S J ddS )NTc                 s  s*    | ]}t |ttfot |t V  qd S r   )r    intfloatr   )r   vr   r   r   r   Z   s    
z _is_numerical.<locals>.<genexpr>FzShould not reach.)r*   r+   r    r	   r   r   allchoicesr-   r   r   r   _is_numericalQ   s   


r6   p_name	list[Any]c                   s.    fdd| D }t |  r|S ttt|S )Nc                   s    g | ]} |j v r|j   qS r   )r*   )r   tr7   r   r   
<listcomp>c   s     z%_get_param_values.<locals>.<listcomp>)r6   listmapr   )r'   r7   valuesr   r:   r   _get_param_valuesb   s   
r?   used_param_namesSequence[str]set[int]c                 C  s<   t  }| D ]}|D ]}||j vr||j  nq	q|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'   r@   skipped_trial_numbersr.   
used_paramr   r   r   _get_skipped_trial_numbersi   s   rI   Twith_messagec                 C  s   |d u rddd}|}g }| D ]=}||}zt |}W n ttfy4   td|j dt| d	  w t|sG|rFt	
d
|j d q|| q|S )Nr9   r   r   r2   c                 S  s   t t| jS r   )r   r2   value)r9   r   r   r   _target   s   z"_filter_nonfinite.<locals>._target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.)r9   r   r   r2   )r2   r"   	TypeErrorr#   r$   rF   reprnpisfinite_loggerwarningappend)r'   r   rJ   rL   filtered_trialsr.   rK   r   r   r   _filter_nonfinite   s2   	



rV   r
   c                 C  s   |d up	| j tjkS r   )	directionr   MINIMIZE)r   r   r   r   r   _is_reverse_scale   s   rY   rK   r   c                 C  s,   zt |  | W S  ty   t|  Y S w r   )jsondumpsrN   r   )rK   r   r   r   _make_json_compatible   s   
r\   r.   r   c                 C  sP   dd | j  D }|rd|ini }tj| j| j| jd|dd}|ddS )	Nc                 S  s   i | ]	\}}|t |qS r   )r\   )r   keyrK   r   r   r   
<dictcomp>   s    z#_make_hovertext.<locals>.<dictcomp>
user_attrs)rF   r>   r*      )indent
z<br>)r_   itemsrZ   r[   rF   r>   r*   replace)r.   r_   user_attrs_dicttextr   r   r   _make_hovertext   s   	rg   )r   r   )r   r   r   r   r   r   r   r   )r'   r(   r)   r   r   r   )r'   r(   r7   r   r   r8   )r'   r(   r@   rA   r   rB   )NT)r'   r(   r   r   rJ   r   r   r(   )r   r
   r   r   r   r   )rK   r   r   r   )r.   r   r   r   ).
__future__r   collections.abcr   r   rZ   typingr   r   r#   numpyrP   optunaoptuna.distributionsr   r   r	   optuna.studyr
   optuna.study._study_directionr   optuna.trialr   optuna.visualizationr   __all__logging
get_logger__name__rR   r   plotly.colorsplotlycolors
sequentialBluesCOLOR_SCALEr&   r0   r6   r?   rI   rV   rY   r\   rg   r   r   r   r   <module>   sB    




	


,
	