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ed
krddlZe Zejdddd e \ZZe	dgdgdZejjeddZe ZejeejdddidejddeeejrgdndddeddeddeddeddeddeddddZe Ze d e! j" dS dS )!zThis example demonstrates the usage of AxSearch with Ray Tune.

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

Requires the Ax library to be installed (`pip install ax-platform`).
    N)tune)AsyncHyperBandScheduler)AxSearchc           	      C   s   t g d}t g dg dg dg dg}dt g dg dg d	g d
g }d}t|D ]+\}}d}tdD ]}||||f | | |||f  d  7 }q;||t |  8 }q1|S )N)      ?g333333?g      @g	@)
               @333333?   )皙?r   r   皙?r      )r   r	   r
   r   r   r   )r   r   r   r   r   r   g-C6?)i   i  i  |   i[   i  )i	  i'  is   i  i  i'  )i,	  i  i  iC  i  i  )i  i|"  i"  io  iC  i}          r         )nparray	enumeraterangeexp)	xalphaAPyjalpha_jtk r!   P/home/ubuntu/.local/lib/python3.10/site-packages/ray/tune/examples/ax_example.py	hartmann6   s,   *r#   c              	      s`   t  d D ]'}t fddt dD }t|t|t|d  d t	d qd S )N
iterationsc                    s    g | ]}  d |d qS )zx{}   )getformat).0iconfigr!   r"   
<listcomp>.   s     z"easy_objective.<locals>.<listcomp>r   r   )timesteps_totalr#   l2normg{Gz?)
r   r   r   r   reportr#   sqrtsumtimesleep)r+   r)   r   r!   r*   r"   easy_objective,   s   r4   __main__z--smoke-test
store_truezFinish quickly for testing)actionhelpzx1 + x2 <= 2.0zl2norm <= 1.25)parameter_constraintsoutcome_constraints   )max_concurrentaxr-   d   )namestopminr   2   )metricmode
search_alg	schedulernum_samplesr   r   )r$   x1x2x3x4x5x6)
run_configtune_configparam_spacez!Best hyperparameters found were: )#__doc__r2   numpyr   rayr   ray.tune.schedulersr   ray.tune.search.axr   r#   r4   __name__argparseArgumentParserparseradd_argumentparse_known_argsargs_algosearchConcurrencyLimiterrF   Tuner	RunConfig
TuneConfig
smoke_testuniformtunerfitresultsprintget_best_resultr+   r!   r!   r!   r"   <module>   s\    





