U
    9%ejq                     @   s  d dl Z d dlZd dlmZ d dlZd dlmZmZ d dlm	Z	m
Z
mZ d dlmZ G dd dZdd	 ZG d
d deZeddgd d gdZeddgd d gdZeddgd d gdZG dd deZedgdgdedgdgdgdgdgdgdgdgdgdgg
edddd d!d"d#d$d%d&g
d'Zed(gdgdgedggedgd'ZG d)d* d*eZed+d,gd-d.gd/d0ZG d1d2 d2eZed3gd4 d5d6d7d8d9d:d;gd<d0ZG d=d> d>eZed?d?gd@gdAdBgdCZG dDdE dEeZdFZe e!dGgdF dHgdF Z"ee"dIgdJdJdKdJdJdLgdCZ#G dMdN dNeZ$e$d3d3gdOgdPdPgdCZ%G dQdR dReZ&e&d+dSgdddCZ'dbdXdYZ(G dZd[ d[Z)G d\d] d]Z*G d^d_ d_Z+G d`da daZ,dS )c    N)assert_allclose)raiseswarns)shgoBoundsminimize)SHGOc                   @   s   e Zd ZdddZdS )StructTestFunctionNc                 C   s"   || _ || _|| _|| _|| _d S Nbounds
expected_xexpected_funexpected_xlexpected_funl)selfr   r   r   r   r    r   ^/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/scipy/optimize/tests/test__shgo.py__init__   s
    zStructTestFunction.__init__)NNN)__name__
__module____qualname__r   r   r   r   r   r	   
   s       r	   c                 C   sX   g }| d k	rPt | tk	r,t | tk	r,| f} n | D ]} |d| d q0t|}nd }|S )NZineq)typefun)r   tuplelistappend)gconsr   r   r   wrap_constraints   s    

r   c                   @   s$   e Zd Zdd Zdd ZeeZdS )StructTest1c                 C   s   |d d |d d  S Nr         r   r   xr   r   r   f%   s    zStructTest1.fc                 C   s   t j| ddd  S )Nr   Zaxisg      @numpysumr%   r   r   r   r   (   s    zStructTest1.gNr   r   r   r&   r   r   r   r   r   r   r   r    $   s   r    )   )r   r   )r   r#   )NNc                   @   s(   e Zd ZdZdd Zdd ZeeZdS )StructTest2zN
    Scalar function with several minima to test all minimizer retrievals
    c                 C   s   |d t | S )N   )r)   sinr$   r   r   r   r&   ;   s    zStructTest2.fc                 C   s   dt j| dd S )N:   r   r'   r(   r+   r   r   r   r   >   s    zStructTest2.gNr   r   r   __doc__r&   r   r   r   r   r   r   r   r/   6   s   r/   )r   <   g⡽4$?g0_r<g GK@g
]<@gI{_H@gi<&,@g>E@gqŤCQ4@g8$B@go.n:@g^5	>@gs8g^V&+6g+?-2g+!/gN|1(gc=C#g^\gNg自ݿr   )r   g      @c                   @   s8   e Zd ZdZdd Zdd Zdd ZeefZeeZ	dS )	StructTest3a  
    Hock and Schittkowski 18 problem (HS18). Hoch and Schittkowski (1981)
    http://www.ai7.uni-bayreuth.de/test_problem_coll.pdf
    Minimize: f = 0.01 * (x_1)**2 + (x_2)**2

    Subject to: x_1 * x_2 - 25.0 >= 0,
                (x_1)**2 + (x_2)**2 - 25.0 >= 0,
                2 <= x_1 <= 50,
                0 <= x_2 <= 50.

    Approx. Answer:
        f([(250)**0.5 , (2.5)**0.5]) = 5.0


    c                 C   s   d|d d  |d d  S )Ng{Gz?r   r"   r#   r   r$   r   r   r   r&   s   s    zStructTest3.fc                 C   s   | d | d  d S )Nr   r#         9@r   r+   r   r   r   g1v   s    zStructTest3.g1c                 C   s   | d d | d d  d S )Nr   r"   r#   r7   r   r+   r   r   r   g2y   s    zStructTest3.g2N)
r   r   r   r4   r&   r8   r9   r   r   r   r   r   r   r   r6   b   s   r6   )r"   2   )r   r:   g'In/@gS[:XL?      @)r   r   r   c                   @   sL   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d ZeeeefZ	e
e	ZdS )StructTest4z
    Hock and Schittkowski 11 problem (HS11). Hoch and Schittkowski (1981)

    NOTE: Did not find in original reference to HS collection, refer to
          Henderson (2015) problem 7 instead. 02.03.2016
    c                 C   s   |d d d d|d d d   |d d  d|d d	 d   d|d d
   d|d d   |d
 d  d|d  |d
   d|d   d|d
   S )Nr   
   r"      r#               r.         r   r$   r   r   r   r&      s&    .

