o
    h                    @   s   d 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 ddlmZmZmZ ddl	mZmZ ddlmZ dd	lmZ ddlZdd
lmZmZmZmZmZmZ ddlm Z!m"Z" ddlZG dd dZ#dS )z@
Unit tests for the differential global minimization algorithm.
    N)Pool)DifferentialEvolutionSolver_ConstraintWrapper)differential_evolutionOptimizeResult)BoundsNonlinearConstraintLinearConstraint)rosenminimize)
csr_matrix)stats)assert_equalassert_allcloseassert_almost_equalassert_string_equalassert_suppress_warnings)raiseswarnsc                   @   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	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+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 Zd5d6 Zd7d8 Zd9d: Zd;d< Z d=d> Z!d?d@ Z"dAdB Z#dCdD Z$dEdF Z%dGdH Z&dIdJ Z'dKdL Z(dMdN Z)e*j+j,dOdP Z-e*j+.dQdRdS Z/dTdU Z0dVdW Z1dXdY Z2e*j+j,dZd[ Z3e*j+.dQe*j+j,d\d] Z4d^d_ Z5d`da Z6dbdc Z7ddde Z8e*j+.dfdgdh Z9e*j+.dQdidj Z:e*j+.dQdkdl Z;e*j+.dQdmdn Z<e*j+.dQdodp Z=e*j+.dQdqdr Z>dsdt Z?e*j+j@e*j+jAeBC dukdvdwdxdy ZDe*j+.dzd{d| ZEe*j+.dQd}d~ ZFdd ZGe*j+j,e*j+.dQdd ZHdd ZIdd ZJe*j+.dfdd ZKdS )TestDifferentialEvolutionSolverc                 C   sx   t jdd| _t ddgddgg| _ddg| _t| jdg| _t| jdgdd	d
| _	t 
t dddj}|| j	_d S )Nraiseinvalid               @r   r   r   d   r               ?)popsizemutation皙?皙?)npseterr
old_seterrarraylimitsboundsr   	quadraticdummy_solverdummy_solver2
atleast_2darangeT
population)selfr3    r5   e/var/www/vscode/kcb/lib/python3.10/site-packages/scipy/optimize/tests/test__differential_evolution.pysetup_method   s   

z,TestDifferentialEvolutionSolver.setup_methodc                 C   s   t jdi | j d S )Nr5   )r'   r(   r)   r4   r5   r5   r6   teardown_method-   s   z/TestDifferentialEvolutionSolver.teardown_methodc                 C   s   |d d S )Nr      r5   )r4   xr5   r5   r6   r-   0   s   z)TestDifferentialEvolutionSolver.quadraticc                 C   s  t t| jdd}t|jd t|jjd t t| jdd}t|jd t|jjd t t| jdd}t|jd t|jjd t t| jdd}t|jd t|jjd t t| jdd}t|jd t|jjd	 t t| jd
d}t|jd
 t|jjd t t| jdd}t|jd t|jjd	 t t| jdd}t|jd t|jjd	 t t| jdd}t|jd t|jjd t t| jdd}t|jd t|jjd t t| jdd}t|jd t|jjd t t| jdd}t|jd t|jjd d S )Nbest1expstrategy_best1best1binrand1bin_rand1rand1exprand2exp_rand2best2bin_best2rand2binrandtobest1bin_randtobest1randtobest1expcurrenttobest1bin_currenttobest1currenttobest1exp)r   r
   r,   r   r>   mutation_func__name__r4   solverr5   r5   r6   test__strategy_resolves3   s   z7TestDifferentialEvolutionSolver.test__strategy_resolvesc                 C   \   t dg}| jt g d}t|| t dg}| jt g d}t|| d S )N皙?r:                     ?)r'   r*   r/   r?   r   rB   r4   resulttrialr5   r5   r6   test__mutate1~   s   
z-TestDifferentialEvolutionSolver.test__mutate1c                 C   rT   )NgrV   r%   )r'   r*   r/   rG   r   rE   r\   r5   r5   r6   test__mutate2   s   
z-TestDifferentialEvolutionSolver.test__mutate2c                 C   s0   t dg}| jt g d}t|| d S )Ng333333?rV   )r'   r*   r/   rJ   r   r\   r5   r5   r6   test__randtobest1   s   z1TestDifferentialEvolutionSolver.test__randtobest1c                 C   s2   t dg}| jdt g d}t|| d S )Nr%   r    rV   )r'   r*   r/   rM   r   r\   r5   r5   r6   test__currenttobest1   s   z4TestDifferentialEvolutionSolver.test__currenttobest1c                 C   s*   d}t | j| j|d}t|jt| d S )Nr"   r    r$   )r   r-   r,   r   ditherlist)r4   r$   rR   r5   r5   r6   test_can_init_with_dithering   s   z<TestDifferentialEvolutionSolver.test_can_init_with_ditheringc                 C   s   t }d}ttt|| j|d d}ttt|| j|d dtjf}ttt|| j|d d}t|| j|d}td|j td |j	 d S )N)r"   rW   rd   r    r%   r"   )
r
   assert_raises
