o
    }oiJ                     @  s   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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 e rPd dlmZ eeZG dd deZe	ddddZd ddZd!ddZdS )"    )annotations)Sequence)
NamedTupleN)experimental_func)compute_hypervolume)
get_logger)_CONSTRAINTS_KEY)Study)StudyDirection)
TrialState)_imports)goc                   @  s   e Zd ZU ded< ded< dS )_HypervolumeHistoryInfoz	list[int]trial_numberszlist[float]valuesN)__name__
__module____qualname____annotations__ r   r   ]/home/ubuntu/.local/lib/python3.10/site-packages/optuna/visualization/_hypervolume_history.pyr      s   
 r   z3.3.0studyr	   reference_pointSequence[float]return'go.Figure'c                 C  sP   t   |  stdt|t| jkrtdt| tj|tj	d}t
|S )a  Plot hypervolume history of all trials in a study.

    Args:
        study:
            A :class:`~optuna.study.Study` object whose trials are plotted for their hypervolumes.
            The number of objectives must be 2 or more.

        reference_point:
            A reference point to use for hypervolume computation.
            The dimension of the reference point must be the same as the number of objectives.

    Returns:
        A :class:`plotly.graph_objects.Figure` object.
    zoStudy must be multi-objective. For single-objective optimization, please use plot_optimization_history instead.zRThe dimension of the reference point must be the same as the number of objectives.)dtype)r   check_is_multi_objective
ValueErrorlen
directions_get_hypervolume_history_infonpasarrayfloat64_get_hypervolume_history_plot)r   r   infor   r   r   plot_hypervolume_history   s   r(   r'   c                 C  s:   t jdddiddid}t j| j| jdd}t j||dS )	NzHypervolume History PlottitleTrialHypervolume)r)   xaxisyaxiszlines+markers)xymode)datalayout)r   LayoutScatterr   r   Figure)r'   r2   r1   r   r   r   r&   B   s   r&   
np.ndarrayc                 C  s  | j dtjfd}t|dkrtd tdd | jD }|| }g }g }d }d}|D ]}	|	|	j
 t|	jv }
|
rP|	jt }ttdd	 |rP|	| q-||	j tjd d f }|d urr||kjd
djddrr|	| q-||k r~|	| q-|t|| 7 }|d u r|}n$t||}|t||8 }||k jd
d}tj||d d f |gdd}|	| q-|d u rtd t||S )NF)deepcopystatesr   z.Your study does not have any completed trials.c                 S  s   g | ]}|t jkrd ndqS )   )r
   MINIMIZE).0dr   r   r   
<listcomp>^   s    z1_get_hypervolume_history_info.<locals>.<listcomp>        c                 S  s   | dkS )Nr?   r   )r.   r   r   r   <lambda>l   s    z/_get_hypervolume_history_info.<locals>.<lambda>r9   )axisz-Your study does not have any feasible trials.)
get_trialsr   COMPLETEr    _loggerwarningr#   r$   r!   appendnumberr   system_attrsanymapr   newaxisallprodmaximumr   concatenater   )r   r   completed_trialssignsminimization_reference_pointr   hypervolume_valuesbest_trials_values_normalizedhypervolumetrialhas_constraintsconstraints_valuesvalues_normalizedlimited_solsis_keptr   r   r   r"   S   sL   







r"   )r   r	   r   r   r   r   )r'   r   r   r   )r   r	   r   r6   r   r   ) 
__future__r   collections.abcr   typingr   numpyr#   optuna._experimentalr   optuna._hypervolumer   optuna.loggingr   optuna.samplers._baser   optuna.studyr	   optuna.study._study_directionr
   optuna.trialr   $optuna.visualization._plotly_importsr   is_successfulr   r   rD   r   r(   r&   r"   r   r   r   r   <module>   s(    
$