
    Q-j;?                       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	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rd dlmZ  ej4                         rd dlmZ e	j8                  j;                  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)
NamedTuple)TYPE_CHECKINGN)_deprecated)optuna_warn)_CONSTRAINTS_KEY)"_get_pareto_front_trials_by_trials)FrozenTrial)
TrialState)_imports)_make_hovertext)Study)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__     p/Users/jameslopez/projects/TradingBot25/.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>)r1   
infeasiblez$%{text}<extra>Feasible Trial</extra>   zPareto-front Plotr      )titlexaxis_titleyaxis_title)r7   r8   zaxis_title)r6   scene)datalayout)r   r   _make_scatter_objectr   r   r   r   r   r   Layoutr   Figure)r.   r   r   r;   r<   s        r&   r,   r,   q   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           
        |2t         j                  j                  ddd      }t        |t               |2t         j                  j                  ddd      }t        |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,                  }|t/        |      D cg c]  }d| 	 }}n |}nt%        |      |k7  rt        d| d      |t1        t/        |            }nt%        |      |k7  rt        d| d| dt%        |       d      t%        t3        |            |k7  rt        d | d!      t5        |      |d"z
  kD  r!t        d#| d$t5        |       d%|d"z
   d      t7        |      dk  rt        d#| d$t7        |       d&      t9        ||||||||	'      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)rG   Nr$   ).0rH   s     r&   	<genexpr>z)_get_pareto_front_info.<locals>.<genexpr>   s     %D1a3hs   r   zcompleted and feasible	completedzYour study does not have any z	 trials. )r4      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<<VEV<Aa* //3Awi9   25V]1KL1KXUAQ 1KLL = Ms   A.A3c                B    t        |       dkD  rt        | d   d         S y )Nr   r5   )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!.r5   zGiven `axis_order` z contains invalid index z higher than z lower than 0.)r   r   r   r   r   r   r   r   )rU   list[FrozenTrial]r(   z(Callable[[FrozenTrial], Sequence[float]]returnr   )r\   -Sequence[tuple[FrozenTrial, Sequence[float]]]r`   z
int | None)r	   _DEPRECATION_WARNING_TEMPLATEformatr
   FutureWarningrQ   
get_trialsr   COMPLETEallmapappendsystem_attrsgetr   r   
directions_get_non_pareto_front_trialsr[   _loggerwarning_targets_defaultmetric_namesrangerT   setmaxminr   )r-   r   r   r   r'   r(   msgfeasible_trialsinfeasible_trialsr   rV   constraintsbest_trialsnon_best_trials
what_trial_targetsrY   r   r   r   r]   r   rq   is                           r&   r+   r+      sN    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+ Q" 5_eFVFVWK6T
;11@-k
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G6Fj,6FL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   )M/c                    | j                   S N)values)rV   s    r&   rp   rp   O  s    <<r%   c                D    g }| D ]  }||vs|j                  |        |S r   )ri   )rU   pareto_trialsnon_pareto_trialsrV   s       r&   rm   rm   S  s2     %$$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)r2   r3   r4   r   r5   markersF)rH   ytextmoder1   marker
showlegendrN   )rH   r   zr   r   r1   r   r   zMust not reach here)_make_markerr   Scatterr   	Scatter3d)r   r   r   r\   r1   r3   r2   rV   _r   r   s              r&   r=   r=   ]  s    ,1r12185!12 )	F A~zz6HI6HFvjm$6HI6HI6HFvjm$6HI9KL9KXUA/%(9KL'
 	
 
a||6HI6HFvjm$6HI6HI6HFvjm$6HI6HI6HFvjm$6HI9KL9KXUA/%(9K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   Bluesr6   Trial)liner   
colorscalecolorbarRedsz
Best Trialg?r5   (   )r6   rH   xpad)r[   number)rU   r   r2   r3   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   )rV   r   r`   zSequence[float])rU   r_   r   r_   r`   r_   )FF)r   r   r   zSequence[int]r   r   r\   ra   r1   strr3   r   r2   r   r`   z'go.Scatter' | 'go.Scatter3d')
rU   zSequence[FrozenTrial]r   r   r2   r   r3   r   r`   zdict[str, Any])(
__future__r   collections.abcr   r   typingr   r   r   optunar	   optuna._warningsr
   optuna.samplers._baser   optuna.study._multi_objectiver   optuna.trialr   r   $optuna.visualization._plotly_importsr   optuna.visualization._utilsr   optuna.studyr   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%   