ValueErrorr   r,   r'   nanr   scalere   )r4   funcr$   rR   r5   r5   r6   +test_invalid_mutation_values_arent_accepted   s:   
zKTestDifferentialEvolutionSolver.test_invalid_mutation_values_arent_acceptedc                 C   sH   dd }t tdd t|ddg W d    d S 1 sw   Y  d S )Nc                 S   s   t t | d t | gS Nr:   )r'   r*   sumr;   r5   r5   r6   rn      s   zETestDifferentialEvolutionSolver.test_invalid_functional.<locals>.funcz,func\(x, \*args\) must return a scalar valuematchr:   )rj   RuntimeErrorr   )r4   rn   r5   r5   r6   test_invalid_functional   s   "z7TestDifferentialEvolutionSolver.test_invalid_functionalc                 C   J   t dg}td| j| t dgdgg| j_td| j| d S )N333333?   r   r   )r'   r*   r   r.   _scale_parametersr+   r4   r^   r5   r5   r6   test__scale_parameters      z6TestDifferentialEvolutionSolver.test__scale_parametersc                 C   ry   )Nr{   rz   r   r   )r'   r*   r   r.   _unscale_parametersr+   r}   r5   r5   r6   test__unscale_parameters   r   z8TestDifferentialEvolutionSolver.test__unscale_parametersc                 C   sz   t jdd t| jddgd}|ddg}t|d W d    n1 s&w   Y  t| jddg}t|jdd	g d S )
Nr   r   r   r   )      ?      @)r,   r   r"   )r   r   r   )	r'   errstater   r-   r   r   r   r   r;   )r4   rR   vresr5   r5   r6   test_equal_bounds   s   z1TestDifferentialEvolutionSolver.test_equal_boundsc                 C   sH   t g d}| j| t|d d tt |dk|dk  d S )N)皙??r   g     r@gh㈵r:   r   r   r    )r'   r*   r.   _ensure_constraintr   r   logical_andallr}   r5   r5   r6   test__ensure_constraint   s    z7TestDifferentialEvolutionSolver.test__ensure_constraintc                 C   sd   t | jdgddd}| }t|j| |j t | jdgddd}| }t|j| |j d S )Nru   r    F)maxiterpolishT)r   r-   solver   funr;   r4   rR   r]   r5   r5   r6   test_differential_evolution   s   z;TestDifferentialEvolutionSolver.test_differential_evolutionc                 C   s(   t | jdg}| }t|j|j d S )Nru   )r   r-   r   r   r;   r   r5   r5   r6   test_best_solution_retrieval  s   z<TestDifferentialEvolutionSolver.test_best_solution_retrievalc                    sX  dfddd _ tj_ fdd d _d  _ _ddg}t|dd	d
}tdi |d i}tdi |di}|j	|j	  u rNd	u sQJ  J  j|j  kr^ksaJ  J |j
dkshJ |j
dksoJ | D ]\}}|dv r|qst j| | t|| | qsd _tj_d|d< tdi |d i}|j|jk sJ d S )N
   c                    s"   t | }| jk r|  _| _|S N)r
   valr;   )r;   r   rn   r5   r6   rn     s
   
zFTestDifferentialEvolutionSolver.test_intermediate_result.<locals>.funcc                    s    j d7  _ |  _| jjdksJ | jjd dksJ | j  j ks$J t| j jj t| j jj	 t| jt
| j tt| jD ]}| j| }t
| j| }t|| qDt| j| jd  t| j| jd  | jdksqJ | jdu sxJ t| tsJ  j krtd S )Nr    r:   r   zin progressT)nitintermediate_resultr3   ndimshaper   r;   rn   r   r   r
   rangelenpopulation_energiesmessagesuccess
isinstancer   StopIteration)r   ir   ref)callbackr   r5   r6   r     s0   

