
    (^i                    
   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  ej"                         rd d
lmZ  ee      Z G d de      Z G d de      ZdddZddZddZdddZddZddZy)    )annotationsN)
NamedTuple)
get_logger)_CONSTRAINTS_KEY)Study)
TrialState)_imports)_make_hovertext)goc                  J    e Zd ZU ded<   ded<   ded<   ded<   ded	<   d
ed<   y)_TimelineBarInfointnumberdatetime.datetimestartcompleter   statestr	hovertextbool
infeasibleN__name__
__module____qualname____annotations__     _/var/www/html/hubwallet-dev/venv/lib/python3.12/site-packages/optuna/visualization/_timeline.pyr   r      s$    KNr   r   c                      e Zd ZU ded<   y)_TimelineInfolist[_TimelineBarInfo]barsNr   r   r   r   r!   r!      s    
  r   r!   c                ~    ||dk  rt        d      t        j                          t        | |      }t	        |      S )a'  Plot the timeline of a study.

    Args:
        study:
            A :class:`~optuna.study.Study` object whose trials are plotted with
            their lifetime.
        n_recent_trials:
            The number of recent trials to plot. If :obj:`None`, all trials are plotted.
            If specified, only the most recent ``n_recent_trials`` will be displayed.
            Must be a positive integer.

    Returns:
        A :class:`plotly.graph_objects.Figure` object.

    Raises:
        ValueError: if ``n_recent_trials`` is 0 or negative.
    r   z3n_recent_trials must be a positive integer or None.)n_recent_trials)
ValueErrorr	   check_get_timeline_info_get_timeline_plot)studyr%   infos      r   plot_timeliner,   !   s>    & "!';NOONNe_EDd##r   c                   t        | j                  D cg c]3  }|j                  %|j                  |j                  |j                  z
  5 c}d       }t	        | |      rt
        j
                  j                         S t        | j                  D cg c]  }|j                  |j                   c}t
        j
                  j                               S c c}w c c}w )N)default)maxtrialsdatetime_completedatetime_start_is_running_trials_in_studydatetimenow)r*   tmax_run_durations      r   _get_max_datetime_completer8   <   s     \\	
"".13C3C3O !"2"22	

  #5*:;  $$&&&+llVa6I6I6U		V!!%%' 	
 	Ws   8CC$Cc                    | j                  t        j                  fd      }t        |      dkD  S t        j                  j                         t        fd|D              S )NF)statesdeepcopyr   c              3  `   K   | ]%  }|j                   |j                   z
  dz  k   ' y w)N   )r2   ).0r6   r7   r5   s     r   	<genexpr>z._is_running_trials_in_study.<locals>.<genexpr>V   s;      ' 	a%5!55s   +.)
get_trialsr   RUNNINGlenr4   r5   any)r*   r7   running_trialsr5   s    ` @r   r3   r3   N   sg    %%j.@.@-BU%SN>"Q&&





!C    r   c                   g }t        |       }t        j                  d      }| j                  d      }||| d  }|D ]  }|j                  xs |}|j
                  t        j                  k(  r||z   n|j                  xs ||z   }t        |j                  vrdn,t        |j                  t           D 	cg c]  }	|	dkD  	 c}	      }
||k  r)t        j                  d|j                   d| d| d	       |j                  t!        |j                  |||j
                  t#        |      |

              t%        |      dk(  rt        j                  d       t'        |      S c c}	w )N   )secondsF)r;   r   z"The start and end times for Trial z( seem to be reversed. The start time is z and the end time is .)r   r   r   r   r   r   z$Your study does not have any trials.)r8   r4   	timedeltar@   r2   r   r   rA   r1   r   system_attrsrC   _loggerwarningr   appendr   r
   rB   r!   )r*   r%   r#   max_datetimetimedelta_for_small_barr0   trialr2   r1   xr   s              r   r(   r(   ^   s~   D-e4L&00;u-F"()* 
--= {{j000 22((TN=T,T 	  u'9'99 U%7%78H%IJa!eJK 	
 ~-OO8 G))7(88MN_M``ac 	||$*kk)%0%		
'
< 4yA~>?/ Ks   6E$
c                &   dddddd}t        j                         }t        t        d       D ]   }|j                  d	k(  r| j
                  D cg c]!  }|j                  |k(  s|j                  s |# }}| j
                  D cg c]!  }|j                  |k(  s|j                  r |# }}t        |d
d|       t        |||j                     |j                  |       | j
                  D cg c]  }|j                  |k(  s| }}t        |||j                     |j                  |        |j                  d       |j                  t        j                  dddiddi             |j                  d       |S c c}w c c}w c c}w )Nblueredorangegreengray)COMPLETEFAILPRUNEDrA   WAITINGc                    | j                   S N)name)rQ   s    r   <lambda>z$_get_timeline_plot.<locals>.<lambda>   s
    !&& r   )keyrX   z#cccccc
INFEASIBLEdate)typezTimeline PlottitleDatetimeTrial)rd   xaxisyaxisT)
showlegend)r   Figuresortedr   r^   r#   r   r   
_plot_barsupdate_xaxesupdate_layoutLayout)r+   _cmfigr   binfeasible_barsfeasible_barsr#   s           r   r)   r)      sb   C ))+C
(89 ?::#*.))YQqww%7GALLqYOY(,		[1QWW5EallQ[M[	<E}c%**ouzz3G#yy=!AGGu,<A=D=tS_ejj#>? &!
		!J'G$	
 &J! Z[ >s0   F%F2FF	F	(F	0FFc                   t        |       dk(  ry |j                  t        j                  || D cg c],  }|j                  |j
                  z
  j                         dz  . c}| D cg c]  }|j                   c}| D cg c]  }|j
                  j                          c}| D cg c]  }|j                   c}d|z   dz   dt        |      d	             y c c}w c c}w c c}w c c}w )	Nr   i  z%{text}<extra>z</extra>h)colornone)	r^   rQ   ybasetexthovertemplateorientationmarkertextposition)rB   	add_tracer   Barr   r   total_secondsr   	isoformatr   dict)r#   rw   r^   rq   rr   s        r   rl   rl      s    
4yA~MM
FJK

QWW$335<K!%&Aqxx&/34!!''##%4'+,!!++,*T1J>e$
	
 L&4,s   1C&C?!C$&C)r]   )r*   r   r%   
int | Nonereturn'go.Figure')r*   r   r   r   )r*   r   r7   zdatetime.timedelta | Noner   r   )r*   r   r%   r   r   r!   )r+   r!   r   r   )
r#   r"   rw   r   r^   r   rq   z	go.Figurer   None)
__future__r   r4   typingr   optuna.loggingr   optuna.samplers._baser   optuna.studyr   optuna.trialr   $optuna.visualization._plotly_importsr	   optuna.visualization._utilsr
   is_successfulr   r   rK   r   r!   r,   r8   r3   r(   r)   rl   r   r   r   <module>r      st    "   % 2  # 9 7 87
X
z !J !$6$ +\>r   