o
    ci                     @   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 Zdd	 Z	dddZ
edkrQd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 )zThis example demonstrates the usage of Optuna with Ray Tune for
multi-objective optimization.

Please note that schedulers may not work correctly with multi-objective
optimization.

Requires the Optuna library to be installed (`pip install optuna`).
    N)tune)ConcurrencyLimiter)OptunaSearchc                 C   s   d||  d  d |d  S )N皙?d    )stepwidthheightr   r   c/home/ubuntu/.local/lib/python3.10/site-packages/ray/tune/examples/optuna_multiobjective_example.pyevaluation_fn   s   r   c                 C   sT   | d | d }}t | d D ]}t|||}t|||| d td qd S )Nr
   r   steps)
iterationslossgainr   )ranger   r   reporttimesleep)configr
   r   r	   intermediate_scorer   r   r   easy_objective   s   r   Fc              
   C   s   t ddgddgd}t|dd}tjttj|| rdnd	d
d	tddtdd	tddgdd}| }t	d|
ddj t	d|
ddj d S )Nr   r   minmax)metricmode   )max_concurrent
   r   )
search_algnum_samplesr      irelutanh)r   r
   r   
activation)tune_configparam_spacez*Best hyperparameters for loss found were: z*Best hyperparameters for gain found were: )r   r   r   Tunerr   
TuneConfiguniformchoicefitprintget_best_resultr   )
smoke_testalgo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.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&    