zJTestDifferentialEvolutionSolver.test_intermediate_result.<locals>.callbackr   r   r:   ie F)rn   r,   rngr   r   r   &callback function requested stop early/Maximum number of iterations has been exceeded.>   r   r   Tr   r5   )r;   r'   infr   r   r   rn   dictr   r   r   itemsr   r   )r4   r,   kwargsr   r   fieldr   r5   )r   rn   r   r6   test_intermediate_result
  s4     z8TestDifferentialEvolutionSolver.test_intermediate_resultc                 C   s   ddg}d}ddd}t t||d}t|j| dd }t t||d}|jr(J dd	d
}t t||d}t|j| |jr?J ddd}t t||d}|jsPJ d S )Nr   r   r   c                 S   s   dS )NTr5   paramconvergencer5   r5   r6   callback_python_trueW     zVTestDifferentialEvolutionSolver.test_callback_terminates.<locals>.callback_python_true)r   c                 S   s   t r   )r   )r   r5   r5   r6   callback_stop`  r   zOTestDifferentialEvolutionSolver.test_callback_terminates.<locals>.callback_stopc                 S   s   dgS )Nr   r5   r   r5   r5   r6   callback_evaluates_truef  s   zYTestDifferentialEvolutionSolver.test_callback_terminates.<locals>.callback_evaluates_truec                 S   s   g S r   r5   r   r5   r5   r6   callback_evaluates_falsen  r   zZTestDifferentialEvolutionSolver.test_callback_terminates.<locals>.callback_evaluates_false)r   )r   r
   r   r   r   )r4   r,   expected_msgr   r]   r   r   r   r5   r5   r6   test_callback_terminatesS  s&   




z8TestDifferentialEvolutionSolver.test_callback_terminatesc                 C   s2   dg}d}dd }t |||dd}t|jd d S )Nr   )r   r   r   c                 W   s6   t |ts	td|d |d |   |d | d   S )Nzargs should be a tupler   r    r:   r   )r   tuplerk   )r;   argsr5   r5   r6   r-   z  s   
$zLTestDifferentialEvolutionSolver.test_args_tuple_is_passed.<locals>.quadraticT)r   r   gUUUUUU?)r   r   r   )r4   r,   r   r-   r]   r5   r5   r6   test_args_tuple_is_passedu  s   z9TestDifferentialEvolutionSolver.test_args_tuple_is_passedc                 C   s    t }dg}ttt||dd d S )NrW   abcr=   )r
   rj   rk   r   )r4   rn   r,   r5   r5   r6   test_init_with_invalid_strategy  s   
z?TestDifferentialEvolutionSolver.test_init_with_invalid_strategyc                 C   sV   t }dg}ttt|| ddg}ttt|| tt tddgddg}t|jd d S )Nr   r   )rW   rX   rY   r   r:   )r   r   )r
   rj   rk   r   r   r   r;   )r4   rn   r,   r]   r5   r5   r6   test_bounds_checking  s   z4TestDifferentialEvolutionSolver.test_bounds_checkingc           
      C   s   t jddddd}tt|dd d f |dd d f }td |dd}d}||d	\}}}}}	ttt 	t 
||||||	gd d S )
Ng      (@float64)dtyper:   rZ   r   r    r#   rY   )r'   r1   reshaperf   zipr   _select_samplesr   r   uniquer*   )
r4   r+   r,   rR   	candidater1r2r3r4r5r5   r5   r6   test_select_samples  s   & z3TestDifferentialEvolutionSolver.test_select_samplesc                 C   s4   t t| jdd}| }t|jd t|jd d S )Nr    )r   Fr   )r   r
   r,   r   r   r   r   r   r5   r5   r6   test_maxiter_stops_solve  s   z8TestDifferentialEvolutionSolver.test_maxiter_stops_solvec                 C   s   t t| jddd}| }t|jd t|jd t|jd t t| jdddd}| }t|jd	 t|jd t|jd t t| jddd
dd}| }t|jd
 t|jd t|jd d S )Nr    F)maxfunr   r:   z9Maximum number of function evaluations has been exceeded.rY   (   )r#   r   r   )   /   deferred)r#   r   r   updatingz8Maximum number of function evaluations has been reached.)r   r
   r,   r   r   nfevr   r   r   r5   r5   r6   test_maxfun_stops_solve  sD   
	z7TestDifferentialEvolutionSolver.test_maxfun_stops_solvec                 C   s0   t | jdgdd}|  tt|jd d S )Nr   r   {Gz?)tolr   )r   r-   r   r   r'   argminr   rQ   r5   r5   r6   test_quadratic  s   z.TestDifferentialEvolutionSolver.test_quadraticc                 C   s   t | jdgddd d S )Nr   r   r    )r   seed)r   r-   r8   r5   r5   r6   test_quadratic_from_diff_ev  s
   
z;TestDifferentialEvolutionSolver.test_quadratic_from_diff_evc                 C   sL   t | jdgdddd}t | jdgdddd}t|j|j t|j|j d S )Nr   Fr    r"   )r   r   r   )r   r-   r   r;   r   )r4   r]   result2r5   r5   r6   test_rng_gives_repeatability  s   z<TestDifferentialEvolutionSolver.test_rng_gives_repeatabilityc              	   C   s8   t j }g d}|D ]}t| jdgd|d|d qd S )N)randomlatinhypercubesobolhaltonr   Fr"   )r   r   r   init)r'   r   default_rngr   r-   )r4   r   initsr   r5   r5   r6   test_random_generator  s   
z5TestDifferentialEvolutionSolver.test_random_generatorc                 C   s   t t| jddd}|  d S )Nr<   r    )r>   r   r   r
   r,   r   rQ   r5   r5   r6   test_exp_runs  s   z-TestDifferentialEvolutionSolver.test_exp_runsc                 C   s   ddg}t t|ddd d S )N)rY   1   r    )r#   r   )r   r
   )r4   r,   r5   r5   r6   test_gh_4511_regression  s   	z7TestDifferentialEvolutionSolver.test_gh_4511_regressionc                 C   sF   t t| jdd}||j |  tt|j	d t|j
d d S )NrW   r   r   rZ   )r   r
   r,   _calculate_population_energiesr3   _promote_lowest_energyr   r'   r   r   _nfevrQ   r5   r5   r6   "test_calculate_population_energies(  s
   zBTestDifferentialEvolutionSolver.test_calculate_population_energiesc           
      C   s   t t| jddd}t|\}}tt|dd t|jd tt	t| t t| j}t|\}}t
|D ]\}}|\}}	||	ksBJ ||	}}|dkrN d S q4d S )NrW      )r#   r   r   r:   2   )r   r
   r,   nextr   r'   sizer   rj   r   	enumerate)
r4   rR   r;   r   _fun_prevr   soln	x_currentfun_currentr5   r5   r6   test_iteration2  s"   

z.TestDifferentialEvolutionSolver.test_iterationc                 C   s,   t t| jddd}|  t|jdk  d S )N皙?F)r   r   )r   r
   r,   r   r   r   rQ   r5   r5   r6   test_convergenceL  s
   
z0TestDifferentialEvolutionSolver.test_convergencec                 C   s   t t| jd d d}|  d S )N)r   r   r   rQ   r5   r5   r6   test_maxiter_none_GH5731R  s   
z8TestDifferentialEvolutionSolver.test_maxiter_none_GH5731c              	   C   s(  t ttgt| jfR i ddi tt| j}|  t|jd tt	
t	|j |  t|jd tt	
t	|j |jdd t|jd tt	
t	|j tt| jdd}|jdd t|jd tt	
t	|j t	dd	d
dd}tt| j|ddddd}t|jd tt	
t	|j t|jdk t|jdk t	||dd}t|jd d | tt	|jd d d tt	|jd d d t	dd	ddd	}t ttgt| jfR i d|i t	jjdddd}tt| j|d}t|jd |d  d S )Nr   rubbishr   r   )
qmc_enginer   )r   ri   rW   r   rY   r:   rF   {Gz?r    )r   r>   atolr   r#   )rY   r:      r   r   )lowhighr   x0)rj   rk   r   r
   r,   init_population_randomr   r   r   r'   r   isinfr   init_population_lhsinit_population_qmclinspacer   num_population_memberspopulation_shapeclipr   r   r3   minmaxr   uniformr   )r4   rR   r3   unscaled_populationr  r5   r5   r6   test_population_initiation[  sd   z:TestDifferentialEvolutionSolver.test_population_initiationc                 C   s`   t t| jddgd}|jsJ tt t t| jddgd W d    d S 1 s)w   Y  d S )Nr  r&   r   @)r   r
   r,   r   rj   rk   )r4   r   r5   r5   r6   test_x0  s
   

"z'TestDifferentialEvolutionSolver.test_x0c                 C   s"   dd }ddg}t ||dd d S )Nc                 S   s   | d dk r	t jS | d S )Nr   r"   r    )r'   r   rr   r5   r5   r6   sometimes_inf  s   zWTestDifferentialEvolutionSolver.test_infinite_objective_function.<locals>.sometimes_infr   F)r,   disp)r   )r4   r  r,   r5   r5   r6    test_infinite_objective_function  s   z@TestDifferentialEvolutionSolver.test_infinite_objective_functionc                 C   sd   ddg}t t|dd}t|jdk t|jjtu  | }|js#J t	t|ddd}|js0J d S )Nr   r   )r   r<   )r   r>   )
r   r
   r   	_updating_mapwrapper_mapfuncmapr   r   r   )r4   r,   rR   r   r5   r5   r6   test_deferred_updating  s   
