
    (phzJ                     4   S r SS/rSSKrSSKJr  SSKJrJrJrJ	r	J
r
JrJrJrJrJr  SSKJrJrJrJrJr  SS	KJr  SS
KJrJr  SSKJr  SSKJr  Sr \" \" \!5      RD                  5      r#S r$SSSSSSSSSSSSSS\#S4S jr%SSSSSSSS\#SS4S jr&S r'S r(g)a  
This module implements the Sequential Least Squares Programming optimization
algorithm (SLSQP), originally developed by Dieter Kraft.
See http://www.netlib.org/toms/733

Functions
---------
.. autosummary::
   :toctree: generated/

    approx_jacobian
    fmin_slsqp

approx_jacobian
fmin_slsqp    N)slsqp)
zerosarraylinalgappendconcatenatefinfosqrtvstackisfinite
atleast_1d   )OptimizeResult_check_unknown_options_prepare_scalar_function_clip_x_for_func_check_clip_x)approx_derivative)old_bound_to_new_arr_to_scalar)array_namespace)array_api_extrazrestructuredtext enc                 F    [        XSUUS9n[        R                  " U5      $ )aC  
Approximate the Jacobian matrix of a callable function.

Parameters
----------
x : array_like
    The state vector at which to compute the Jacobian matrix.
func : callable f(x,*args)
    The vector-valued function.
epsilon : float
    The perturbation used to determine the partial derivatives.
args : sequence
    Additional arguments passed to func.

Returns
-------
An array of dimensions ``(lenf, lenx)`` where ``lenf`` is the length
of the outputs of `func`, and ``lenx`` is the number of elements in
`x`.

Notes
-----
The approximation is done using forward differences.

2-point)methodabs_stepargs)r   np
atleast_2d)xfuncepsilonr   jacs        K/var/www/html/venv/lib/python3.13/site-packages/scipy/optimize/_slsqp_py.pyr   r   $   s(    6 DI!%'C ==     d   gư>c                 2  ^
 Ub  UnUUUUS:g  UUS.nSnU[        U
4S jU 5       5      -  nU[        U
4S jU 5       5      -  nU(       a
  USX8T
S.4-  nU(       a
  USXYT
S.4-  n[        XT
4XvUS	.UD6nU(       a  US
   US   US   US   US   4$ US
   $ )a  
Minimize a function using Sequential Least Squares Programming

Python interface function for the SLSQP Optimization subroutine
originally implemented by Dieter Kraft.

Parameters
----------
func : callable f(x,*args)
    Objective function.  Must return a scalar.
x0 : 1-D ndarray of float
    Initial guess for the independent variable(s).
eqcons : list, optional
    A list of functions of length n such that
    eqcons[j](x,*args) == 0.0 in a successfully optimized
    problem.
f_eqcons : callable f(x,*args), optional
    Returns a 1-D array in which each element must equal 0.0 in a
    successfully optimized problem. If f_eqcons is specified,
    eqcons is ignored.
ieqcons : list, optional
    A list of functions of length n such that
    ieqcons[j](x,*args) >= 0.0 in a successfully optimized
    problem.
f_ieqcons : callable f(x,*args), optional
    Returns a 1-D ndarray in which each element must be greater or
    equal to 0.0 in a successfully optimized problem. If
    f_ieqcons is specified, ieqcons is ignored.
bounds : list, optional
    A list of tuples specifying the lower and upper bound
    for each independent variable [(xl0, xu0),(xl1, xu1),...]
    Infinite values will be interpreted as large floating values.
fprime : callable ``f(x,*args)``, optional
    A function that evaluates the partial derivatives of func.
fprime_eqcons : callable ``f(x,*args)``, optional
    A function of the form ``f(x, *args)`` that returns the m by n
    array of equality constraint normals. If not provided,
    the normals will be approximated. The array returned by
    fprime_eqcons should be sized as ( len(eqcons), len(x0) ).
fprime_ieqcons : callable ``f(x,*args)``, optional
    A function of the form ``f(x, *args)`` that returns the m by n
    array of inequality constraint normals. If not provided,
    the normals will be approximated. The array returned by
    fprime_ieqcons should be sized as ( len(ieqcons), len(x0) ).
args : sequence, optional
    Additional arguments passed to func and fprime.
iter : int, optional
    The maximum number of iterations.
acc : float, optional
    Requested accuracy.
iprint : int, optional
    The verbosity of fmin_slsqp :

    * iprint <= 0 : Silent operation
    * iprint == 1 : Print summary upon completion (default)
    * iprint >= 2 : Print status of each iterate and summary
disp : int, optional
    Overrides the iprint interface (preferred).
full_output : bool, optional
    If False, return only the minimizer of func (default).
    Otherwise, output final objective function and summary
    information.
epsilon : float, optional
    The step size for finite-difference derivative estimates.
callback : callable, optional
    Called after each iteration, as ``callback(x)``, where ``x`` is the
    current parameter vector.

Returns
-------
out : ndarray of float
    The final minimizer of func.
fx : ndarray of float, if full_output is true
    The final value of the objective function.
its : int, if full_output is true
    The number of iterations.
imode : int, if full_output is true
    The exit mode from the optimizer (see below).
smode : string, if full_output is true
    Message describing the exit mode from the optimizer.

See also
--------
minimize: Interface to minimization algorithms for multivariate
    functions. See the 'SLSQP' `method` in particular.

Notes
-----
Exit modes are defined as follows:

- ``-1`` : Gradient evaluation required (g & a)
- ``0`` : Optimization terminated successfully
- ``1`` : Function evaluation required (f & c)
- ``2`` : More equality constraints than independent variables
- ``3`` : More than 3*n iterations in LSQ subproblem
- ``4`` : Inequality constraints incompatible
- ``5`` : Singular matrix E in LSQ subproblem
- ``6`` : Singular matrix C in LSQ subproblem
- ``7`` : Rank-deficient equality constraint subproblem HFTI
- ``8`` : Positive directional derivative for linesearch
- ``9`` : Iteration limit reached

Examples
--------
Examples are given :ref:`in the tutorial <tutorial-sqlsp>`.

r   )maxiterftoliprintdispepscallbackr(   c              3   0   >#    U  H  nS UTS.v   M     g7f)eqtypefunr   Nr(   .0cr   s     r&   	<genexpr>fmin_slsqp.<locals>.<genexpr>   s     I&Q448&   c              3   0   >#    U  H  nS UTS.v   M     g7f)ineqr3   Nr(   r6   s     r&   r9   r:      s     LGq6!T:Gr;   r2   )r4   r5   r%   r   r=   )r%   boundsconstraintsr"   r5   nitstatusmessage)tuple_minimize_slsqp)r#   x0eqconsf_eqconsieqcons	f_ieqconsr>   fprimefprime_eqconsfprime_ieqconsr   iteraccr-   r.   full_outputr$   r0   optsconsress             `          r&   r   r   F   s    ` aK "D D 	EI&IIIDELGLLLD $x  # 	#&  # 	# $D 4f&*4.24C3xUSZXINN3xr'   Fc                 `  ^^^H^I [        U5        US-
  nUnU
mHU	(       d  Sn[        U5      n[        R                  " UR	                  U5      SUS9nUR
                  nUR                  UR                  S5      (       a  UR                  nUR                  UR                  UU5      S5      nUb  [        U5      S:X  a"  [        R                  * [        R                  4mIO[        U5      mI[        R                  " UTIS   TIS   5      n[        U[         5      (       a  U4nSSS.n[#        U5       H  u  nn US	   R%                  5       nUS;  a  ['        S
US	    S35      e SU;  a  ['        SU-  5      eUR/                  S5      nUc  UHUUUI4S jnU" US   5      nUU==   US   UUR/                  SS5      S.4-  ss'   M     SSSSSSSSSSSS .n[1        [3        [        US!    Vs/ s H  n[5        US   " U/US   Q76 5      PM     sn5      5      n[1        [3        [        US"    Vs/ s H  n[5        US   " U/US   Q76 5      PM     sn5      5      nUU-   n[7        SU/5      R9                  5       n[        U5      n U S-   n!UU-
  U!-   U!-   n"S#U!-  U-   U!S-   -  U!U-
  S-   U"S$-   -  -   S$U"-  -   U!U"-   U!U-
  -  -   S$U-  -   U!-   U S-   U -  S$-  -   S$U-  -   S#U -  -   S#U!-  -   S-   n#U"n$[;        U#5      n%[;        U$5      n&Ub  [        U5      S:X  ar  [        R<                  " U [>        S%9n'[        R<                  " U [>        S%9n(U'RA                  [        RB                  5        U(RA                  [        RB                  5        GO[7        U V)V*s/ s H  u  n)n*[E        U)5      [E        U*5      4PM     sn*n)[>        5      n+U+RF                  S   U :w  a  [I        S&5      e[        RJ                  " S'S(9   U+SS2S4   U+SS2S4   :  n,SSS5        W,RM                  5       (       a%  ['        S)S*RO                  S+ U, 5       5       S,35      eU+SS2S4   U+SS2S4   n(n'[Q        U+5      ) n-[        RB                  U'U-SS2S4   '   [        RB                  U(U-SS2S4   '   [S        U UTX*TTIS-9n.[U        U.RV                  TI5      n/[U        U.RX                  TI5      n0[7        S[Z        5      n1[7        U[>        5      n[7        U[Z        5      n2Sn3[7        S[>        5      n4[7        S[>        5      n5[7        S[>        5      n6[7        S[>        5      n7[7        S[>        5      n8[7        S[>        5      n9[7        S[>        5      n:[7        S[>        5      n;[7        S[>        5      n<[7        S[>        5      n=[7        S[Z        5      n>[7        S[Z        5      n?[7        S[Z        5      n@[7        S[Z        5      nA[7        S[Z        5      nB[7        S[Z        5      n![7        S[Z        5      nC[7        S[Z        5      nDUS$:  a  []        S.S/-  5        U/" U5      nE[_        U0" U5      S05      nF[a        UU5      n[c        UUUU UUU5      nG [e        / UPUPUPU'PU(PWEPUPWFPWGPUPU2PU1PU%PU&PU4PU5PU6PU7PU8PU9PU:PU;PU<PU=PU>PU?PW@PWAPWBPU!PWCPWDP76   U1S:X  a  U/" U5      nE[a        UU5      nU1S:X  a#  [_        U0" U5      S05      nF[c        UUUU UUU5      nGU2U3:  aU  Ub  U" [        Rf                  " U5      5        US$:  a0  []        S1U2U.Rh                  WE[j        Rl                  " WF5      4-  5        [o        U15      S:w  a  O[[        U25      n3GM  US:  am  []        U[[        U15         S2-   [q        U15      -   S3-   5        []        S4WE5        []        S5U25        []        S6U.Rh                  5        []        S7U.Rr                  5        [u        UWEWFSS [[        U25      U.Rh                  U.Rr                  [[        U15      U[[        U15         U1S:H  S89	$ ! [(         a  n[)        SU-  5      UeSnAf[*         a  n[+        S5      UeSnAf[,         a  n[+        S5      UeSnAff = fs  snf s  snf s  sn*n)f ! , (       d  f       GN= f)9aV  
Minimize a scalar function of one or more variables using Sequential
Least Squares Programming (SLSQP).

Options
-------
ftol : float
    Precision goal for the value of f in the stopping criterion.
eps : float
    Step size used for numerical approximation of the Jacobian.
disp : bool
    Set to True to print convergence messages. If False,
    `verbosity` is ignored and set to 0.
maxiter : int
    Maximum number of iterations.
finite_diff_rel_step : None or array_like, optional
    If ``jac in ['2-point', '3-point', 'cs']`` the relative step size to
    use for numerical approximation of `jac`. The absolute step
    size is computed as ``h = rel_step * sign(x) * max(1, abs(x))``,
    possibly adjusted to fit into the bounds. For ``method='3-point'``
    the sign of `h` is ignored. If None (default) then step is selected
    automatically.
r   r   )ndimxpzreal floatingNr(   )r2   r=   r4   zUnknown constraint type 'z'.z"Constraint %d has no type defined.z/Constraints must be defined using a dictionary.z#Constraint's type must be a string.r5   z&Constraint %d has no function defined.r%   c                    >^  UUU UU4S jnU$ )Nc           	      `   > [        U T5      n TS;   a  [        TU TUTTS9$ [        TU STUTS9$ )N)r   z3-pointcs)r   r   rel_stepr>   r   )r   r   r   r>   )r   r   )r"   r   r$   finite_diff_rel_stepr5   r%   
new_boundss     r&   cjac3_minimize_slsqp.<locals>.cjac_factory.<locals>.cjac,  sT    %a4A::0a$:N8B D D  1a	:A8B D Dr'   r(   )r5   r]   r$   r[   r%   r\   s   ` r&   cjac_factory%_minimize_slsqp.<locals>.cjac_factory+  s    
D 
D r'   r   )r5   r%   r   z$Gradient evaluation required (g & a)z$Optimization terminated successfullyz$Function evaluation required (f & c)z4More equality constraints than independent variablesz*More than 3*n iterations in LSQ subproblemz#Inequality constraints incompatiblez#Singular matrix E in LSQ subproblemz#Singular matrix C in LSQ subproblemz2Rank-deficient equality constraint subproblem HFTIz.Positive directional derivative for linesearchzIteration limit reached)rV   r   r                        	   r2   r=   rb   ra   )dtypezDSLSQP Error: the length of bounds is not compatible with that of x0.ignore)invalidzSLSQP Error: lb > ub in bounds z, c              3   8   #    U  H  n[        U5      v   M     g 7f)N)str)r7   bs     r&   r9   "_minimize_slsqp.<locals>.<genexpr>t  s     )A&Q#a&&&s   .)r%   r   r$   r[   r>   z%5s %5s %16s %16s)NITFCOBJFUNGNORMg        z%5i %5i % 16.6E % 16.6Ez    (Exit mode )z#            Current function value:z            Iterations:z!            Function evaluations:z!            Gradient evaluations:)	r"   r5   r%   r@   nfevnjevrA   rB   success);r   r   xpx
atleast_ndasarrayfloat64isdtyperi   reshapeastypelenr    infr   clip
isinstancedict	enumeratelower
ValueErrorKeyError	TypeErrorAttributeErrorgetsummapr   r   maxr   emptyfloatfillnanr   shape
IndexErrorerrstateanyjoinr   r   r   r5   gradintprintr	   _eval_constraint_eval_con_normalsr   copyrv   r   normabsrm   ngevr   )Jr#   rE   r   r%   r>   r?   r+   r,   r-   r.   r/   r0   r[   unknown_optionsrM   rN   rU   ri   r"   rQ   icconctypeer]   r_   
exit_modesr8   meqmieqmlann1mineqlen_wlen_jwwjwxlxulubndsbnderrinfbndsfwrapped_funwrapped_gradmodemajitermajiter_prevalphaf0gsh1h2h3h4tt0toliexactinconsiresetitermxlinen2n3fxgar$   r\   sJ      `        `                                                           @@r&   rD   rD      sK	   8 ?+Q;D
CG 
	B	

2Q2	6BJJE	zz"((O,,


299R',A ~V)vvgrvv&
%f-
 	:a=*Q-0A +t$$"ob!D[)C	NK%%'E N* #<S[M!LMM + EJKK wwu~<   E
+D 	UE
 $!$!46 9 	9S *Z =<<LB;;;JF/
1J c#Dz#!! #1U8A#:&	#:;!# $ %Cs3V&$1 $AeHQ$;6$;<$& ' (D 	d
A	1v			BAA 
QBGbL2ErT!VbdORVAXa001U7:BuHr#v;NNeqS!Ga<(*+A#.01!467d;=>?EFeA	vB ~V)XXau%XXau%

$*,$*&1a &a(.*;<$*,-24::a=A ; < < [[*!Q$Z$q!t*,F + ::<<> $		)A&)A AB!E F FadT!Q$ZB 4.666!Q$<666!Q$< 
"$s7K)3
5B
 #266:6K#BGGZ8L C=D
U
CD#GL !UOE	q%B	q%B	q%B	q%B	q%B	q%BaA	q%B
5/C1c]F1c]F1c]F1c]FC=D	q#B	q#B	q#B {!$DDE
 
QB|A$AD!A!T2q!S$7A
 	a 	 	a 	 	R 	 	Q 	 	1 	c 	7 	D 	! 	R 					!#	%'	)+	-.	02	47			$	&,	.2	 	 	 	
 19QB D)A2:|A,A!!T2q!S$?A\!#$ {/7BGG35v{{1~3G G H t9>7|; @ {jT#&77#d)CcIJ3R8'11277;1277;A21Sb6s7|!wwRWWSY",SY"7$!)N Nw  	M?"DE1L 	2 * +012 	JABI	Jd#&2, +*sN   9`;."b1"b#b
:b;
bab!a--b:bb
b-c                 ^   US   (       a6  [        US    Vs/ s H  n[        US   " U /US   Q76 5      PM     sn5      nO[        S5      nUS   (       a6  [        US    Vs/ s H  n[        US   " U /US   Q76 5      PM     sn5      nO[        S5      n[        X445      nU$ s  snf s  snf )Nr2   r5   r   r   r=   )r
   r   r   )r"   rQ   r   c_eqc_ieqr8   s         r&   r   r     s    Dz'+Dz3'1 's5z!'Bc&k'BC'13 4 QxF|(,V6(4 (E
1(Cs6{(CD(46 7 a 	TM"AH36s   "B%""B*c           
         US   (       a-  [        US    Vs/ s H  nUS   " U /US   Q76 PM     sn5      nO[        XS45      nUS   (       a-  [        US    Vs/ s H  nUS   " U /US   Q76 PM     sn5      n	O[        Xc45      n	US:X  a  [        X#45      n
O[        X45      n
[        U
[        US/5      4S5      n
U
$ s  snf s  snf )Nr2   r%   r   r=   r   r   )r   r   r
   )r"   rQ   r   r   r   r   r   r   a_eqa_ieqr   s              r&   r   r     s    Dz"&t*.",3 5z!2c&k2",. / cXF|#'<1#/C E
13s6{3#/1 2 ti  	Av2'ND=!Qr1g'+AH%.1s   CC))__doc____all__numpyr    scipy.optimize._slsqpr   r   r   r   r	   r
   r   r   r   r   r   	_optimizer   r   r   r   r   _numdiffr   _constraintsr   r   scipy._lib._array_apir   
scipy._libr   ry   __docformat__r   r/   _epsilonr   r   rD   r   r   r(   r'   r&   <module>r      s    l
+  '7 7 7' ' ( : 1 - &e  !D !#T2T"#6d8	Od $&4 "fQU 4d|N~&r'   