L i>ddlmZddlmZddlmZddlmZddlmZddlZddl Z ddl m Z ddl m Z dd l mZdd lmZdd lmZdd lmZdd lmZddlmZej0rddlmZe j4j7eZGddeZdddddd ddZddZ d ddZ!ddZ" d dZ# d! d"dZ$ d! d#dZ%y)$) annotations)Callable)Sequence)Any) NamedTupleN) _deprecated)_CONSTRAINTS_KEY)Study)"_get_pareto_front_trials_by_trials) FrozenTrial) TrialState)_imports)_make_hovertext)goc^eZdZUded<ded<ded<ded<ded<d ed <d ed <d ed <y)_ParetoFrontInfoint n_targetsz list[str] target_names%list[tuple[FrozenTrial, list[float]]]best_trials_with_valuesnon_best_trials_with_valuesinfeasible_trials_with_valuesz list[int] axis_orderboolinclude_dominated_trialshas_constraintsN)__name__ __module__ __qualname____annotations__h/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/optuna/visualization/_pareto_front.pyrrs1NBB!FF#HH""r#rT)rrrconstraints_functargetsc`tjt||||||}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. )rcheck_get_pareto_front_info_get_pareto_front_plot)studyrrrr%r&infos r$plot_pareto_frontr-%s6@ NN ! |5zCSU\ D "$ ''r#c |j}|j}|s_t|j|j||j ddt|j|j||j ddg}nt|j|j||jddt|j|j||j ddt|j|j||j ddg}|jd k(rMtjd |j|jd |j|jd  }nitjd |j|jd |j|jd |j|jd d}tj||S)Nz%{text}TrialT) hovertemplatedominated_trialsz %{text}Best TrialFz&%{text}Infeasible Trial)r/ infeasiblez$%{text}Feasible TrialzPareto-front Plotr)title xaxis_title yaxis_title)r5r6 zaxis_title)r4scene)datalayout) rr_make_scatter_objectrrrrrrLayoutrFigure)r,rrr9r:s r$r*r*ms#<<**O  (00;!%   !(,,@!&   ( !(22F   !(00D!%   !(,,@!&  # 6 ~~%))$//!*<=))$//!*<=  %#001CD#001CD#001CD  99$v ..r#c |z(_get_pareto_front_info..s cr#c3&K|] }|dk yw)rENr").0rFs r$ z)_get_pareto_front_info..s%D1a3h%Dsr completedzcompleted and feasiblezYour study does not have any z trials. )r2z`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|Dcgc] }|| }}|D])}t|trtdt|t ||Dcgc]\}}|t |fc}}Scc}wcc}}w)NzL`targets` should return a sequence of target values. your `targets` returns ) isinstancer ValueErrortypeziplist)trialsr&trial target_valuesvs r$_make_trials_with_valuesz8_get_pareto_front_info.._make_trials_with_valuess6<._infer_n_targetss+ ! "Q &)!,Q/0 0r#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 .zSize of `axis_order` z . Expect: z , Actual: zElements of given `axis_order` z are not unique!.r3zGiven `axis_order` z contains invalid index z higher than z lower than 0.)rrrrrrrr)rSlist[FrozenTrial]r&z(Callable[[FrozenTrial], Sequence[float]]returnr)rZ-Sequence[tuple[FrozenTrial, Sequence[float]]]r^z int | None)r_DEPRECATION_WARNING_TEMPLATEformatwarningswarn FutureWarningrO get_trialsr COMPLETEallmapappend system_attrsgetr r directions_get_non_pareto_front_trialsrY_loggerwarning_targets_default metric_namesrangerRsetmaxminr)r+rrrr%r&msgfeasible_trialsinfeasible_trialsrrT constraints best_trialsnon_best_trials what_trial_targetsrWrrrr[rrqis r$r)r)sW77>>wg?   c=)#77>>%WG?   c=)z5 4  OO!!5*:M:M9O!P,  '"O3)+;E+BCD&&u-!((/ ((,,-=> ;d22  #%D %D"D  " "5 )  $ $U +,"5_eFVFVWK6 T ;1$3[9Q 7 |9MNH u F *'HJ  M! M9 M / M7{HM":?H"U$<=NPX$Y!I !!89=M%>I  #L)I _E,,-I`  " = 2  ))  6;I6FGj,GLG'L \ i 'J9+UVWXX% *+ z?i '' |:i[Iz?+1.  s: 9 ,>zlJ[\] ] z?Y] *%j\1I#j/IZ[(1}oQ0  z?Q %j\1I#j/IZ[    ! 7$?&C!9'  7Hs= Nc|jSN)values)rTs r$rprpKs <<r#cDg}|D]}||vs|j||Sr)ri)rS pareto_trialsnon_pareto_trialsrTs r$rmrmOs7,  %  $ $U +, r#c |xsg}t|Dcgc]\}}| c}}|||} |dk(rjtj|D cgc] \}} | |dc} }|D cgc] \}} | |dc} }|Dcgc]\}}t|c}}d|| dS|dk(rtj|D cgc] \}} | |dc} }|D cgc] \}} | |dc} }|D cgc] \}} | |dc} }|Dcgc]\}}t|c}}d|| d SJd cc}}wcc} }wcc} }wcc}}wcc} }wcc} }wcc} }wcc}}w) N)r0r1r2rr3markersF)rFytextmoder/marker showlegendrL)rFrzrrr/rrzMust not reach here) _make_markerrScatterr Scatter3d) rrrrZr/r1r0rT_rrs r$r;r;Ysb,1r 1285!2 ) F A~zz6HIFvjm$I6HIFvjm$I9KLXUA/%(L'   a||6HIFvjm$I6HIFvjm$I6HIFvjm$I9KLXUA/%(L'   ,++u7 3JILJIILs/ D( D. D4 6D:1E E %E ?Ec|r|st|dk(sJ|rddiS|r$ddd|Dcgc]}|jc}ddd id Sddd|Dcgc]}|jc}d d |rd ndddd Scc}wcc}w)Nrcolorz#ccccccg?Grey)widthrBluesr4Trial)liner colorscalecolorbarRedsz Best Trialg?r3()r4rFxpad)rYnumber)rSrr0r1ts r$rrs  86{a Y   !F3(./1ahh/!   "F3(./1ahh/ %4S!  00s A+ A0)r+r rlist[str] | Nonerrrlist[int] | Noner%/Callable[[FrozenTrial], Sequence[float]] | Noner&rr^ 'go.Figure')r,rr^r)NTNNN)r+r rrrrrrr%rr&rr^r)rTr r^zSequence[float])rSr]rr]r^r])FF)rrrz Sequence[int]rrrZr_r/strr1rr0rr^z'go.Scatter' | 'go.Scatter3d') rSzSequence[FrozenTrial]rrr0rr1rr^zdict[str, Any])& __future__rcollections.abcrrtypingrrrboptunaroptuna.samplers._baser optuna.studyr optuna.study._multi_objectiver optuna.trialr r $optuna.visualization._plotly_importsroptuna.visualization._utilsr is_successfulrlogging get_loggerrrnrr-r*r)rprmr;rr"r#r$rs"$$ 2L$#9787 .. # #H -z&*%)#'HL?CE( E(#E(# E( ! E( F E(=E(E(PA/L&*%)#'HL?C W W"W#W! W F W = WWt .? "',',',#',F ',  ',  ',',#',Z#  !  "        r#