z6TestDifferentialEvolutionSolver.test_deferred_updatingc              
   C   s   ddg}t t|}t|jdk td}|d@}tt$ t t||j	d}|
  W d    n1 s7w   Y  W d    n1 sFw   Y  |jdksRJ W d    d S 1 s]w   Y  d S )Nr   	immediatespawnr:   )workersr   )r   r
   r   r!  multiprocessingget_contextr   r   UserWarningr$  r   )r4   r,   rR   ctxpsr5   r5   r6   test_immediate_updating  s   



"z7TestDifferentialEvolutionSolver.test_immediate_updatingr   c              	   C   s   ddg}t d6}tt|d|jddd}|jjd usJ |jdks$J |  W d    n1 s2w   Y  W d    n1 sAw   Y  tt|ddddd}|jjd usYJ |jdks`J |  W d    d S 1 sow   Y  d S )Nr   r:   r   r%   rW   )r   r(  r   r#   )r   r(  r#   r   )
ThreadPoolr   r
   r$  r"  poolr!  r   )r4   r,   r-  rR   r5   r5   r6   test_parallel  s&   
 
"z-TestDifferentialEvolutionSolver.test_parallelc                 C   s&   t tddg}|  t|  d S )Nr   )r   r
   r   r   	convergedrQ   r5   r5   r6   test_converged  s   z.TestDifferentialEvolutionSolver.test_convergedc                    s  dd }dd  t |tj d}ttddg|fdtddg}t|d	 t  tj d
}ttddg||fdg d}g d}t||D ]\}}t|}t	|t
| qIt	t|t| tfddt|D }	|	jdksJ  fdd}
t |
tj d
}ttddg||fddd_tjtdd t| W d    d S 1 sw   Y  d S )Nc                 S      | d | d  gS Nr   r    r5   rr   r5   r5   r6   constr_f     zNTestDifferentialEvolutionSolver.test_constraint_violation_fn.<locals>.constr_fc                 S   *   t | d d | d  | d | d  gS Nr   r:   r    r'   r*   rr   r5   r5   r6   	constr_f2     *zOTestDifferentialEvolutionSolver.test_constraint_violation_fn.<locals>.constr_f2ffffff?r   constraintsr   r%   ?))333333?r    r   )r"   r"   ))rz   {Gz?r   )r  @r   )r   r   r   c                    s   g | ]}  |qS r5   )_constraint_violation_fn).0r;   )rR   r5   r6   
<listcomp>  s    zPTestDifferentialEvolutionSolver.test_constraint_violation_fn.<locals>.<listcomp>)rW   r    rW   c                    s
    | j S r   )r2   rr   )r<  r5   r6   	constr_f3  s   
zOTestDifferentialEvolutionSolver.test_constraint_violation_fn.<locals>.constr_f3F)r@  
vectorizedTz#An array returned from a Constraintrs   )r   r'   r   r   r
   rE  r*   r   r   r   r0   r   rI  pytestr   rw   )r4   r7  nlccvnlc2xsvsr;   r   constraint_violationrH  r5   )r<  rR   r6   test_constraint_violation_fn  sH   



"z<TestDifferentialEvolutionSolver.test_constraint_violation_fnc           	      C   s  dd }dd }t |tj d}ttddg|fd}|tddgd	d	gg\}}t|d
d
g t|tdgdgg |j	dksDJ t |tj d}dD ]}ttddg||f|dd}|tddgddgg\}}t|d
d
g t|tg dg dg |tddgd	d	gg\}}t|d
d
g t|tg dg dg |j	dksJ |tddgd	d	gg\}}t|dd
g t|tg dg dg |j	dksJ qNd S )Nc                 S   r5  r6  r5   rr   r5   r5   r6   r7  )  r8  zZTestDifferentialEvolutionSolver.test_constraint_population_feasibilities.<locals>.constr_fc                 S   s$   | d d | d  | d | d  gS r:  r5   rr   r5   r5   r6   r<  ,  s   $z[TestDifferentialEvolutionSolver.test_constraint_population_feasibilities.<locals>.constr_f2r>  r   r?  r"   r   Fr%   r  )r:   r    rA  )FTr   )r@  rI  r   g333333?)r%   r  r   )rz   rC  r   )r  rD  r   )r:   rW   r[   T)r   r   r   )
r   r'   r   r   r
   #_calculate_population_feasibilitiesr*   r   r   r   )	r4   r7  r<  rK  rR   feasrL  rM  	vectorizer5   r5   r6   (test_constraint_population_feasibilities(  sJ   

zHTestDifferentialEvolutionSolver.test_constraint_population_feasibilitiesc                 C   s|   dd }t |tj d}ttddg|fd}tt | }W d    n1 s)w   Y  ||jdks7J |j	s<J d S )Nc                 S      t | d | d  gS r6  r;  rr   r5   r5   r6   r7  W     zGTestDifferentialEvolutionSolver.test_constraint_solve.<locals>.constr_fr>  r   r?  )
r   r'   r   r   r
   r   r+  r   r;   r   )r4   r7  rK  rR   r   r5   r5   r6   test_constraint_solveU  s   


z5TestDifferentialEvolutionSolver.test_constraint_solvec                 C   sL  dd }t |tj d}ttddg|fdddd}tt | }W d    n1 s,w   Y  |jdks8J |j	r=J ttddg|fd	d
}t
| |j rSJ t|j r]J d}|jd }|j|dg |jd|g< |j|dgd d f |jd|gd d f< |j|dgd d f |jd|gd d f< |  t|jd | d S )Nc                 S   rV  r6  r;  rr   r5   r5   r6   r7  i  rW  zLTestDifferentialEvolutionSolver.test_impossible_constraint.<locals>.constr_fri   r   r    r   )r@  r#   r   r   r   F)r@  r      )r   r'   r   r   r
   r   r+  r   maxcvr   r   feasibler   isfiniter   rP  r3   r   r   )r4   r7  rK  rR   r   lrL  r5   r5   r6   test_impossible_constraintf  s0   



(z:TestDifferentialEvolutionSolver.test_impossible_constraintc              
   C   sP  dd }t |tj d}ttddg|fd}|j}|ddtdgd	dtdgs,J |d	dtdgddtdgd
