
    -ji?                       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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  \R2                  " 5       (       a  S SKJr  \R6                  R9                  \5      r " S S\5      rSSSSSS.             SS jjr SS jr!     S             SS jjr"S S jr#      S!S jr$  S"               S#S jjr%  S"         S$S jjr&g)%    )annotations)Callable)Sequence)Any)
NamedTupleN)_deprecated)optuna_warn)_CONSTRAINTS_KEY)Study)"_get_pareto_front_trials_by_trials)FrozenTrial)
TrialState)_imports)_make_hovertext)goc                  f    \ rS rSr% S\S'   S\S'   S\S'   S\S'   S\S	'   S
\S'   S\S'   S\S'   Srg)_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_constraints N)__name__
__module____qualname____firstlineno____annotations____static_attributes__r        \/home/james-whalen/.local/lib/python3.13/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               \    [         R                  " 5         [        XX#XE5      n[        U5      $ )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_frontr1   %   s/    @ NN!5CSD "$''r'   c                   U R                   nU R                  nU(       dY  [        U R                  U R                  UU R
                  SSS9[        U R                  U R                  UU R                  SSS9/nO[        U R                  U R                  UU R                  SSS9[        U R                  U R                  UU R
                  SSS9[        U R                  U R                  UU R                  SSS9/nU R                  S	:X  aK  [        R                  " S
U R                  U R                  S      U R                  U R                  S      S9nOg[        R                  " S
U R                  U R                  S      U R                  U R                  S      U R                  U R                  S	      S.S9n[        R                  " X4S9$ )Nz%{text}<extra>Trial</extra>T)hovertemplatedominated_trialsz %{text}<extra>Best Trial</extra>Fz&%{text}<extra>Infeasible Trial</extra>)r3   
infeasiblez$%{text}<extra>Feasible Trial</extra>   zPareto-front Plotr      )titlexaxis_titleyaxis_title)r9   r:   zaxis_title)r8   scene)datalayout)r   r   _make_scatter_objectr   r   r   r   r   r   Layoutr   Figure)r0   r   r   r=   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$..r'   c                6   Ub/  [         R                  R                  SSSS9n[        U[        5        Ub/  [         R                  R                  SSSS9n[        U[        5        Ub  Ub  [        S5      e/ n/ nS	n	U R                  S	[        R                  4S
9 H  n
UbH  Sn	[        [        S U" U
5      5      5      (       a  UR                  U
5        OUR                  U
5        MN  U
R                  R                  [        5      nXS L-  n	Ub  [        S U 5       5      (       a  UR                  U
5        M  UR                  U
5        M     [        XpR                   5      nU(       a  [#        X|5      nO/ n[%        U5      S:X  a$  U	(       a  SOSn[&        R)                  SU S35        UnUc+  [%        U R                   5      S;   a  [*        nO[        S5      e      S(S jnU" X5      nU" X5      nU" X5      n    S)S jnU" U5      =(       d    U" U5      nUc3  Ub  [%        U5      nO$Uc  [%        U R                   5      nO[        S5      eUS;  a  [        SU S35      eUc1  U R,                  nUc  [/        U5       Vs/ s H  nSU 3PM
     nnO!UnO[%        U5      U:w  a  [        SU S35      eUc  [1        [/        U5      5      nO[%        U5      U:w  a  [        SU SU S[%        U5       S35      e[%        [3        U5      5      U:w  a  [        S U S!35      e[5        U5      US"-
  :  a!  [        S#U S$[5        U5       S%US"-
   S35      e[7        U5      S:  a  [        S#U S$[7        U5       S&35      e[9        UUUUUUUU	S'9$ s  snf )*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                    U S:*  $ )N        r    )xs    r(   <lambda>(_get_pareto_front_info.<locals>.<lambda>   s    cr'   c              3  *   #    U  H	  oS :*  v   M     g7f)rI   Nr    ).0rJ   s     r(   	<genexpr>)_get_pareto_front_info.<locals>.<genexpr>   s     %D13hs   r   	completedzcompleted and feasiblezYour study does not have any z	 trials. )r6      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                   U  Vs/ s H
  o!" U5      PM     nnU H/  n[        U[        5      (       a  M  [        S[        U5       35      e   [	        X5       VVs/ s H  u  p$U[        U5      4PM     snn$ s  snf s  snnf )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_values8_get_pareto_front_info.<locals>._make_trials_with_values   s     6<<VEV<Aa** //3Awi9   25V1KL1KXUQ 1KLL = Ms   A8A=c                D    [        U 5      S:  a  [        U S   S   5      $ g )Nr   r7   )len)trials_with_valuess    r(   _infer_n_targets0_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!.r7   zGiven `axis_order` z contains invalid index z higher than z lower than 0.)r   r   r   r   r   r   r   r   )rY   list[FrozenTrial]r*   z(Callable[[FrozenTrial], Sequence[float]]returnr   )ra   -Sequence[tuple[FrozenTrial, Sequence[float]]]rf   z
int | None)r   _DEPRECATION_WARNING_TEMPLATEformatr	   FutureWarningrU   
get_trialsr   COMPLETEallmapappendsystem_attrsgetr
   r   
directions_get_non_pareto_front_trialsr`   _loggerwarning_targets_defaultmetric_namesrangerX   setmaxminr   )r/   r   r   r   r)   r*   msgfeasible_trialsinfeasible_trialsr   rZ   constraintsbest_trialsnon_best_trials
what_trial_targetsr]   r   r   r   rb   r   rw   is                           r(   r-   r-      sI    77>>wg ? 
 	C'#77>>%WG ? 
 	C'z54
 	

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

 ))6;I6FG6Fj,6FLGL'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                    U R                   $ N)values)rZ   s    r(   rv   rv   K  s    <<r'   c                L    / nU  H  nX1;  d  M
  UR                  U5        M     U$ r   )ro   )rY   pareto_trialsnon_pareto_trialsrZ   s       r(   rs   rs   O  s0     %$$U+  r'   c                   U=(       d    / n[        U VVs/ s H  u  pxUPM	     snnUUUS9n	U S:X  al  [        R                  " U VV
s/ s H  u  pXS      PM     sn
nU VV
s/ s H  u  pXS      PM     sn
nU VVs/ s H  u  px[        U5      PM     snnSUU	SS9$ U S:X  a  [        R                  " U VV
s/ s H  u  pXS      PM     sn
nU VV
s/ s H  u  pXS      PM     sn
nU VV
s/ s H  u  pXS      PM     sn
nU VVs/ s H  u  px[        U5      PM     snnSUU	SS	9$  S
5       es  snnf s  sn
nf s  sn
nf s  snnf s  sn
nf s  sn
nf s  sn
nf s  snnf )N)r4   r5   r6   r   r7   markersF)rJ   ytextmoder3   marker
showlegendrR   )rJ   r   zr   r   r3   r   r   zMust not reach here)_make_markerr   Scatterr   	Scatter3d)r   r   r   ra   r3   r5   r4   rZ   _r   r   s              r(   r?   r?   Y  sx    ,1r1218512 )	F A~zz6HI6Hvm$6HI6HI6Hvm$6HI9KL9KXU/%(9KL'
 	
 
a||6HI6Hvm$6HI6HI6Hvm$6HI6HI6Hvm$6HI9KL9KXU/%(9KL'	
 		
 	,++u7 	3 JIL JIILs/   D3
D9
#D?>E:E
E0EEc                &   U(       a  U(       d  [        U 5      S:X  d   eU(       a  SS0$ U(       a&  SSS.U  Vs/ s H  oDR                  PM     snSSS	0S
.$ SSS.U  Vs/ s H  oDR                  PM     snSSU(       a  SOSSS.S
.$ s  snf s  snf )Nr   colorz#ccccccg      ?Grey)widthr   Bluesr8   Trial)liner   
colorscalecolorbarRedsz
Best Trialg?r7   (   )r8   rJ   xpad)r`   number)rY   r   r4   r5   ts        r(   r   r     s      86{aY
 	
 
!F3(./1hh/!	
 	
 "F3(./1hh/ %4S!		
 		
 0 0s   B	 B)r/   r   r   list[str] | Noner   r   r   list[int] | Noner)   /Callable[[FrozenTrial], Sequence[float]] | Noner*   r   rf   'go.Figure')r0   r   rf   r   )NTNNN)r/   r   r   r   r   r   r   r   r)   r   r*   r   rf   r   )rZ   r   rf   zSequence[float])rY   re   r   re   rf   re   )FF)r   r   r   zSequence[int]r   r   ra   rg   r3   strr5   r   r4   r   rf   z'go.Scatter' | 'go.Scatter3d')
rY   zSequence[FrozenTrial]r   r   r4   r   r5   r   rf   zdict[str, Any])'
__future__r   collections.abcr   r   typingr   r   optunar   optuna._warningsr	   optuna.samplers._baser
   optuna.studyr   optuna.study._multi_objectiver   optuna.trialr   r   $optuna.visualization._plotly_importsr   optuna.visualization._utilsr   is_successfulr   logging
get_loggerr!   rt   r   r1   r.   r-   rv   rs   r?   r   r    r'   r(   <module>r      s   " $ $     ( 2  L $ # 9 7 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'   