zStructTest4.fc                 C   sJ   d| d d  d| d d   | d  d| d d   d| d   d  S )Nr"   r   rA   r#   r@   r>      r   r+   r   r   r   r8      s
    6
zStructTest4.g1c                 C   s>   d| d  d| d   d| d d   | d  | d  d  S )	NrC   r   rA   r#   r=   r"   r@   g     q@r   r+   r   r   r   r9      s    zStructTest4.g2c                 C   s:   d| d  | d d  d| d d   d| d   d  S )	N   r   r#   r"   r.   r>   rD      r   r+   r   r   r   g3   s    zStructTest4.g3c                 C   sZ   d| d d  | d d  d| d  | d   d| d d   d| d   d| d    S )	Nr@   r   r"   r#   rA   r>   rB   r.   r   r+   r   r   r   g4   s
    >

zStructTest4.g4Nr   r   r   r4   r&   r8   r9   rH   rI   r   r   r   r   r   r   r   r<      s   r<   )ir=   rC   gܤ@g$H8?g	޿g0ev@gn8)gk_@/?g0g+?gP{[
E@c                   @   s    e Zd Zdd ZdZeeZdS )StructTest5c              
   C   sb   |d d  t t t|d d |d d   |d t t t|d |d d    S )Nr#   g     G@r          @)r)   r1   sqrtabsr$   r   r   r   r&      s
    &*zStructTest5.fNr,   r   r   r   r   rK      s   rK   )i i   g g      @gyCy@)r   r   r   c                   @   s$   e Zd ZdZdd ZdZeeZdS )StructTestLJzV
    LennardJones objective function. Used to test symmetry constraints settings.
    c                 G   s   |d | _ t| j d }d}t|d D ]}t|d |D ]}d| }d| }|| ||  }	||d  ||d   }
||d  ||d   }|	|	 |
|
  ||  }|| | }|dkr:|d| d | 7 }q:q(|S )Nr   rA           r#   r"         ?rL   )Nintrange)r   r%   argsksijabZxdZydZzdZedZudr   r   r   r&      s    
zStructTestLJ.fNr3   r   r   r   r   rO      s   rO   r.   g      g      @      g/Ur]g) g=S c                   @   s    e Zd Zdd ZdZeeZdS )StructTestTablec                 C   s$   |d dkr|d dkrdS dS d S )Nr         @r#   r:   d   r   r$   r   r   r   r&      s    zStructTestTable.fNr,   r   r   r   r   r]      s   r]   r:   r^   c                   @   sL   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d ZeeeefZ	e
e	ZdS )StructTestInfeasiblez0
    Test function with no feasible domain.
    c                 G   s   |d d |d d  S r!   r   )r   r%   rU   r   r   r   r&      s    zStructTestInfeasible.fc                 C   s   | d | d  d S Nr   r#   r   r+   r   r   r   r8     s    zStructTestInfeasible.g1c                 C   s   | d | d  d  S ra   r   r+   r   r   r   r9     s    zStructTestInfeasible.g2c                 C   s   | d  | d  d S ra   r   r+   r   r   r   rH     s    zStructTestInfeasible.g3c                 C   s   | d  | d  d  S ra   r   r+   r   r   r   rI     s    zStructTestInfeasible.g4NrJ   r   r   r   r   r`      s   r`   )r-   r#   r   h㈵>   sobolc	           
      C   s   t | j| j|| j||||||d
}	t|	 | jd k	rNtjj	|	j
| j||d | jd k	rntjj	|	j| j|d | jd k	rtjj	|	j| j|d | jd k	rtjj	|	j| j|d d S )N)rU   constraintsniterscallbackminimizer_kwargsoptionssampling_methodZrtolatolrm   )r   r&   r   r   logginginfor   r)   testingr   r%   r   r   r   Zxlr   Zfunl)
testrU   	test_atolrf   rg   rh   ri   rj   rk   resr   r   r   run_test  s<       