u sAJ |ddtdgddtdgsTJ |ddtdgd	d
td	gsgJ |dd
tddgd	d
td	d	gs|J |dd
tddgd	d
td	dgsJ |d	d
tddgd	d
td	dgrJ d S )Nc                 S   r5  r6  r5   rr   r5   r5   r6   r7    r8  zCTestDifferentialEvolutionSolver.test_accept_trial.<locals>.constr_fr>  r   r?  r%   Tr   r   Fg#@r"   g?)r   r'   r   r   r
   _accept_trialr*   )r4   r7  rK  rR   fnr5   r5   r6   test_accept_trial  s&   
&*&&z1TestDifferentialEvolutionSolver.test_accept_trialc           
         s*  t g d}t dt jdg}t g d}tt|||}||dk s*J |g ddk s7J t dd	d	d
}g }|D ]
}|
|| qEt j||jt |j t g d}t g dg dg dg tt t j d|}||dk sJ |g ddk sJ t dd	dd}g }|D ]
}|
|| qt j||jt |j ttt t j d|}||dk sJ |g ddk sJ  fdd}t|t j d}	t|	g d}||dk sJ |g ddk sJ d S )N)r   rY  r{   r"   F   )r    r:   rW   r   )r[         r       rY   rW   )r    r:   rW   rX   )rY   r   r   rZ   )r!   r      r   )r   r:   r   rX      r!   rX   c                    s
     | S r   )dotrr   Ar5   r6   r     s   
zDTestDifferentialEvolutionSolver.test_constraint_wrapper.<locals>.fun)r'   r*   r   r   r   	violationanyr   r1   r   appendtestingr   r2   r	   r   r   )
r4   lbubr  pcrN  
violationsr;   r   	nonlinearr5   ri  r6   test_constraint_wrapper  s>    z7TestDifferentialEvolutionSolver.test_constraint_wrapperc                 C   s   dd }t |ddgddg}t|ddg}t|jd dks!J g d	}g d
}t||D ]\}}t||| q.t|t|j	t|j	 |
t|j	jdt|fks]J |t|j	jdt|fksoJ |jdksvJ |jdks}J d S )Nc                 S   s.   t | d d | d  | d d | d  gS r:  r;  rr   r5   r5   r6   cons_f  s   zQTestDifferentialEvolutionSolver.test_constraint_wrapper_violation.<locals>.cons_fri   g333333r:   r"   r    r   )rc   )r"   rB  )rB  rB  )r%   333333)r%   r   ))r   r   )r   r%   )rC  r   )gRQ?r   )r  g=
ףp=?)r   r   r'   r   r,   r   r   rk  r*   r2   r   r   r   
num_constrparameter_count)r4   ru  rK  rq  rN  rO  r;   r   r5   r5   r6   !test_constraint_wrapper_violation  s   	
$$zATestDifferentialEvolutionSolver.test_constraint_wrapper_violationc                 C   s   t  }|t tg dg dg}W d    n1 sw   Y  t|dd}td}t||}||j	dks=J t
ddd}||j	d	ksPJ d S )
N)r    r    r    r   )r:   r:   r:   r   r   r    rX   )r:   rY  rY   )r:   rY   )r   filterPendingDeprecationWarningr'   matrixr	   onesr   rk  r   r1   r   )r4   supr|  lcr  cwxtrialr5   r5   r6   test_matrix_linear_constraint  s   



z=TestDifferentialEvolutionSolver.test_matrix_linear_constraintrY  c              
   C   s  dd }t d}d|dg df< d|ddd	gf< d
|dg df< d|dg df< d|dddgf< d
|dg df< d|dg df< d|dddgf< d
|dg df< |dd dd f }t g d}t|t j |}dgd dgd  dg }t||dd|fddd}d }d!}t|||d"d# |jsJ t|j|d"d# t|j	|d$d# t
t ||j |k t
t |jt |d d d%f k t
t |jt |d d df k tt|t j |}t||dd&|fdd'd}t||| |jsJ t|j|d(d# t|j	|d$d# t
t ||j |k t
t |jt |d d d%f k t
t |jt |d d df k d)d* }	d+d, }
t|d dd d f t j |d d }t|ddd d f t j |dd }t|	t j |dd }t|
t j |dd }||||f}t }|t t||dd&|dd'd}W d    n	1 sw   Y  t|j|d"d# t|j	|d$d# t
t ||j |k t
t |jt |d d d%f k t
t |jt |d d df k d S )-Nc                 S   sX   t dg| f} t d| dd  d| dd  | dd   t | dd   }|S )Nr   rY   r    )r'   hstackrq   r;   r   r5   r5   r6   f  s   Dz2TestDifferentialEvolutionSolver.test_L1.<locals>.f)r      )r:   r:   r    r    r    )r    r:   r      )r    r:   r   )rv   ri   r    rW   )rX   rY   r   rX   )r    rW   r   r  rY   r  rZ   )rZ   r!   r  r!   )r:   rW   r  r   rf  r   	   )rf  r  r   )	r   r   r   r   r   r   r   r   r   r   r   r@   i90  r  r>   r   r@  r#   r   )r    r    r    r    r    r    r    r    r    rW   rW   rW   r    iga2U0*C?r	  g{Gzt?r   iz rU   gMb@?c                 S   sL   t dg| f} d| d  d| d   | d  | d  d| d  | d  gS )Nr   r:   rW   r  r   r  r'   r  rr   r5   r5   r6   c1G  s   &z3TestDifferentialEvolutionSolver.test_L1.<locals>.c1c                 S   s,   t dg| f} d| d  | d  | d  S )Nr   rv   rf  r  r   r  rr   r5   r5   r6   c2L     z3TestDifferentialEvolutionSolver.test_L1.<locals>.c2)r'   zerosr*   r	   r   r   r   r   r;   r   r   r   r   r   r   rz  r+  )r4   r  rj  bLr,   r   x_optf_optr  r  L2NN2r@  r~  r5   r5   r6   test_L1  sv   

&&
&&((
&*z'TestDifferentialEvolutionSolver.test_L1c           
      C   s  dd }dd }t |dtj}dgd }|}t }|t t||dd	|d
}W d    n1 s2w   Y  d}d}	t||	| t|j| t|j	|	dd |j
sUJ ttt||j	dk tt|j	t|d d df k tt|j	t|d d df k d S )Nc                 S   s   t dg| f} | 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:   rY   r   rW   rX   r  rZ   r!   rf  r  r  r5   r5   r6   r  g  s   B


