
    (^i>                       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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j0                         rd dlmZ e	j4                  j7                  e      Z G d de      Zdddddd	 	 	 	 	 	 	 	 	 	 	 	 	 ddZddZ 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ!ddZ"	 	 	 	 	 	 d dZ#	 	 d!	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d"dZ$	 	 d!	 	 	 	 	 	 	 	 	 d#dZ%y)$    )annotations)Callable)Sequence)Any)
NamedTupleN)_deprecated)_CONSTRAINTS_KEY)Study)"_get_pareto_front_trials_by_trials)FrozenTrial)
TrialState)_imports)_make_hovertext)goc                  ^    e Zd ZU ded<   ded<   ded<   ded<   ded<   d	ed
<   ded<   ded<   y)_ParetoFrontInfoint	n_targetsz	list[str]target_names%list[tuple[FrozenTrial, list[float]]]best_trials_with_valuesnon_best_trials_with_valuesinfeasible_trials_with_valuesz	list[int]
axis_orderboolinclude_dominated_trialshas_constraintsN)__name__
__module____qualname____annotations__     c/var/www/html/hubwallet-dev/venv/lib/python3.12/site-packages/optuna/visualization/_pareto_front.pyr   r      s1    NBB!FF#HH""r#   r   T)r   r   r   constraints_functargetsc               `    t        j                          t        | |||||      }t        |      S )a  Plot the Pareto front of a study.

    .. seealso::
        Please refer to :ref:`multi_objective` for the tutorial of the Pareto front visualization.

    Args:
        study:
            A :class:`~optuna.study.Study` object whose trials are plotted for their objective
            values. The number of objectives must be either 2 or 3 when ``targets`` is :obj:`None`.
        target_names:
            Objective name list used as the axis titles. If :obj:`None` is specified,
            "Objective {objective_index}" is used instead. If ``targets`` is specified
            for a study that does not contain any completed trial,
            ``target_name`` must be specified.
        include_dominated_trials:
            A flag to include all dominated trial's objective values.
        axis_order:
            A list of indices indicating the axis order. If :obj:`None` is specified,
            default order is used. ``axis_order`` and ``targets`` cannot be used at the same time.

            .. warning::
                Deprecated in v3.0.0. This feature will be removed in the future. The removal of
                this feature is currently scheduled for v5.0.0, but this schedule is subject to
                change. See https://github.com/optuna/optuna/releases/tag/v3.0.0.
        constraints_func:
            An optional function that computes the objective constraints. It must take a
            :class:`~optuna.trial.FrozenTrial` and return the constraints. The return value must
            be a sequence of :obj:`float` s. A value strictly larger than 0 means that a
            constraint is violated. A value equal to or smaller than 0 is considered feasible.
            This specification is the same as in, for example,
            :class:`~optuna.samplers.NSGAIISampler`.

            If given, trials are classified into three categories: feasible and best, feasible but
            non-best, and infeasible. Categories are shown in different colors. Here, whether a
            trial is best (on Pareto front) or not is determined ignoring all infeasible trials.

            .. warning::
                Deprecated in v4.0.0. This feature will be removed in the future. The removal of
                this feature is currently scheduled for v6.0.0, but this schedule is subject to
                change. See https://github.com/optuna/optuna/releases/tag/v4.0.0.
        targets:
            A function that returns targets values to display.
            The argument to this function is :class:`~optuna.trial.FrozenTrial`.
            ``axis_order`` and ``targets`` cannot be used at the same time.
            If ``study.n_objectives`` is neither 2 nor 3, ``targets`` must be specified.

            .. note::
                Added in v3.0.0 as an experimental feature. The interface may change in newer
                versions without prior notice.
                See https://github.com/optuna/optuna/releases/tag/v3.0.0.

    Returns:
        A :class:`plotly.graph_objects.Figure` object.
    )r   check_get_pareto_front_info_get_pareto_front_plot)studyr   r   r   r%   r&   infos          r$   plot_pareto_frontr-   %   s6    @ NN!|5zCSU\D "$''r#   c           
        | j                   }| j                  }|s_t        | j                  | j                  || j
                  dd      t        | j                  | j                  || j                  dd      g}nt        | j                  | j                  || j                  dd      t        | j                  | j                  || j
                  dd      t        | j                  | j                  || j                  dd      g}| j                  d	k(  rMt        j                  d
| j                  | j                  d      | j                  | j                  d            }nit        j                  d
| j                  | j                  d      | j                  | j                  d      | j                  | j                  d	      d      }t        j                  ||      S )Nz%{text}<extra>Trial</extra>T)hovertemplatedominated_trialsz %{text}<extra>Best Trial</extra>Fz&%{text}<extra>Infeasible Trial</extra>)r/   
infeasiblez$%{text}<extra>Feasible Trial</extra>   zPareto-front Plotr      )titlexaxis_titleyaxis_title)r5   r6   zaxis_title)r4   scene)datalayout)r   r   _make_scatter_objectr   r   r   r   r   r   Layoutr   Figure)r,   r   r   r9   r:   s        r$   r*   r*   m   s   #<<**O (00;!% !(,,@!&
( !(22F !(00D!% !(,,@!&#
6 ~~%))$//!*<=))$//!*<=
 %#001CD#001CD#001CD
 99$v..r#   c           
        |<t         j                  j                  ddd      }t        j                  |t
               |<t         j                  j                  ddd      }t        j                  |t
               ||t        d      g }g }d	}	| j                  d	t        j                  f
      D ]  }
