
    &`il                         d dl mZmZmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZmZ erd dlmZ e G d d                      Ze G d	 d
e                      ZdS )    )TYPE_CHECKINGDictOptionaltag_scheduler)Trial)DEFAULT_METRIC)DeveloperAPI	PublicAPI)TuneControllerc                   $   e Zd ZdZdZdZdZdZdZdZ	d Z
ed	             Zed
             Zdee         dee         defdZdddefdZdddefdZdddededefdZdddedefdZdddefdZdddee         fdZdefdZdefdZdefdZdS )TrialSchedulerzInterface for implementing a Trial Scheduler class.

    Note to Tune developers: If a new scheduler is added, please update
    `air/_internal/usage.py`.
    CONTINUEPAUSESTOPNOOPNTc                 $    t          |            d S Nr   selfs    w/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/tune/schedulers/trial_scheduler.py__init__zTrialScheduler.__init__!   s    d    c                     | j         S r   )_metricr   s    r   metriczTrialScheduler.metric$   s
    |r   c                     | j         S r   )_supports_buffered_resultsr   s    r   supports_buffered_resultsz(TrialScheduler.supports_buffered_results(   s    ..r   r   modereturnc                 T    | j         r|rdS |r|| _         | j         t          | _         dS )a  Pass search properties to scheduler.

        This method acts as an alternative to instantiating schedulers
        that react to metrics with their own `metric` and `mode` parameters.

        Args:
            metric: Metric to optimize
            mode: One of ["min", "max"]. Direction to optimize.
            **spec: Any kwargs for forward compatiblity.
                Info like Experiment.PUBLIC_KEYS is provided through here.
        FNT)r   r	   )r   r   r    specs       r   set_search_propertiesz$TrialScheduler.set_search_properties,   s=     < 	F 	5 	"!DL<)DLtr   tune_controllerr   trialc                     t           )z5Called when a new trial is added to the trial runner.NotImplementedErrorr   r%   r&   s      r   on_trial_addzTrialScheduler.on_trial_addE   
     "!r   c                     t           )znNotification for the error of trial.

        This will only be called when the trial is in the RUNNING state.r(   r*   s      r   on_trial_errorzTrialScheduler.on_trial_errorJ   s
    
 "!r   resultc                     t           )zCalled on each intermediate result returned by a trial.

        At this point, the trial scheduler can make a decision by returning
        one of CONTINUE, PAUSE, and STOP. This will only be called when the
        trial is in the RUNNING state.r(   r   r%   r&   r/   s       r   on_trial_resultzTrialScheduler.on_trial_resultQ   s
     "!r   c                     t           )zNotification for the completion of trial.

        This will only be called when the trial is in the RUNNING state and
        either completes naturally or by manual termination.r(   r1   s       r   on_trial_completez TrialScheduler.on_trial_complete\   
     "!r   c                     t           )zCalled to remove trial.

        This is called when the trial is in PAUSED or PENDING state. Otherwise,
        call `on_trial_complete`.r(   r*   s      r   on_trial_removezTrialScheduler.on_trial_removef   s
     "!r   c                     t           )zCalled to choose a new trial to run.

        This should return one of the trials in tune_controller that is in
        the PENDING or PAUSED state. This function must be idempotent.

        If no trial is ready, return None.r(   )r   r%   s     r   choose_trial_to_runz"TrialScheduler.choose_trial_to_runn   r5   r   c                     t           )z=Returns a human readable message for printing to the console.r(   r   s    r   debug_stringzTrialScheduler.debug_stringx   r,   r   checkpoint_pathc                     t           )z$Save trial scheduler to a checkpointr(   r   r<   s     r   savezTrialScheduler.save}       !!r   c                     t           )z(Restore trial scheduler from checkpoint.r(   r>   s     r   restorezTrialScheduler.restore   r@   r   )__name__
__module____qualname____doc__r   r   r   r   r   r   r   propertyr   r   r   strboolr$   r   r+   r.   r   r2   r4   r7   r9   r;   r?   rB    r   r   r   r      s         HED
 DG!%     X / / X/sm+3C=	   2",< "U " " " "
".> "u " " " "	"/	"8=	"GK	"		" 	" 	" 	""/"8="GK" " " ""/? " " " " ""3C "QV " " " ""c " " " "
"C " " " ""s " " " " " "r   r   c                        e Zd ZdZ fdZdddefdZdddefdZdddeded	e	fd
Z
dddedefdZdddefdZddd	ee         fdZd	e	fdZ xZS )FIFOSchedulerz;Simple scheduler that just runs trials in submission order.c                 H    t                                                       d S r   )superr   )r   	__class__s    r   r   zFIFOScheduler.__init__   s    r   r%   r   r&   c                     d S r   rJ   r*   s      r   r+   zFIFOScheduler.on_trial_add       r   c                     d S r   rJ   r*   s      r   r.   zFIFOScheduler.on_trial_error   rQ   r   r/   r!   c                     t           j        S r   )r   r   r1   s       r   r2   zFIFOScheduler.on_trial_result   s     &&r   c                     d S r   rJ   r1   s       r   r4   zFIFOScheduler.on_trial_complete   s	     	r   c                     d S r   rJ   r*   s      r   r7   zFIFOScheduler.on_trial_remove   rQ   r   c                     |                                 D ]}|j        t          j        k    r|c S |                                 D ]}|j        t          j        k    r|c S d S r   )
get_trialsstatusr   PENDINGPAUSEDr*   s      r   r9   z!FIFOScheduler.choose_trial_to_run   sw    $//11 	 	E|u},, -$//11 	 	E|u|++ ,tr   c                     dS )Nz Using FIFO scheduling algorithm.rJ   r   s    r   r;   zFIFOScheduler.debug_string   s    11r   )rC   rD   rE   rF   r   r   r+   r.   r   rH   r2   r4   r7   r   r9   r;   __classcell__)rO   s   @r   rL   rL      sJ       EE    ,< U    .> u    '/'8='GK'	' ' ' '
/8=GK   
/?     3C QV    2c 2 2 2 2 2 2 2 2r   rL   N)typingr   r   r   ray.air._internal.usager   ray.tune.experimentr   ray.tune.resultr	   ray.util.annotationsr
   r   "ray.tune.execution.tune_controllerr   r   rL   rJ   r   r   <module>rc      s	   0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 % % % % % % * * * * * * 8 8 8 8 8 8 8 8 BAAAAAA v" v" v" v" v" v" v" v"r #2 #2 #2 #2 #2N #2 #2 #2 #2 #2r   