z2TestDifferentialEvolutionSolver.test_L2.<locals>.fc                 S   s   t dg| f} 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   d| d d   | d  | d  d| d d  | d d  d| d  | d   d| d d   d| d
   d| d   gS )Nr      r:   r    rW   rX   rY         rZ   rf  r!   i  r   r  r  rr   r5   r5   r6   r  n  s   F6:>

z3TestDifferentialEvolutionSolver.test_L2.<locals>.c1r   r   r!   r@     r>   r   r@  gy\
E@)gܤ@g$H8?g	޿g0ev@gn8)gk_@/?g0g+?h㈵>r  r    )r   r'   r   r   rz  r+  r   r   r   r;   r   r   r   r*   )
r4   r  r  r  r,   r@  r~  r   r  r  r5   r5   r6   test_L2c  s(   


&*z'TestDifferentialEvolutionSolver.test_L2c                 C   s  dd }t d}d|dg df< d|dg df< d	|d
g df< |dd dd f }t g d}dd }t||t j}t|dt j}dgd }||f}t }	|	t t	||d|d
d}
W d    n1 siw   Y  d}d}t
|||dd t
|
j|dd t
|
j|dd |
jsJ tt ||
j |k tt t ||
jdk tt |
jt |d d df k tt |
jt |d d df k d S )Nc                 S   s   t dg| f} | 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| d d d   d| d d d   | d d d  d }|S )Nr   r    r:   r  re  rW   r   rX   rY   rZ   r!   rf  r  r  -   r  r  r5   r5   r6   r    s*   >z2TestDifferentialEvolutionSolver.test_L3.<locals>.f)rX   r  )r  r   rW   ir    )r    r:   r!   rf  )r   rf     rv   r:   )rf  rv   r   r:   rW   )r    r:   r  r   )ir   ic                 S   sX  t dg| f} 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 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   d| d d   | d  d gS )Nr   rW   r    rZ   r:   r   r  rf  r!   r   r   rX   x   r  rY   r   r         r{   r  rr   r5   r5   r6   r    s   6FL:Bz3TestDifferentialEvolutionSolver.test_L3.<locals>.c1r   r   r   r  )r   r@  r#   )
gWXp?`@g@gVW@!@g3Ib@grq?g` ?g$F-t%?g6N#@g7h @g]y @g<6cN8@r  r  ư>)r'   r  r*   r	   r   r   r   rz  r+  r   r   r;   r   r   r   r   r4   r  rj  r  r  r  r  r,   r@  r~  r   r  r  r5   r5   r6   test_L3  s8   
	


&*z'TestDifferentialEvolutionSolver.test_L3c              
   C   s  dd }t d}d|dddgf< d|d	g d
f< d|dddgf< |dd dd f }t g d}dd }t|t j d}t|dt j}dgdgd	  dgd  }||f}t }	|	t t	||dd|ddd}
W d    n1 stw   Y  d}g d}t
|||dd t
|
j|dd t dkrt t jjdk rt
|
j|dd d! n	t
|
j|d"d#d! |
jsJ tt ||
j |k tt t ||
jdk tt |
jt |d d df k tt |
jt |d d df k d S )$Nc                 S   s   t | d d S )NrW   r'   rq   rr   r5   r5   r6   r    r8  z2TestDifferentialEvolutionSolver.test_L4.<locals>.f)rX   r  ){Gzd?r  r    rX   rZ   )r  r  g{Gzdr:   )rY   r!   rX   )r  g{GzrW   rf  rY   )r    r    r    c                 S   s   t dg| f} | d | d  d| d   d| d   d | d | d	  d
| d   | d | d   d
| d   | d | d  d | d | d   d| d   gS )Nr   r    rZ   g!> 
@rX   r   gSUX@r:   r!   i  rY   rW   rf  i i	  r  rr   r5   r5   r6   r    s
   *6.z3TestDifferentialEvolutionSolver.test_L4.<locals>.c1r   )r   '  )  r  )r   r  r@   r  rU   r  gh|?@)got@g?@g:@gt$f@gVfyr@gh o?k@gCq@gVfx@MbP?r  Windowsgv!>gy&1l?)rtolr	  gh㈵>ga2U0*c?)r'   r  r*   r	   r   r   r   rz  r+  r   r   r   platformsystemr   intpitemsizer;   r   r   r   )r4   r  rj  r  r  r  r  r,   r@  r~  r   r  r  r5   r5   r6   test_L4  s>   


&*z'TestDifferentialEvolutionSolver.test_L4c           	      C   s   dd }dd }t |tj d}dgd }|}t||dd	|d
}d}d}t|||dd t|j|dd |js:J ttt	||j
dk tt|j
t	|d d df k tt|j
t	|d d df k d S )Nc                 S   sf   t dg| f} t dt j | d  d t dt j | d   | d d | d | d    }| S )Nr   r:   r    rW   )r'   r  sinpir  r5   r5   r6   r    s
   2z2TestDifferentialEvolutionSolver.test_L5.<locals>.fc                 S   sD   t dg| f} | d d | d  d d| d  | d d d  gS )Nr   r    r:   rX   r  rr   r5   r5   r6   r    s   z3TestDifferentialEvolutionSolver.test_L5.<locals>.c1r   r   r   r:   rA   r  r  )gJIť?gU(C@g#gh㈵>r  -C6?r    )r   r'   r   r   r   r   r   r   r   r*   r;   	r4   r  r  r  r,   r@  r   r  r  r5   r5   r6   test_L5  s    


&*z'TestDifferentialEvolutionSolver.test_L5c           	      C   s   dd }dd }t |dtj}ddg}|}t||dd	|d
d}d}d}t|||dd t|j|dd t|j|dd |jsAJ tt	t
||jdk tt	|jt
|d d df k tt	|jt
|d d df k d S )Nc                 S   s4   t dg| f} | d d d | d d d  }|S )Nr   r    r   rW   r:   rY  r  r  r5   r5   r6   r    s    z2TestDifferentialEvolutionSolver.test_L6.<locals>.fc                 S   sZ   t dg| f} | d d d | d d d  d | d d d  | d d d  d gS )Nr   r    rY   r:   r   rZ   gp=
׳T@r  rr   r5   r5   r6   r    s   "$z3TestDifferentialEvolutionSolver.test_L6.<locals>.c1r   )   r   r   rA   r  gHz>)r>   r   r@  r   )gq=
ף0,@g??g1r  r  r  r  r    )r   r'   r   r   r   r   r;   r   r   r   r*   r  r5   r5   r6   test_L6  s"   

