o
    ciu                     @   s   d Z ddl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 Z
d	d
 ZdddZedkrWddlZe Zejdddd e \ZZejdd eejd dS dS )a2  This example demonstrates the usage of Optuna with Ray Tune.

It also checks that it is usable with a separate scheduler.

Requires the Optuna library to be installed (`pip install optuna`).

For an example of using an Optuna define-by-run function, see
:doc:`/tune/examples/optuna_define_by_run_example`.
    N)tune)AsyncHyperBandScheduler)ConcurrencyLimiter)OptunaSearchc                 C   s   d||  d  d |d  S )N皙?d    )stepwidthheightr	   r	   T/home/ubuntu/.local/lib/python3.10/site-packages/ray/tune/examples/optuna_example.pyevaluation_fn   s   r   c                 C   sN   | d | d }}t | d D ]}t|||}t||d td qd S )Nr   r   steps)
iterations	mean_lossr   )ranger   r   reporttimesleep)configr   r   r
   intermediate_scorer	   r	   r   easy_objective   s   r   Fc              
   C   s   t  }t|dd}t }tjttjdd||| rdndddtdd	td
dtddgdd}|	 }t
d| j d S )N   )max_concurrentr   min
   r   )metricmode
search_alg	schedulernum_samplesr      irelutanh)r   r   r   
activation)tune_configparam_spacez!Best hyperparameters found were: )r   r   r   r   Tunerr   
TuneConfiguniformchoicefitprintget_best_resultr   )
smoke_testalgor    tunerresultsr	   r	   r   run_optuna_tune$   s(   


r3   __main__z--smoke-test
store_truezFinish quickly for testing)actionhelp)configure_logging)r/   )F)__doc__r   rayr   ray.tune.schedulersr   ray.tune.searchr   ray.tune.search.optunar   r   r   r3   __name__argparseArgumentParserparseradd_argumentparse_known_argsargs_initr/   r	   r	   r	   r   <module>   s(    

