
    -ji                    d    S SK Jr  S SKrS SKJr  S SKrS SKJr  S SKJ	r	  S	S jr
 " S S\5      rg)
    )annotationsN)Any)
BasePruner)_is_first_in_interval_stepc                     [        U 5      n U $ ! [        [        4 a&    S[        U 5      R                   S3n[        U5      S ef = f)Nz!The `value` argument is of type 'z' but supposed to be a float.)float	TypeError
ValueErrortype__name__)valuemessages     S/home/james-whalen/.local/lib/python3.13/site-packages/optuna/pruners/_threshold.py_check_valuer      sY    +e L z" +/U0D0D/EEbc 	  d*	+s	    6Ac                  J    \ rS rSrSr    S         SS jjrS	S jrSrg)
ThresholdPruner   a2  Pruner to detect outlying metrics of the trials.

Prune if a metric exceeds upper threshold,
falls behind lower threshold or reaches ``nan``.

Example:
    .. testcode::

        from optuna import create_study
        from optuna.pruners import ThresholdPruner
        from optuna import TrialPruned


        def objective_for_upper(trial):
            for step, y in enumerate(ys_for_upper):
                trial.report(y, step)

                if trial.should_prune():
                    raise TrialPruned()
            return ys_for_upper[-1]


        def objective_for_lower(trial):
            for step, y in enumerate(ys_for_lower):
                trial.report(y, step)

                if trial.should_prune():
                    raise TrialPruned()
            return ys_for_lower[-1]


        ys_for_upper = [0.0, 0.1, 0.2, 0.5, 1.2]
        ys_for_lower = [100.0, 90.0, 0.1, 0.0, -1]

        study = create_study(pruner=ThresholdPruner(upper=1.0))
        study.optimize(objective_for_upper, n_trials=10)

        study = create_study(pruner=ThresholdPruner(lower=0.0))
        study.optimize(objective_for_lower, n_trials=10)

Args:
    lower:
        A minimum value which determines whether pruner prunes or not.
        If an intermediate value is smaller than lower, it prunes.
    upper:
        A maximum value which determines whether pruner prunes or not.
        If an intermediate value is larger than upper, it prunes.
    n_warmup_steps:
        Pruning is disabled if the step is less than the given number of warmup steps.
    interval_steps:
        Interval in number of steps between the pruning checks, offset by the warmup steps.
        If no value has been reported at the time of a pruning check, that particular check
        will be postponed until a value is reported. Value must be at least 1.

Nc                D   Uc  Uc  [        S5      eUb  [        U5      nUb  [        U5      nUb  UO[        S5      * nUb  UO
[        S5      nX:  a  [        S5      eUS:  a  [        SU S35      eUS:  a  [        SU S35      eXl        X l        X0l        X@l        g )	Nz(Either lower or upper must be specified.infz#lower should be smaller than upper.r   z2Number of warmup steps cannot be negative but got .   z2Pruning interval steps must be at least 1 but got )r	   r   r   r
   _lower_upper_n_warmup_steps_interval_steps)selfloweruppern_warmup_stepsinterval_stepss        r   __init__ThresholdPruner.__init__Q   s     =U]FGG 'E 'E*u*e=BCCAD^DTTUV  AD^DTTUV  --    c                F   UR                   nUc  gU R                  nX4:  a  g[        X2R                  R	                  5       X@R
                  5      (       d  gUR                  U   n[        R                  " U5      (       a  gXPR                  :  a  gXPR                  :  a  gg)NFT)
	last_stepr   r   intermediate_valueskeysr   mathisnanr   r   )r   studytrialstepr   latest_values         r   pruneThresholdPruner.pruner   s    <-- )++002NDXDX
 
 006::l##++%++%r#   )r   r   r   r   )NNr   r   )
r   float | Noner   r0   r   intr    r1   returnNone)r*   z'optuna.study.Study'r+   z'optuna.trial.FrozenTrial'r2   bool)r   
__module____qualname____firstlineno____doc__r!   r.   __static_attributes__ r#   r   r   r      sQ    6t #".. . 	.
 . 
.Br#   r   )r   r   r2   r   )
__future__r   r(   typingr   optunaoptuna.prunersr   optuna.pruners._percentiler   r   r   r:   r#   r   <module>r@      s*    "    % A
rj rr#   