|Bd}	t        t        d  ||
                  r|j                  |
       n|j                  |
       G|
j                  j                  t              }|	|d uz  }	|t        d |D              r|j                  |
       |j                  |
        t!        || j"                        }|rt%        ||      }ng }t'        |      dk(  r|	rdnd}t(        j+                  d| d       |}|)t'        | j"                        dv rt,        }nt        d      	 	 	 	 	 	 d(d} |||      } |||      } |||      }	 	 	 	 d)d} ||      xs  ||      }|1|t'        |      }n#|t'        | j"                        }nt        d      |dvrt        d| d      |-| j.                  }|t1        |      D cg c]  }d| 	 }}n |}nt'        |      |k7  rt        d| d      |t3        t1        |            }nt'        |      |k7  rt        d| d| dt'        |       d      t'        t5        |            |k7  rt        d | d!      t7        |      |d"z
  kD  r!t        d#| d$t7        |       d%|d"z
   d      t9        |      dk  rt        d#| d$t9        |       d&      t;        ||||||||	'      S c c}w )*Nz`axis_order`z3.0.0z5.0.0)named_verr_verz`constraints_func`z4.0.0z6.0.0z]Using both `targets` and `axis_order` is not supported. Use either `targets` or `axis_order`.F)deepcopystatesTc                    | dk  S )N        r"   )xs    r$   <lambda>z(_get_pareto_front_info.<locals>.<lambda>   s
    c r#   c              3  &   K   | ]	  }|d k    yw)rE   Nr"   ).0rF   s     r$   	<genexpr>z)_get_pareto_front_info.<locals>.<genexpr>   s     %D1a3h%Ds   r   	completedzcompleted and feasiblezYour study does not have any z	 trials. )r2      z`plot_pareto_front` function only supports 2 or 3 objective studies when using `targets` is `None`. Please use `targets` if your objective studies have more than 3 objectives.c                    | D cg c]
  } ||       }}|D ])  }t        |t              rt        dt        |              t	        | |      D cg c]  \  }}|t        |      f c}}S c c}w c c}}w )NzL`targets` should return a sequence of target values. your `targets` returns )
isinstancer   
ValueErrortypeziplist)trialsr&   trialtarget_valuesvs        r$   _make_trials_with_valuesz8_get_pareto_front_info.<locals>._make_trials_with_values   s     6<<E<< 	Aa* //3Awi9 	 25V]1KLXUAQ LL = Ms   A.A3c                B    t        |       dkD  rt        | d   d         S y )Nr   r3   )len)trials_with_valuess    r$   _infer_n_targetsz0_get_pareto_front_info.<locals>._infer_n_targets  s+     !"Q&)!,Q/00r#   zNIf `targets` is specified for empty studies, `target_names` must be specified.zD`plot_pareto_front` function only supports 2 or 3 targets. you used z targets now.z
Objective z/The length of `target_names` is supposed to be .zSize of `axis_order` z
. Expect: z
, Actual: zElements of given `axis_order` z are not unique!.r3   zGiven `axis_order` z contains invalid index z higher than z lower than 0.)r   r   r   r   r   r   r   r   )rS   list[FrozenTrial]r&   z(Callable[[FrozenTrial], Sequence[float]]returnr   )rZ   -Sequence[tuple[FrozenTrial, Sequence[float]]]r^   z
int | None)r   _DEPRECATION_WARNING_TEMPLATEformatwarningswarnFutureWarningrO   
get_trialsr   COMPLETEallmapappendsystem_attrsgetr	   r   
directions_get_non_pareto_front_trialsrY   _loggerwarning_targets_defaultmetric_namesrangerR   setmaxminr   )r+   r   r   r   r%   r&   msgfeasible_trialsinfeasible_trialsr   rT   constraintsbest_trialsnon_best_trials
what_trial_targetsrW   r   r   r   r[   r   rq   is                           r$   r)   r)      sW    77>>wg ? 
 	c=)#77>>%WG ? 
 	c=)z54
 	

 OO!!5*:M:M9O!P ,'"O3)+;E+BCD&&u-!((/((,,-=>;d22#%D%D"D""5)$$U+," 5_eFVFVWK6T
