
    ukiZ                        d dl mZ d dlmZmZ d dlmZmZ d dlm	Z
 d dlmZ d dlmZ d dlmZ  G d d	e      Z	 dd
d
d	 	 	 	 	 	 	 	 	 	 	 	 	 ddZy
)    )annotations)CallableMapping)Any
NamedTuple)numpy)minimize_bfgs)_minimize_lbfgs)Arrayc                  l    e Zd ZU dZded<   ded<   ded<   ded<   ded	<   d
ed<   ded<   ded<   ded<   y)OptimizeResultsa[  Object holding optimization results.

  Parameters:
    x: final solution.
    success: ``True`` if optimization succeeded.
    status: integer solver specific return code. 0 means converged (nominal),
      1=max BFGS iters reached, 3=zoom failed, 4=saddle point reached,
      5=max line search iters reached, -1=undefined
    fun: final function value.
    jac: final jacobian array.
    hess_inv: final inverse Hessian estimate.
    nfev: integer number of function calls used.
    njev: integer number of gradient evaluations.
    nit: integer number of iterations of the optimization algorithm.
  r   xzbool | Arraysuccesszint | ArraystatusfunjaczArray | Nonehess_invnfevnjevnitN)__name__
__module____qualname____doc____annotations__     [/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/jax/_src/scipy/optimize/minimize.pyr   r      s<     (
**r   r   N)toloptionsc               <    |i }t        t              sd}t        |j                               fd}|j	                         dk(  rt        ||fi |}|j                  t        j                  |j                        z  }	t        |j                  |	|j                  |j                  |j                  |j                  |j                   |j"                  |j$                  	      S |j	                         dk(  rt'        ||fi |}|j                  t        j                  |j                        z  }	t        |j                  |	|j                  |j                  |j                  d|j                   |j"                  |j$                  	      S t)        d| d      )	aF  Minimization of scalar function of one or more variables.

  This API for this function matches SciPy with some minor deviations:

  - Gradients of ``fun`` are calculated automatically using JAX's autodiff
    support when required.
  - The ``method`` argument is required. You must specify a solver.
  - Various optional arguments in the SciPy interface have not yet been
    implemented.
  - Optimization results may differ from SciPy due to differences in the line
    search implementation.

  ``minimize`` supports :func:`~jax.jit` compilation. It does not yet support
  differentiation or arguments in the form of multi-dimensional arrays, but
  support for both is planned.

  Args:
    fun: the objective function to be minimized, ``fun(x, *args) -> float``,
      where ``x`` is a 1-D array with shape ``(n,)`` and ``args`` is a tuple
      of the fixed parameters needed to completely specify the function.
      ``fun`` must support differentiation.
    x0: initial guess. Array of real elements of size ``(n,)``, where ``n`` is
      the number of independent variables.
    args: extra arguments passed to the objective function.
    method: solver type. Currently only ``"BFGS"`` is supported.
    tol: tolerance for termination. For detailed control, use solver-specific
      options.
    options: a dictionary of solver options. All methods accept the following
      generic options:

      - maxiter (int): Maximum number of iterations to perform. Depending on the
        method each iteration may use several function evaluations.

  Returns:
    An :class:`OptimizeResults` object.
  NzDargs argument to jax.scipy.optimize.minimize must be a tuple, got {}c                     | g S )Nr   )r   argsr   s    r   <lambda>zminimize.<locals>.<lambda>i   s    CMDM r   bfgs)	r   r   r   r   r   r   r   r   r   z'l-bfgs-experimental-do-not-rely-on-thiszMethod z not recognized)
isinstancetuple	TypeErrorformatlowerr	   	convergedjnplogical_notfailedr   x_kr   f_kg_kH_kr   ngevkr
   
ValueError)
r   x0r#   methodr   r    msgfun_with_argsresultsr   s
   ` `       r   minimizer;   5   sS   Z _G	D%	 
PC
CJJt$
%%)-\\^vM299G#//'.."AAGW[[#*")..&{{&{{$+KK ' '&yy* * \\^@@mR;7;G#//'.."AAGW[[#*")..&{{&{{$( ' '&yy* * 	WVHO455r   )r   )r   r   r6   r   r#   r'   r7   strr   zfloat | Noner    zMapping[str, Any] | Nonereturnr   )
__future__r   collections.abcr   r   typingr   r   jax._srcr   r,   jax._src.scipy.optimize.bfgsr	   jax._src.scipy.optimize._lbfgsr
   jax._src.typingr   r   r;   r   r   r   <module>rE      s    # - " ! 6 : !j < P6 (,P6	P6P6 P6
 P6 
P6 &P6 P6r   