ru   c                   @   s`   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	e
jjdd Zdd Zdd ZdS )TestShgoSobolTestFunctionsz8
    Global optimization tests with Sobol sampling:
    c                 C   s   t t dS )VMultivariate test function 1:
        x[0]**2 + x[1]**2 with bounds=[(-1, 6), (-1, 6)]Nru   test1_1r   r   r   r   test_f1_1_sobol@  s    z*TestShgoSobolTestFunctions.test_f1_1_sobolc                 C   s   t t dS )zUMultivariate test function 1:
         x[0]**2 + x[1]**2 with bounds=[(0, 1), (0, 1)]Nru   test1_2rz   r   r   r   test_f1_2_sobolE  s    z*TestShgoSobolTestFunctions.test_f1_2_sobolc                 C   s   t t dS )z_Multivariate test function 1:
        x[0]**2 + x[1]**2 with bounds=[(None, None),(None, None)]Nru   test1_3rz   r   r   r   test_f1_3_sobolJ  s    z*TestShgoSobolTestFunctions.test_f1_3_sobolc                 C   s   t t dS )RUnivariate test function on
        f(x) = (x - 30) * sin(x) with bounds=[(0, 60)]Nru   test2_1rz   r   r   r   test_f2_1_sobolO  s    z*TestShgoSobolTestFunctions.test_f2_1_sobolc                 C   s   t t dS )NUnivariate test function on
        f(x) = (x - 30) * sin(x) bounds=[(0, 4.5)]Nru   test2_2rz   r   r   r   test_f2_2_sobolT  s    z*TestShgoSobolTestFunctions.test_f2_2_sobolc                 C   s   t t dS )%NLP: Hock and Schittkowski problem 18Nru   test3_1rz   r   r   r   test_f3_sobolY  s    z(TestShgoSobolTestFunctions.test_f3_sobolc                 C   s   ddi}t td|d dS )?NLP: (High-dimensional) Hock and Schittkowski 11 problem (HS11)infty_constraintsFi   rf   rj   Nru   test4_1r   rj   r   r   r   test_f4_sobol]  s    z(TestShgoSobolTestFunctions.test_f4_sobolc                 C   s   t tdd dS )NLP: Eggholder, multimodal@   )rf   Nru   test5_1rz   r   r   r   test_f5_1_sobole  s    z*TestShgoSobolTestFunctions.test_f5_1_sobolc                 C   s   t tddd dS )r   rc   r>   )rf   rg   Nr   rz   r   r   r   test_f5_2_soboli  s    z*TestShgoSobolTestFunctions.test_f5_2_sobolN)r   r   r   r4   r{   r~   r   r   r   r   pytestmarkslowr   r   r   r   r   r   r   rv   :  s   
rv   c                   @   sX   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	e
jjdd Zdd ZdS )TestShgoSimplicialTestFunctionsz=
    Global optimization tests with Simplicial sampling:
    c                 C   s   t tddd dS )rw   r#   
simplicialrf   rk   Nrx   rz   r   r   r   test_f1_1_simplicialx  s    z4TestShgoSimplicialTestFunctions.test_f1_1_simplicialc                 C   s   t tddd dS )zTMultivariate test function 1:
        x[0]**2 + x[1]**2 with bounds=[(0, 1), (0, 1)]r#   r   r   Nr|   rz   r   r   r   test_f1_2_simplicial}  s    z4TestShgoSimplicialTestFunctions.test_f1_2_simplicialc                 C   s   t tddd dS )z_Multivariate test function 1: x[0]**2 + x[1]**2
        with bounds=[(None, None),(None, None)]r#   r   r   Nr   rz   r   r   r   test_f1_3_simplicial  s    z4TestShgoSimplicialTestFunctions.test_f1_3_simplicialc                 C   s   ddi}t td|dd dS )r   minimize_every_iterFrC   r   )rg   rj   rk   Nr   r   r   r   r   test_f2_1_simplicial  s    z4TestShgoSimplicialTestFunctions.test_f2_1_simplicialc                 C   s   t tddd dS )r   r#   r   r   Nr   rz   r   r   r   test_f2_2_simplicial  s    z4TestShgoSimplicialTestFunctions.test_f2_2_simplicialc                 C   s   t tddd dS )r   r#   r   r   Nr   rz   r   r   r   test_f3_simplicial  s    z2TestShgoSimplicialTestFunctions.test_f3_simplicialc                 C   s   t tddd dS )r   r#   r   r   Nr   rz   r   r   r   test_f4_simplicial  s    z2TestShgoSimplicialTestFunctions.test_f4_simplicialc                 C   s&   ddd}d}t t|d|ddd dS )z&LJ: Symmetry-constrained test functionT)Zsymmetrydisp)r.   Nr@   r   )rU   rf   rj   rg   rk   )ru   testLJ)r   rj   rU   r   r   r   test_lj_symmetry  s     z0TestShgoSimplicialTestFunctions.test_lj_symmetryN)r   r   r   r4   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   s  s   
r   c                   @   s  e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	e
jjdd Ze
jjdd Ze
jjdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 Zd5d6 Z d7d8 Z!d9S ):TestShgoArgumentsc                 C   s   t tdddd dS )z>Iterative simplicial sampling on TestFunction 1 (multivariate)Nr"   r   rf   rg   rk   r|   rz   r   r   r   test_1_1_simpl_iter  s    z%TestShgoArguments.test_1_1_simpl_iterc                 C   s   ddi}t tdd|dd dS )z3Iterative simplicial on TestFunction 2 (univariate)r   FNrC   r   rf   rg   rj   rk   r   r   r   r   r   test_1_2_simpl_iter  s    
z%TestShgoArguments.test_1_2_simpl_iterc                 C   s   t tdddd dS )z9Iterative Sobol sampling on TestFunction 1 (multivariate)Nr#   rd   r   r|   rz   r   r   r   test_2_1_sobol_iter  s    z%TestShgoArguments.test_2_1_sobol_iterc                 C   sL   t tjtjtjdddd}tjj|jtj	ddd tjj|j
tjdd dS )z7Iterative Sobol sampling on TestFunction 2 (univariate)Nr#   rd   )re   rf   rg   rk   rb   rl   rn   )r   r   r&   r   r   r)   rq   r   r%   r   r   r   r   rt   r   r   r   test_2_2_sobol_iter  s      z%TestShgoArguments.test_2_2_sobol_iterc              	   C   sR   dd }t tfD ]<}t|j|jdd|ddid t|j|jdd|ddid qd	S )
zCIterative sampling on TestFunction 1 and 2  (multi- and univariate)c                 S   s   t d d S Nz Local minimization callback testprintr+   r   r   r   callback_func  s    zATestShgoArguments.test_3_1_disp_simplicial.<locals>.callback_funcr#   r   r   Trg   rk   rh   rj   rf   rk   rh   rj   Nry   r   r   r&   r   r   r   rr   r   r   r   test_3_1_disp_simplicial  s      z*TestShgoArguments.test_3_1_disp_simplicialc              	   C   sR   dd }t tfD ]<}t|j|jdd|ddid t|j|jdd|ddid	 qd
S )zBIterative sampling on TestFunction 1 and 2 (multi- and univariate)c                 S   s   t d d S r   r   r+   r   r   r   r     s    z<TestShgoArguments.test_3_2_disp_sobol.<locals>.callback_funcr#   rd   r   Tr   r   r   Nr   r   r   r   r   test_3_2_disp_sobol  s      z%TestShgoArguments.test_3_2_disp_sobolc                 C   sF   t dd dgdd}t dd dgd}t|j|j t|j|j d S )Nc                 S   s   | | | S r
   r   )r%   yzr   r   r   <lambda>      z5TestShgoArguments.test_args_gh14589.<locals>.<lambda>)r   rA   )r#   r"   )funcr   rU   c                 S   s   d|  d S )Nr"   r#   r   r+   r   r   r   r     r   )r   r   )r   r   r   r%   )r   rt   refr   r   r   test_args_gh14589  s    z#TestShgoArguments.test_args_gh14589c                 C   s$   t jddd}tt dd|dd dS )z,Test known function minima stopping criteriaư>T)f_minf_tolr   Nrb   r   rf   rs   rj   rk   r   r   ru   r   r   r   r   test_4_1_known_f_min  s    
z&TestShgoArguments.test_4_1_known_f_minc                 C   s&   t jdddd}tt dd|dd dS )	*Test Global mode limiting local evalutionsr   Tr#   )r   r   r   
local_iterNrb   r   r   r   r   r   r   r   test_4_2_known_f_min  s    
z&TestShgoArguments.test_4_2_known_f_minc                 C   s(   t jddddd}tt dd|dd	 d
S )r   r   Tr#   Fr   r   r   r   r   i   rb   rd   r   Nr   r   r   r   r   test_4_3_known_f_min  s    
z&TestShgoArguments.test_4_3_known_f_minc              	   C   sJ   t jddddd}tt jt jt jdd|dd}tjj|j	t j
d	d	d
 dS )z<Test Global mode limiting local evalutions for 1-D functionsr   Tr#   Fr   Nrd   re   rf   rg   rj   rk   rb   rl   )r   r   r   r&   r   r   r)   rq   r   r%   r   r   rj   rt   r   r   r   test_4_4_known_f_min  s      z&TestShgoArguments.test_4_4_known_f_minc                 C   s0   t tjtjtjd}tjj|jtj	ddd dS )z;Test Default simplicial sampling settings on TestFunction 1re   rb   rl   N
r   ry   r&   r   r   r)   rq   r   r%   r   r   r   r   r   test_5_1_simplicial_argless  s    z-TestShgoArguments.test_5_1_simplicial_arglessc                 C   s2   t tjtjtjdd}tjj|jtj	ddd dS )z6Test Default sobol sampling settings on TestFunction 1rd   )re   rk   rb   rl   Nr   r   r   r   r   test_5_2_sobol_argless  s    z(TestShgoArguments.test_5_2_sobol_arglessc                 C   sR   ddi}t tjtjtj|dd}tjj|jtj	ddd tjj|j
tjdd dS )	:Test that maximum iteration option works on TestFunction 3Zmax_iterr"   r   re   rj   rk   rb   rl   rn   Nr   r   r&   r   r   r)   rq   r   r%   r   r   r   r   r   r   r   test_6_1_simplicial_max_iter#  s     z.TestShgoArguments.test_6_1_simplicial_max_iterc                 C   sR   ddi}t tjtjtj|dd}tjj|jtj	ddd tjj|j
tjdd dS )	r   Zmin_iterr"   r   r   rb   rl   rn   Nr   r   r   r   r   test_6_2_simplicial_min_iter,  s     z.TestShgoArguments.test_6_2_simplicial_min_iterc                 C   sB   dD ]8}|t jd}td| td tt dd|dd qd	S )
z@Test the minimizer_kwargs arguments for solvers with constraints)ZCOBYLAZSLSQP)methodre   Solver = {}d====================================================================================================rc   MbP?rd   rf   rs   ri   rk   N)r   r   r   formatru   )r   solverri   r   r   r   test_7_1_minkwargs5  s     z$TestShgoArguments.test_7_1_minkwargsc                 C   s0   ddi}ddi}t tjtjtjd ||d dS )z'Test the minimizer_kwargs default initsZftolrb   r   Tr   )re   ri   rj   Nr   r   r&   r   r   )r   ri   rj   r   r   r   test_7_2_minkwargsB  s     z$TestShgoArguments.test_7_2_minkwargsc                 C   sV   dD ]L}dd }dd }|||d}t d| t d ttd	d
|dd qdS )z?Test minimizer_kwargs arguments for solvers without constraints)zNelder-MeadZPowellZCGZBFGSz	Newton-CGzL-BFGS-BZTNCZdoglegz	trust-ncgztrust-exactztrust-krylovc                 S   s    t d| d  d| d  gjS )Nr"   r   r#   )r)   arrayTr+   r   r   r   jacN  s    z1TestShgoArguments.test_7_3_minkwargs.<locals>.jacc                 S   s   t ddgddggS )Nr"   r   )r)   r   r+   r   r   r   hessQ  s    z2TestShgoArguments.test_7_3_minkwargs.<locals>.hess)r   r   r   r   r   rc   r   rd   r   N)ro   rp   r   ru   ry   )r   r   r   r   ri   r   r   r   test_7_3_minkwargsI  s    
 z$TestShgoArguments.test_7_3_minkwargsc                 C   s    ddd}t td d |dd d S )Nr#   T)Zminhgrdr   r   r   rx   r   r   r   r   test_8_homology_group_diff\  s    
z,TestShgoArguments.test_8_homology_group_diffc                 C   s   t tjtjtjd d dS )'Test single function constraint passingr   r   Nr   rz   r   r   r   test_9_cons_gc  s    zTestShgoArguments.test_9_cons_gc                 C   s$   ddi}t tjtjdd|dd dS )r   maxtimeV瞯<r#   Nrd   r   )r   ry   r&   r   r   r   r   r   test_10_finite_timeg  s
     z%TestShgoArguments.test_10_finite_timec                 C   s&   ddd}t tjtjdd|dd dS z*Test to cover the case where f_lowest == 0r   rP   )r   r   r#   Nrd   r   r   r}   r&   r   r   r   r   r   test_11_f_min_timem  s     z$TestShgoArguments.test_11_f_min_timec                 C   s&   ddd}t tjtjdd|dd dS r   r   r   r   r   r   test_12_sobol_inf_const  s     z(TestShgoArguments.test_12_sobol_inf_consc                 C   s   ddi}t td|d dS )z6Test limited local iterations for a pseudo-global moder   r@   r   r   Nr   r   r   r   r   test_14_local_iter{  s    z$TestShgoArguments.test_14_local_iterc                 C   s   ddi}t tdd|dd dS )z9Test minimize every iter options and cover function cacher   Tr#   rC   rd   r   Nrx   r   r   r   r   test_15_min_every_iter  s    
z(TestShgoArguments.test_15_min_every_iterc                 C   s$   ddi}ddi}t td||d dS )z:Test disp=True with minimizers that do not support bounds r   Tr   znelder-meadr   )rk   rj   ri   Nr|   )r   rj   ri   r   r   r   test_16_disp_bounds_minimizer  s     z/TestShgoArguments.test_16_disp_bounds_minimizerc                 C   s   dd }t td|d dS )z=Test the functionality to add custom sampling methods to shgoc                 S   s   t jj| |fdS )N)size)r)   randomuniform)rf   dr   r   r   sample  s    z9TestShgoArguments.test_17_custom_sampling.<locals>.sampler0   r   Nrx   )r   r   r   r   r   test_17_custom_sampling  s    z)TestShgoArguments.test_17_custom_samplingc           	      C   s   dd }dddg}dddg}t t||}t||}t||}t||}|j|jksXt|j|jksht|j|jksxtt	ddd	g}tj
|j| tj
|j|j d S )
Nc                 S   s   t |  S r
   )r)   Zsquarer*   r+   r   r   r   r&     s    z1TestShgoArguments.test_18_bounds_class.<locals>.fg      rQ   g      r\   r^   r;   rP   )r   zipr   r   nfevAssertionErrormessagesuccessr)   r   rq   r   r%   )	r   r&   ZlbZubZ
bounds_oldZ
bounds_newZres_old_boundsZres_new_boundsZx_optr   r   r   test_18_bounds_class  s    





z&TestShgoArguments.test_18_bounds_classN)"r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r   r   r   r   r     s>   	



		r   c                   @   sx   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zejddddgdd ZdS )TestShgoFailuresc                 C   sD   ddi}t tjtjdd|dd}tjd|j tjd|j dS )z'Test failure on insufficient iterationsmaxiterr"   r@   Nrd   r   F)	r   r   r&   r   r)   rq   assert_equalr  r   r   r   r   r   test_1_maxiter  s     zTestShgoFailures.test_1_maxiterc                 C   s   t tttjtjdd dS )z$Rejection of unknown sampling methodZ	not_Sobol)rk   N)assert_raises
ValueErrorr   ry   r&   r   rz   r   r   r   test_2_sampling  s    z TestShgoFailures.test_2_samplingc                 C   sD   ddd}t tjtjd|dd}tjd|j tjd|j d	S )
zoCheck that the routine stops when no minimiser is found
           after maximum specified function evaluationsr=   T)Zmaxfevr   r@   rd   rf   rj   rk   F   N)	r   
test_tabler&   r   r)   rq   r  r  r   r   r   r   r   test_3_1_no_min_pool_sobol  s    z+TestShgoFailures.test_3_1_no_min_pool_sobolc                 C   s4   ddd}t tjtjd|dd}tjd|j dS )	zoCheck that the routine stops when no minimiser is found
           after maximum specified sampling evaluationsr=   Tmaxevr   rA   r   r  FN)r   r  r&   r   r)   rq   r  r  r   r   r   r   test_3_2_no_min_pool_simplicial  s    z0TestShgoFailures.test_3_2_no_min_pool_simplicialc                 C   s   ddg}t tttj| dS )zSpecified bounds ub > lb)r.   rA   rA   r>   Nr  r	  r   ry   r&   r   r   r   r   r   test_4_1_bound_err  s    z#TestShgoFailures.test_4_1_bound_errc                 C   s   ddg}t tttj| dS )z)Specified bounds are of the form (lb, ub))rA   r>   r>   r  Nr  r  r   r   r   test_4_2_bound_err  s    z#TestShgoFailures.test_4_2_bound_errc                 C   s8   ddd}t tjtjtjd|dd}tjd|j dS )zxEnsures the algorithm terminates on infeasible problems
           after maxev is exceeded. Use infty constraints optionr   Tr  rd   re   rf   rj   rk   FN	r   test_infeasibler&   r   r   r)   rq   r  r  r   r   r   r   test_5_1_1_infeasible_sobol  s    
  z,TestShgoFailures.test_5_1_1_infeasible_sobolc                 C   s:   dddd}t tjtjtjd|dd}tjd|j dS )zEnsures the algorithm terminates on infeasible problems
           after maxev is exceeded. Do not use infty constraints optionr   TF)r  r   r   rd   r  Nr  r   r   r   r   test_5_1_2_infeasible_sobol  s    
  z,TestShgoFailures.test_5_1_2_infeasible_sobolc                 C   s8   ddd}t tjtjtjd|dd}tjd|j dS )z[Ensures the algorithm terminates on infeasible problems
           after maxev is exceeded.i  Fr  r_   r   r  Nr  r   r   r   r   test_5_2_infeasible_simplicial  s    
  z/TestShgoFailures.test_5_2_infeasible_simplicialc                 C   sJ   t jd ddddd}t jt jf}t jdd|dd	}tttf|| dS )
z;Test Global mode limiting local evalutions with f* too highrL   r   Tr#   Fr   Nrd   r   )r   r   r&   r   r   r   UserWarningr   )r   rj   rU   kwargsr   r   r   test_6_1_lower_known_f_min  s    z+TestShgoFailures.test_6_1_lower_known_f_min
derivativer   r   hesspc                 C   s   dd }dd }dd }dd }|||d	}||| i}d
di}dg}	t ||	||d}
t|fdg|	d||}|
jszttj|
j|j tj|
j|j dS )zzshgo used to raise an error when passing `options` with 'jac'
        # see gh-12829. check that this is resolved
        c                 S   s$   d| d  | d  d| d   d S )NrA   r   r"   r>   r   r+   r   r   r   	objective  s    z@TestShgoFailures.test_21_2_derivative_options.<locals>.objectivec                 S   s   d| d  d S )Nr.   r   r"   r   r+   r   r   r   gradient  s    z?TestShgoFailures.test_21_2_derivative_options.<locals>.gradientc                 S   s   dS Nr.   r   r+   r   r   r   r     s    z;TestShgoFailures.test_21_2_derivative_options.<locals>.hessc                 S   s   d| S r$  r   )r%   pr   r   r   r!    s    z<TestShgoFailures.test_21_2_derivative_options.<locals>.hessp)r   r   r!  r   ztrust-constr)ir_   )ri   rj   r   )Zx0r   N)	r   r   r  r   r)   rq   r   r   r%   )r   r   r"  r#  r   r!  Zderivative_funcsrj   ri   r   rt   r   r   r   r   test_21_2_derivative_options  s"    
z-TestShgoFailures.test_21_2_derivative_optionsN)r   r   r   r  r
  r  r  r  r  r  r  r  r  r   r   Zparametrizer&  r   r   r   r   r    s   		r  )r   rb   rc   NNNNrd   )-ro   r)   Znumpy.testingr   r   r   r  r   Zscipy.optimizer   r   r   Zscipy.optimize._shgor   r	   r   r    ry   r}   r   r/   r   r   r   r6   r   r<   r   rK   r   rO   rR   r   r   ZboundsLJr   r]   r  r`   r  ru   rv   r   r   r  r   r   r   r   <module>   s   

    
"
          
"94  