;1$3[9Q
7
|9MNHu F*'HJ M!M9M 
/M 7{HM":?H"U$<=NPX$Y!I	 !!89 =M%>I #L)I_E,,-I`  "=2
 	

 ))6;I6FGj,GLG'L	\	i	'J9+UVWXX%	*+
z?i''
|:i[ Iz?+1.  s:9,>zlJ[\]]z?Y]*%j\1I#j/IZ [(1}oQ0  z?Q%j\1I#j/IZ [    
 ! 7$?&C!9'	 	7 Hs   =Nc                    | j                   S N)values)rT   s    r$   rp   rp   K  s    <<r#   c                D    g }| D ]  }||vs|j                  |        |S r   )ri   )rS   pareto_trialsnon_pareto_trialsrT   s       r$   rm   rm   O  s7      ,%$$U+, r#   c                   |xs g }t        |D cg c]  \  }}|	 c}}|||      }	| dk(  rjt        j                  |D 
cg c]  \  }}
|
|d       c}
}|D 
cg c]  \  }}
|
|d       c}
}|D cg c]  \  }}t        |       c}}d||	d      S | dk(  rt        j                  |D 
cg c]  \  }}
|
|d       c}
}|D 
cg c]  \  }}
|
|d       c}
}|D 
cg c]  \  }}
|
|d       c}
}|D cg c]  \  }}t        |       c}}d||	d	      S J d
       c c}}w c c}
}w c c}
}w c c}}w c c}
}w c c}
}w c c}
}w c c}}w )N)r0   r1   r2   r   r3   markersF)rF   ytextmoder/   marker
showlegendrL   )rF   r   zr   r   r/   r   r   zMust not reach here)_make_markerr   Scatterr   	Scatter3d)r   r   r   rZ   r/   r1   r0   rT   _r   r   s              r$   r;   r;   Y  sb    ,1r1285!2 )	F A~zz6HIFvjm$I6HIFvjm$I9KLXUA/%(L'
 	
 
a||6HIFvjm$I6HIFvjm$I6HIFvjm$I9KLXUA/%(L'	
 		
 	,++u7 	3 JIL JIILs/   D(
D.
D46D:1E 
E%E?Ec                    |r|st        |       dk(  sJ |rddiS |r$ddd| D cg c]  }|j                   c}ddd	id
S ddd| D cg c]  }|j                   c}dd|rdndddd
S c c}w c c}w )Nr   colorz#ccccccg      ?Grey)widthr   Bluesr4   Trial)liner   
colorscalecolorbarRedsz
Best Trialg?r3   (   )r4   rF   xpad)rY   number)rS   r   r0   r1   ts        r$   r   r     s      86{aY
 	
 
!F3(./1ahh/!	
 	
 "F3(./1ahh/ %4S!		
 		
 0 0s   A+	A0)r+   r
   r   list[str] | Noner   r   r   list[int] | Noner%   /Callable[[FrozenTrial], Sequence[float]] | Noner&   r   r^   'go.Figure')r,   r   r^   r   )NTNNN)r+   r
   r   r   r   r   r   r   r%   r   r&   r   r^   r   )rT   r   r^   zSequence[float])rS   r]   r   r]   r^   r]   )FF)r   r   r   zSequence[int]r   r   rZ   r_   r/   strr1   r   r0   r   r^   z'go.Scatter' | 'go.Scatter3d')
rS   zSequence[FrozenTrial]r   r   r0   r   r1   r   r^   zdict[str, Any])&
__future__r   collections.abcr   r   typingr   r   rb   optunar   optuna.samplers._baser	   optuna.studyr
   optuna.study._multi_objectiver   optuna.trialr   r   $optuna.visualization._plotly_importsr   optuna.visualization._utilsr   is_successfulr   logging
get_loggerr   rn   r   r-   r*   r)   rp   rm   r;   r   r"   r#   r$   <module>r      s   " $ $      2  L $ # 9 7 87
..
#
#H
-z  &*%)#'HL?CE(E( #E( #	E(
 !E( FE( =E( E(PA/L &*%)#'HL?CWW"W #W !	W
 FW =W Wt.?  "',',', #', F	',
 ', ', ', #',Z #	 
! 
" 
  
 	 

  
r#   