&*z'TestDifferentialEvolutionSolver.test_L6c           	      C   s0  dd }dd }t |g dg d}ddgd	gd
  }|}t||dd|d}g d}d}t||| t|j|dd t|j|dd |jsHJ ttt	||jt	g dk ttt	||jt	g dk tt|jt	|d d df k tt|jt	|d d df k d S )Nc                 S   sH   t dg| f} d| d d  d| d  | d   d| d   d	 }|S )
Nr   g+dvqn@rW   r:   g"C?r    rY   gtۈB@gn@r  r  r5   r5   r6   r  1  s   "
z2TestDifferentialEvolutionSolver.test_L7.<locals>.fc                 S   s   t dg| f} 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| d
  | d   gS )Nr   gl#fUU@g+WPIw?r:   rY   g=BD?r    rX   gOlb?rW   gaۢ T@g+<$!6}?g h?g^5a?g/h"@gxLCs?gݗT?g^gED_?r  rr   r5   r5   r6   r  7  s   ***z3TestDifferentialEvolutionSolver.test_L7.<locals>.c1)r   Z   rY  )\   n      )N   f   )!   r  )   r  rW   rA   r  r  )gq S@g] @@g˻f=@g:F@g%ShMcB@gCgbr  r  r   r    )
r   r   r   r;   r   r   r   r'   r   r*   r  r5   r5   r6   test_L7/  s$   

((&*z'TestDifferentialEvolutionSolver.test_L7ppc64lezfails on ppc64le)reasonc              	   C   s  dd }t d}d|dddgf< d|dddgf< |dd dd f }t d	d	g}d
d }t||t j}t|t ddt dd}dgd dgd  }||f}t }	|	t	 t
||dd|dd}
W d    n1 snw   Y  d}d}t|||dd t|
jd d |d d dd t|
jdd  |dd  dd t|
j|dd |
jsJ tt ||
j |k tt t ||
jdk tt t ||
jdk tt |
jt |d d df k tt |
jt |d d df k d S )Nc                 S   sL   t dg| f} d| d  d| d d   d| d   d| d d   }|S )Nr   rW   r    r  r:   g^>r  r  r5   r5   r6   r  a  s   8z2TestDifferentialEvolutionSolver.test_L8.<locals>.f)rW   rY   )r    ri   r    rX   rW   r:   皙c              	   S   s   t dg| f} dt | d  d  dt | d  d   d | d  dt | d d  dt | d | d  d   d | d  dt | d d  dt | d | d  d   d	 gS )
Nr   r  rW   r[   rX   gfffff@r    r:   g33333;@)r'   r  r  rr   r5   r5   r6   r  l  s   .22z3TestDifferentialEvolutionSolver.test_L8.<locals>.c1MbPr  )r   i  )r  g?r@   r  i  )r>   r   r@  r   )gEGr?@gT㥛D@g&D
n?gd,[ٿg#J{@r  gMb`?r   r   )r'   r  r*   r	   r   r   fullr   rz  r+  r   r   r;   r   r   r   r   r  r5   r5   r6   test_L8]  s<   


	  
&*z'TestDifferentialEvolutionSolver.test_L8rY   c           	      C   s   dd }dd }t |dgdg}dgd }|}t||d	d
|d}tdd dg}d}t||| tt|j|dd t|j|dd |jsJJ t	t
t||jdk t	t
t||jdk t	t
|jt|d d df k t	t
|jt|d d df k d S )Nc                 S   s,   t dg| f} | d d | d d d  S )Nr   r    r:   r  rr   r5   r5   r6   r    r  z2TestDifferentialEvolutionSolver.test_L9.<locals>.fc                 S   s&   t dg| f} | d | d d  gS r:  r  rr   r5   r5   r6   r    s   z3TestDifferentialEvolutionSolver.test_L9.<locals>.c1r  r  rh   r:   rA   r  r  r"   g      ?r  r   r    )r   r   r'   sqrtr   absr;   r   r   r   r   r*   r  r5   r5   r6   test_L9  s$   


&*z'TestDifferentialEvolutionSolver.test_L9c                    s   t jd}tj}d}|j|d|d}dd  ddg}d	d
g}t |||f|d|d}|jd dks5J t|j|dd t |||f|d|d} fdd}	t	|	|jd d||fd
gd}
t|jd |
j |j
|j
ksoJ d S )Nl   b	)rY   r"   r  )r   random_statec                 W   s>   |\}}t |j|g| R  jdd }t |rt j}|S )Nri   axis)r'   logpmfrq   isnanr   )r-  r   distr;   llr5   r5   r6   rn     s
   "
z>TestDifferentialEvolutionSolver.test_integrality.<locals>.funcTF)r       )r   gffffff?)r   integralityr   r   r   rY   g?)r  c                    s$   |\}}} t || d g||S )Nr   r;  )r-  r   nr  r;   r   r5   r6   func2  s   
z?TestDifferentialEvolutionSolver.test_integrality.<locals>.func2r    )r   r,   )r'   r   r   r   nbinomrvsr   r;   r   r   r   )r4   r   r  shapesr;   r  r,   r   res2r  LBFGSBr5   r   r6   test_integrality  s.   z0TestDifferentialEvolutionSolver.test_integralityc                 C   s  dd }g d}g d}t ||ddd}t|jd g d t|jd	 g d
 t ||d|d}t|jd g d t|jd	 g d t|jg d |jdu sSJ g d}t ||d|d}t|jd g d t|jd	 g d tt|jd g d tt|jd	 g d g d}t ||d|d}t|jd g d t|jd	 g d g d}tj	t
dd t ||d|d W d    d S 1 sw   Y  d S )Nc                 S   s   | S r   r5   rr   r5   r5   r6   r    r   zBTestDifferentialEvolutionSolver.test_integrality_limits.<locals>.f)TFT))r  r   r   皙@)ffffff
@皙@F)r,   r   r  r   )r  r   r  r    )r   r  r  )r"   r   g      @)g      ?r        @))rv  gr  )g$gffffff@)g      r         %)r  r  r  )      r   g      $)r  r   g      @))ffffff$g333333 r  g%gr#)r  r   r  )g      !r  g      #))r  g333333$r  r  zOne of the integralityrs   )r   r   r+   r   r  r   r'   roundrJ  r   rk   )r4   r  r  r,   rR   r5   r5   r6   test_integrality_limits  sF   "z7TestDifferentialEvolutionSolver.test_integrality_limitsc                    s<  dd }dd }t jtdd t|| jddd	 W d    n1 s#w   Y  ttd
d t|| jdd W d    n1 sAw   Y  ttdd t|| jdtdd W d    n1 saw   Y  dg  fdd}ddg}tt|ddd}t||dddd}t	|j
|j
  d |jksJ |j|jksJ d S )Nc                 S   s   t | d S rp   r  rr   r5   r5   r6   r-        zBTestDifferentialEvolutionSolver.test_vectorized.<locals>.quadraticc                 S   s   t j| d ddS )Nr:   r   r  r  rr   r5   r5   r6   quadratic_vec  r8  zFTestDifferentialEvolutionSolver.test_vectorized.<locals>.quadratic_veczThe vectorized functionrs   Tr   )rI  r   z#differential_evolution: the 'vector)rI  z$differential_evolution: the 'workers)rI  r(  r   r   c                    s    d  d7  < t | S r6  )r
   rr   ncallsr5   r6   	rosen_vec'  s   zBTestDifferentialEvolutionSolver.test_vectorized.<locals>.rosen_vecr  r    )r   r   )rI  r   r   )rJ  r   rw   r   r,   r   r+  r$  r
   r   r;   r   r   )r4   r-   r  r  r,   res1r  r5   r  r6   test_vectorized  s<   z/TestDifferentialEvolutionSolver.test_vectorizedc           	   	   C   s   dd }dd }t |tj d}t |dd}dd	 }d
d
g}tt|dd||gdd}t||ddd||gdd}t|j|j d S )Nc                 S   rV  r6  r;  rr   r5   r5   r6   r7  7  rW  zMTestDifferentialEvolutionSolver.test_vectorized_constraints.<locals>.constr_fc                 S   r9  r:  r;  rr   r5   r5   r6   r<  :  r=  zNTestDifferentialEvolutionSolver.test_vectorized_constraints.<locals>.constr_f2r>  )r   r"   r   c                 S   sF   d| dd  | d d d  d  }|d| d d  d 7 }t |S )Nr   r    ri   r   )r'   squeeze)r;   r   r5   r5   r6   r  @  s   $
zNTestDifferentialEvolutionSolver.test_vectorized_constraints.<locals>.rosen_vecr  r   r    F)r   r   r@  r   T)rI  r   r   r@  r   )r   r'   r   r   r
   r   r;   )	r4   r7  r<  nlc1rM  r  r,   r  r  r5   r5   r6   test_vectorized_constraints6  s    z;TestDifferentialEvolutionSolver.test_vectorized_constraintsc                 C   sj   dd }t dd dtj}t dd tj d}t|ddg||gd	d
dd}|jd
u s,J d|jv s3J d S )Nc                 S   s   t | d t | d  S r6  )r'   cosr  rr   r5   r5   r6   rn   T  s   zUTestDifferentialEvolutionSolver.test_constraint_violation_error_message.<locals>.funcc                 S   s   | d | d d d  S Nr    r   r:   r5   rr   r5   r5   r6   <lambda>X  s    zYTestDifferentialEvolutionSolver.test_constraint_violation_error_message.<locals>.<lambda>r   c                 S   s   | d | d d  S r  r5   rr   r5   r5   r6   r  Y  s    )ri   r:   rh   r   Fi3)r,   r@  r   r   r   z
MAXCV = 0.)r   r'   r   r   r   r   )r4   rn   c0r  r]   r5   r5   r6   'test_constraint_violation_error_messageR  s   zGTestDifferentialEvolutionSolver.test_constraint_violation_error_messagec                    s   dd}dg }| dddg d fdd	}t t||d	|dd
d	}|j|u s3J |   d dks?J tt||dd}|jsLJ ddd}tjtdd tt||d W d    d S 1 skw   Y  d S )NrX   r   )r   g      $@r&   gffffff?r   c                    s    d  d7  < t ||  }|}t }|| |d d }||| k d d }|d d \}}|d || ||    }	|jd}
|
k }
d|
|< t |
|	|}|S )Nr   r    rW   r:   )r   T)r'   copychoicer1   shuffler  where)r   r3   r   r^   
fill_pointr1  idxsr0r   bprime
crossoverscallsr$   rx  recombinationtotal_popsizer5   r6   custom_strategy_fnu  s    


zLTestDifferentialEvolutionSolver.test_strategy_fn.<locals>.custom_strategy_fnr:   F)r#   r  r$   r   r>   r   r   r   )r>   r   c                 S   s   t ddgS )Nr   r   r;  )r   r3   r   r5   r5   r6   r    r  z	strategy*rs   r=   r   )	r   r
   r>   r   r   r   rJ  r   rw   )r4   r#   r,   r  rR   r   r5   r  r6   test_strategy_fni  sD   


"z0TestDifferentialEvolutionSolver.test_strategy_fnN)LrP   
__module____qualname__r7   r9   r-   rS   r_   r`   ra   rb   rg   ro   rx   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%  rJ  markthread_unsafer/  	fail_slowr2  r4  rQ  rU  rX  r^  ra  rt  ry  r  r  r  r  r  r  r  r  xslowxfailr  machiner  r  r  r  r  r  r  r  r5   r5   r5   r6   r      s    K
		I"

	0	
	F	



9-

',


^

'

2

4


.
3


,-
(
r   )$__doc__r)  multiprocessing.dummyr   r0  r  %scipy.optimize._differentialevolutionr   r   scipy.optimizer   r   scipy.optimize._constraintsr   r   r	   r
   r   scipy.sparser   scipyr   numpyr'   numpy.testingr   r   r   r   r   r   rJ  r   rj   r   r   r5   r5   r5   r6   <module>   s     