§
    µ³ÙgàÅ  ã                   óÎ   — d dl Z d dlZd dlmZ ddlmZ ddlmZm	Z	m
Z
  ej        e¦  «        j        Z G d„ d¦  «        ZdddddœZd	„ Z G d
„ d¦  «        Z G d„ d¦  «        ZdS )é    N)Úeighé   )ÚOptions)ÚMaxEvalErrorÚTargetSuccessÚFeasibleSuccessc                   ó¶   — e Zd ZdZd„ Zed„ ¦   «         Zed„ ¦   «         Zed„ ¦   «         Zej	        d„ ¦   «         Zed„ ¦   «         Z
e
j	        d„ ¦   «         Z
d	„ Zd
S )ÚInterpolationz×
    Interpolation set.

    This class stores a base point around which the models are expanded and the
    interpolation points. The coordinates of the interpolation points are
    relative to the base point.
    c                 óÎ  — |t           j                 | _        dt          j        |j        j        |j        j        z
  ¦  «        z  }|t           j                 |k    rL||t           j        j	        <   t          j        |t           j
                 |g¦  «        |t           j
        j	        <   t          j        |j        ¦  «        | _        | j        |j        j        d|t           j                 z  z   k    }|j        j        |         | j        |<   |j        j        d|t           j                 z  z   | j        k     | j        |j        j        |t           j                 z   k    z  }t          j        |j        j        |         |t           j                 z   |j        j        |         ¦  «        | j        |<   | j        |j        j        d|t           j                 z  z
  k    }|j        j        |         | j        |<   | j        |j        j        d|t           j                 z  z
  k     |j        j        |t           j                 z
  | j        k    z  }t          j        |j        j        |         |t           j                 z
  |j        j        |         ¦  «        | j        |<   t          j        |j        |t           j                 f¦  «        | _        t+          d|t           j                 ¦  «        D �]{}||j        k    rL||dz
           r!|t           j                  | j        |dz
  |f<   Œ:|t           j                 | j        |dz
  |f<   ŒZ|d|j        z  k    r¦|||j        z
  dz
           r+d|t           j                 z  | j        ||j        z
  dz
  |f<   Œ¦|||j        z
  dz
           r+d|t           j                 z  | j        ||j        z
  dz
  |f<   Œä|t           j                  | j        ||j        z
  dz
  |f<   �Œ||j        z
  dz
  |j        z  }	|d|	z   |j        z  z
  dz
  }
|
|	z   |j        z  }| j        |
|
dz   f         | j        |
|f<   | j        ||dz   f         | j        ||f<   �Œ}dS )zÜ
        Initialize the interpolation set.

        Parameters
        ----------
        pb : `cobyqa.problem.Problem`
            Problem to be solved.
        options : dict
            Options of the solver.
        ç      à?r   é   ç       @g       ÀN)r   ÚDEBUGÚ_debugÚnpÚminÚboundsÚxuÚxlÚRHOBEGÚvalueÚRHOENDÚcopyÚx0Ú_x_baseÚx_baseÚminimumÚmaximumÚzerosÚnÚNPTÚ_xptÚrangeÚxpt)ÚselfÚpbÚoptionsÚ
max_radiusÚvery_close_xl_idxÚclose_xl_idxÚvery_close_xu_idxÚclose_xu_idxÚkÚspreadÚk1Úk2s               úN/granary/edev/quantum/lib/python3.11/site-packages/scipy/_lib/cobyqa/models.pyÚ__init__zInterpolation.__init__   së  € ð �gœmÔ,ˆŒØ�2œ6 "¤)¤,°´´Ñ"=Ñ>Ô>Ñ>ˆ
Ø•7”>Ô" ZÒ/Ð/Ø,6ˆG•G”NÔ(Ñ)Ý,.¬Fà�GœNÔ+Øðñ-ô -ˆG•G”NÔ(Ñ)õ ”w˜rœu‘~”~ˆŒàŒK˜2œ9œ<¨#°½¼Ô0GÑ*GÑGÒGð 	ð *,¬¬Ð6GÔ)HˆŒÐ%Ñ&àŒIŒL˜3 ­¬Ô!8Ñ8Ñ8¸4¼;ÒFØŒ[˜BœIœL¨7µ7´>Ô+BÑBÒBñDˆõ %'¤JØŒIŒL˜Ô&¨µ´Ô)@Ñ@ØŒIŒL˜Ô&ñ%
ô %
ˆŒ�LÑ!ð
 ŒK˜2œ9œ<¨#°½¼Ô0GÑ*GÑGÒGð 	ð *,¬¬Ð6GÔ)HˆŒÐ%Ñ&àŒK˜"œ)œ,¨¨wµw´~Ô/FÑ)FÑFÒFØŒYŒ\˜G¥G¤NÔ3Ñ3°t´{ÒBñDˆõ %'¤JØŒIŒL˜Ô&¨µ´Ô)@Ñ@ØŒIŒL˜Ô&ñ%
ô %
ˆŒ�LÑ!õ ”H˜bœd G­G¬KÔ$8Ð9Ñ:Ô:ˆŒ	Ý�q˜'¥'¤+Ô.Ñ/Ô/ð 	7ñ 	7ˆAØ�B”DŠyˆyØ$ Q¨¡UÔ+ð AØ*1µ'´.Ô*AÐ)A�D”H˜Q ™U A˜XÑ&Ð&à)0µ´Ô)@�D”H˜Q ™U A˜XÑ&Ð&Ø�a˜"œ$‘h’�Ø$ Q¨¬¡X°¡\Ô2ð IØ03°g½g¼nÔ6MÑ0M�D”H˜Q ¤™X¨™\¨1˜_Ñ-Ð-Ø& q¨2¬4¡x°!¡|Ô4ð IØ04°w½w¼~Ô7NÑ0N�D”H˜Q ¤™X¨™\¨1˜_Ñ-Ð-à18½¼Ô1HÐ0H�D”H˜Q ¤™X¨™\¨1˜_Ñ-Ñ-à˜bœd™( Q™,¨2¬4Ñ/�Ø˜!˜f™*¨¬Ñ,Ñ,¨qÑ0�Ø˜6‘k R¤TÑ)�Ø"&¤(¨2¨r°A©v¨:Ô"6�”˜˜Q˜‘Ø"&¤(¨2¨r°A©v¨:Ô"6�”˜˜Q˜‘‘ð%	7ð 	7ó    c                 ó&   — | j         j        d         S )út
        Number of variables.

        Returns
        -------
        int
            Number of variables.
        r   ©r$   Úshape©r%   s    r1   r    zInterpolation.n\   ó   € ð ŒxŒ~˜aÔ Ð r3   c                 ó&   — | j         j        d         S )úŠ
        Number of interpolation points.

        Returns
        -------
        int
            Number of interpolation points.
        r   r6   r8   s    r1   ÚnptzInterpolation.npth   r9   r3   c                 ó   — | j         S )z’
        Interpolation points.

        Returns
        -------
        `numpy.ndarray`, shape (n, npt)
            Interpolation points.
        )r"   r8   s    r1   r$   zInterpolation.xptt   s   € ð ŒyÐr3   c                 ód   — | j         r!|j        | j        | j        fk    s
J d¦   «         ‚|| _        dS )zª
        Set the interpolation points.

        Parameters
        ----------
        xpt : `numpy.ndarray`, shape (n, npt)
            New interpolation points.
        z The shape of `xpt` is not valid.N)r   r7   r    r<   r"   )r%   r$   s     r1   r$   zInterpolation.xpt€   sR   € ð Œ;ð 	2Ø”9Ø”Ø”ð!ò ð ð ð 2ñô ð ð ˆŒ	ˆ	ˆ	r3   c                 ó   — | j         S )zÄ
        Base point around which the models are expanded.

        Returns
        -------
        `numpy.ndarray`, shape (n,)
            Base point around which the models are expanded.
        )r   r8   s    r1   r   zInterpolation.x_base‘   s   € ð Œ|Ðr3   c                 óX   — | j         r|j        | j        fk    s
J d¦   «         ‚|| _        dS )zß
        Set the base point around which the models are expanded.

        Parameters
        ----------
        x_base : `numpy.ndarray`, shape (n,)
            New base point around which the models are expanded.
        z#The shape of `x_base` is not valid.N)r   r7   r    r   )r%   r   s     r1   r   zInterpolation.x_base�   sK   € ð Œ;ð 	5Ø”<Ø”ð$ò ð ð à4ñô ð ð ˆŒˆˆr3   c                 ó~   — | j         rd|cxk    r| j        k     sn J d¦   «         ‚| j        | j        dd…|f         z   S )a<  
        Get the `k`-th interpolation point.

        The return point is relative to the origin.

        Parameters
        ----------
        k : int
            Index of the interpolation point.

        Returns
        -------
        `numpy.ndarray`, shape (n,)
            `k`-th interpolation point.
        r   zThe index `k` is not valid.N)r   r<   r   r$   )r%   r-   s     r1   ÚpointzInterpolation.point­   sZ   € ð  Œ;ð 	DØ˜Ð$Ð$Ò$Ð$˜DœHÒ$Ð$Ð$Ð$Ð$Ð&CÑ$Ô$Ð$ØŒ{˜TœX a a a¨ dœ^Ñ+Ð+r3   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r2   Úpropertyr    r<   r$   Úsetterr   rB   © r3   r1   r
   r
      sæ   € € € € € ðð ðD7ð D7ð D7ðL ð	!ð 	!ñ „Xð	!ð ð	!ð 	!ñ „Xð	!ð ð	ð 	ñ „Xð	ð 	„Zðð ñ „Zðð  ð	ð 	ñ „Xð	ð „]ðð ñ „]ðð,ð ,ð ,ð ,ð ,r3   r
   )r$   ÚaÚright_scalingr   c                 ó¦  — t           d         �Kt          j        | j        t           d         ¦  «        r&t           d         t           d         t           d         fS t          j        t          j                             | j        d¬¦  «        t          ¬¦  «        }| j        |z  }|j        \  }}t          j	        ||z   d	z   ||z   d	z   f¦  «        }d
|j
        |z  dz  z  |d|…d|…f<   d|d|…|f<   |j
        |d|…|d	z   d…f<   d||d|…f<   |||d	z   d…d|…f<   t          j        ||z   d	z   ¦  «        }d|dz  z  |d|…<   |dz  ||<   |||d	z   d…<   t          |d¬¦  «        \  }}t          j        | j        ¦  «        t           d<   t          j        |¦  «        t           d<   t          j        |¦  «        t           d<   ||ft           d<   ||||ffS )a‰  
    Build the left-hand side matrix of the interpolation system. The
    matrix below stores W * diag(right_scaling),
    where W is the theoretical matrix of the interpolation system. The
    right scaling matrices is chosen to keep the elements in
    the matrix well-balanced.

    Parameters
    ----------
    interpolation : `cobyqa.models.Interpolation`
        Interpolation set.
    r$   NrJ   rK   r   r   )Úaxis©Úinitialr   r   r   ç      ð?F)Úcheck_finite)Ú_cacher   Úarray_equalr$   ÚmaxÚlinalgÚnormÚEPSr7   r   ÚTÚemptyr   r   )	ÚinterpolationÚscaleÚ	xpt_scaler    r<   rJ   rK   Ú
eig_valuesÚeig_vectorss	            r1   Úbuild_systemr_   Å   sì  € õ" ˆe„}Ð ¥R¤^ØÔ�6 %œ=ñ&ô &Ð õ �cŒ{�F ?Ô3µV¸F´^ÐCÐCåŒF•2”9—>’> -Ô"3¸!�>Ñ<Ô<ÅcÐJÑJÔJ€EØÔ! EÑ)€IàŒ_�F€A€sÝ
Œ�#˜‘'˜A‘+˜s Q™w¨™{Ð+Ñ,Ô,€AØ˜9œ;¨Ñ2°sÑ:Ñ:€A€d€s€dˆDˆSˆD€j�MØ€A€d€s€dˆC€i�LØ!œ€A€d€s€dˆC�!‰GˆHˆH€nÑØ€A€cˆ4ˆCˆ4€i�LØ!€A€cˆA�g€h€h���€nÑõ ”H˜S 1™W q™[Ñ)Ô)€MØ  s¡
Ñ*€M�$�3�$ÑØ ™€M�#ÑØ#€M�#˜‘'�(�(Ñå" 1°5Ð9Ñ9Ô9Ñ€J�å”G˜MÔ-Ñ.Ô.…Fˆ5�MÝ”'˜!‘*”*…Fˆ3�KÝ œg mÑ4Ô4…Fˆ?ÑØ  +Ð.…Fˆ6�Nàˆm˜j¨+Ð6Ð6Ð6r3   c                   óš   — e Zd ZdZd„ Zd„ Zed„ ¦   «         Zed„ ¦   «         Zd„ Z	d„ Z
d„ Zd	„ Zd
„ Zd„ Zed„ ¦   «         Zed„ ¦   «         ZdS )Ú	Quadratica:  
    Quadratic model.

    This class stores the Hessian matrix of the quadratic model using the
    implicit/explicit representation designed by Powell for NEWUOA [1]_.

    References
    ----------
    .. [1] M. J. D. Powell. The NEWUOA software for unconstrained optimization
       without derivatives. In G. Di Pillo and M. Roma, editors, *Large-Scale
       Nonlinear Optimization*, volume 83 of Nonconvex Optim. Appl., pages
       255--297. Springer, Boston, MA, USA, 2006. `doi:10.1007/0-387-30065-1_16
       <https://doi.org/10.1007/0-387-30065-1_16>`_.
    c                 óR  — || _         | j         r|j        |j        fk    s
J d¦   «         ‚|j        |j        dz   k     rt	          d|j        dz   › d�¦  «        ‚|                      ||¦  «        \  | _        | _        | _        }t          j
        | j        | j        f¦  «        | _        dS )aú  
        Initialize the quadratic model.

        Parameters
        ----------
        interpolation : `cobyqa.models.Interpolation`
            Interpolation set.
        values : `numpy.ndarray`, shape (npt,)
            Values of the interpolated function at the interpolation points.
        debug : bool
            Whether to make debugging tests during the execution.

        Raises
        ------
        `numpy.linalg.LinAlgError`
            If the interpolation system is ill-defined.
        ú#The shape of `values` is not valid.r   z4The number of interpolation points must be at least ú.N)r   r7   r<   r    Ú
ValueErrorÚ
_get_modelÚ_constÚ_gradÚ_i_hessr   r   Ú_e_hess)r%   rZ   ÚvaluesÚdebugÚ_s        r1   r2   zQuadratic.__init__  s×   € ð$ ˆŒØŒ;ð 	5Ø”<ØÔ!ð$ò ð ð à4ñô ð ð Ô˜}œ°Ñ2Ò2Ð2Ýð*Ø ”? QÑ&ð*ð *ð *ñô ð ð 48·?²?ØØñ4
ô 4
Ñ0ˆŒ�T”Z ¤¨qõ ”x ¤¨¬Ð 0Ñ1Ô1ˆŒˆˆr3   c                 óÖ   — | j         r|j        | j        fk    s
J d¦   «         ‚||j        z
  }| j        | j        |z  z   d| j        |j        j        |z  dz  z  || j	        z  |z  z   z  z   S )a�  
        Evaluate the quadratic model at a given point.

        Parameters
        ----------
        x : `numpy.ndarray`, shape (n,)
            Point at which the quadratic model is evaluated.
        interpolation : `cobyqa.models.Interpolation`
            Interpolation set.

        Returns
        -------
        float
            Value of the quadratic model at `x`.
        úThe shape of `x` is not valid.r   r   )
r   r7   r    r   rg   rh   ri   r$   rX   rj   ©r%   ÚxrZ   Úx_diffs       r1   Ú__call__zQuadratic.__call__(  s�   € ð  Œ;ð 	JØ”7˜tœv˜iÒ'Ð'Ð'Ð)IÑ'Ô'Ð'Ø�]Ô)Ñ)ˆàŒKØŒj˜6Ñ!ñ"àà” Ô 1Ô 3°fÑ <ÀÑDÑDØ˜4œ<Ñ'¨&Ñ0ñ1ññð	
r3   c                 ó   — | j         j        S )r5   )rh   Úsizer8   s    r1   r    zQuadratic.nE  s   € ð ŒzŒÐr3   c                 ó   — | j         j        S )zÐ
        Number of interpolation points used to define the quadratic model.

        Returns
        -------
        int
            Number of interpolation points used to define the quadratic model.
        )ri   ru   r8   s    r1   r<   zQuadratic.nptQ  s   € ð Œ|Ô Ð r3   c                 ó–   — | j         r|j        | j        fk    s
J d¦   «         ‚||j        z
  }| j        |                      ||¦  «        z   S )aº  
        Evaluate the gradient of the quadratic model at a given point.

        Parameters
        ----------
        x : `numpy.ndarray`, shape (n,)
            Point at which the gradient of the quadratic model is evaluated.
        interpolation : `cobyqa.models.Interpolation`
            Interpolation set.

        Returns
        -------
        `numpy.ndarray`, shape (n,)
            Gradient of the quadratic model at `x`.
        ro   )r   r7   r    r   rh   Ú	hess_prodrp   s       r1   ÚgradzQuadratic.grad]  sW   € ð  Œ;ð 	JØ”7˜tœv˜iÒ'Ð'Ð'Ð)IÑ'Ô'Ð'Ø�]Ô)Ñ)ˆØŒz˜DŸNšN¨6°=ÑAÔAÑAÐAr3   c                 ór   — | j         |j        | j        dd…t          j        f         |j        j        z  z  z   S )a;  
        Evaluate the Hessian matrix of the quadratic model.

        Parameters
        ----------
        interpolation : `cobyqa.models.Interpolation`
            Interpolation set.

        Returns
        -------
        `numpy.ndarray`, shape (n, n)
            Hessian matrix of the quadratic model.
        N)rj   r$   ri   r   ÚnewaxisrX   )r%   rZ   s     r1   ÚhesszQuadratic.hessr  s<   € ð Œ|˜mÔ/ØŒL˜˜˜�BœJ˜Ô'¨-Ô*;Ô*=Ñ=ñ
ñ 
ð 	
r3   c                 óš   — | j         r|j        | j        fk    s
J d¦   «         ‚| j        |z  |j        | j        |j        j        |z  z  z  z   S )a.  
        Evaluate the right product of the Hessian matrix of the quadratic model
        with a given vector.

        Parameters
        ----------
        v : `numpy.ndarray`, shape (n,)
            Vector with which the Hessian matrix of the quadratic model is
            multiplied from the right.
        interpolation : `cobyqa.models.Interpolation`
            Interpolation set.

        Returns
        -------
        `numpy.ndarray`, shape (n,)
            Right product of the Hessian matrix of the quadratic model with
            `v`.
        úThe shape of `v` is not valid.)r   r7   r    rj   r$   ri   rX   ©r%   ÚvrZ   s      r1   rx   zQuadratic.hess_prod„  sb   € ð& Œ;ð 	JØ”7˜tœv˜iÒ'Ð'Ð'Ð)IÑ'Ô'Ð'ØŒ|˜aÑ -Ô"3ØŒL˜MÔ-Ô/°!Ñ3Ñ4ñ#
ñ 
ð 	
r3   c                 ó–   — | j         r|j        | j        fk    s
J d¦   «         ‚|| j        z  |z  | j        |j        j        |z  dz  z  z   S )aÄ  
        Evaluate the curvature of the quadratic model along a given direction.

        Parameters
        ----------
        v : `numpy.ndarray`, shape (n,)
            Direction along which the curvature of the quadratic model is
            evaluated.
        interpolation : `cobyqa.models.Interpolation`
            Interpolation set.

        Returns
        -------
        float
            Curvature of the quadratic model along `v`.
        r~   r   )r   r7   r    rj   ri   r$   rX   r   s      r1   ÚcurvzQuadratic.curv�  sb   € ð" Œ;ð 	JØ”7˜tœv˜iÒ'Ð'Ð'Ð)IÑ'Ô'Ð'à�”Ñ˜qÑ ØŒl˜mÔ/Ô1°AÑ5¸#Ñ=Ñ=ñ>ð	
r3   c                 óÈ  — | j         rTd|cxk    r| j        k     sn J d¦   «         ‚|j        | j        fk    s
J d¦   «         ‚|j        | j        fk    s
J d¦   «         ‚| xj        | j        |         t          j        ||¦  «        z  z  c_        d| j        |<   |                      ||¦  «        \  }}}}| xj	        |z  c_	        | xj
        |z  c_
        | xj        |z  c_        |S )a�  
        Update the quadratic model.

        This method applies the derivative-free symmetric Broyden update to the
        quadratic model. The `knew`-th interpolation point must be updated
        before calling this method.

        Parameters
        ----------
        interpolation : `cobyqa.models.Interpolation`
            Updated interpolation set.
        k_new : int
            Index of the updated interpolation point.
        dir_old : `numpy.ndarray`, shape (n,)
            Value of ``interpolation.xpt[:, k_new]`` before the update.
        values_diff : `numpy.ndarray`, shape (npt,)
            Differences between the values of the interpolated nonlinear
            function and the previous quadratic model at the updated
            interpolation points.

        Raises
        ------
        `numpy.linalg.LinAlgError`
            If the interpolation system is ill-defined.
        r   úThe index `k_new` is not valid.z$The shape of `dir_old` is not valid.z(The shape of `values_diff` is not valid.ç        )r   r<   r7   r    rj   ri   r   Úouterrf   rg   rh   )	r%   rZ   Úk_newÚdir_oldÚvalues_diffÚconstry   Úi_hessÚill_conditioneds	            r1   ÚupdatezQuadratic.updateµ  s3  € ð4 Œ;ð 	:Ø˜Ð(Ð(Ò(Ð( ¤Ò(Ð(Ð(Ð(Ð(Ð*KÑ(Ô(Ð(Ø”=Ø”ð%ò ð ð à5ñô ð ð Ô$Ø”ð)ò ð ð à9ñô ð ð 	ˆŒ˜œ UÔ+­b¬h°wÀÑ.HÔ.HÑHÑHˆŒØ!ˆŒ�UÑð 04¯ªØØñ0
ô 0
Ñ,ˆˆt�V˜_ð 	ˆŒ�uÑˆŒØˆ
Œ
�dÑˆ
Œ
ØˆŒ˜ÑˆŒØÐr3   c                 ó^  — | j         r|j        | j        fk    s
J d¦   «         ‚ | ||¦  «        | _        |                      ||¦  «        | _        ||j        z
  }t          j        ||j	        d|dd…t          j
        f         z  z
  | j        z  ¦  «        }| xj        ||j        z   z  c_        dS )aB  
        Shift the point around which the quadratic model is defined.

        Parameters
        ----------
        interpolation : `cobyqa.models.Interpolation`
            Previous interpolation set.
        new_x_base : `numpy.ndarray`, shape (n,)
            Point that will replace ``interpolation.x_base``.
        ú'The shape of `new_x_base` is not valid.r   N)r   r7   r    rg   ry   rh   r   r   r†   r$   r{   ri   rj   rX   )r%   rZ   Ú
new_x_baseÚshiftr�   s        r1   Úshift_x_basezQuadratic.shift_x_baseé  sÍ   € ð Œ;ð 	9ØÔ#Ø”ð(ò ð ð à8ñô ð ð �d˜: }Ñ5Ô5ˆŒØ—Y’Y˜z¨=Ñ9Ô9ˆŒ
Ø˜]Ô1Ñ1ˆÝ”ØØÔ  u¨Q¨Q¨Qµ´
¨]Ô';Ñ!;Ñ;¸t¼|ÑKñ
ô 
ˆð 	ˆŒ˜ ¤Ñ)Ñ)ˆŒˆˆr3   c                 óÂ  — | j         j        \  }}|j        dk    r|j        d         ||z   dz   k    s
J d¦   «         ‚t          | ¦  «        \  }}}||dd…t          j        f         z  }t	          j        t	          j        |¦  «        ¦  «        r&t	          j        t	          j        |¦  «        ¦  «        st          j         	                    d¦  «        ‚|\  }}	t	          j
        |¦  «        t          k    }
|	dd…|
f         }	d||
         z  }t	          j        |
d¦  «         }|	|	j        |z  |dd…t          j        f         z  z  }||dd…t          j        f         z  |fS )a•  
        Solve the interpolation systems.

        Parameters
        ----------
        interpolation : `cobyqa.models.Interpolation`
            Interpolation set.
        rhs : `numpy.ndarray`, shape (npt + n + 1, m)
            Right-hand side vectors of the ``m`` interpolation systems.

        Returns
        -------
        `numpy.ndarray`, shape (npt + n + 1, m)
            Solutions of the interpolation systems.
        `numpy.ndarray`, shape (m, )
            Whether the interpolation systems are ill-conditioned.

        Raises
        ------
        `numpy.linalg.LinAlgError`
            If the interpolation systems are ill-defined.
        r   r   r   z The shape of `rhs` is not valid.Nz(The interpolation system is ill-defined.rP   )r$   r7   Úndimr_   r   r{   ÚallÚisfiniterU   ÚLinAlgErrorÚabsrW   rX   )rZ   Úrhsr    r<   rJ   rK   ÚeigÚ
rhs_scaledr]   r^   Úlarge_eig_valuesÚinv_eig_valuesrŒ   Úleft_scaled_solutionss                 r1   Úsolve_systemszQuadratic.solve_systems  ss  € ð0 Ô"Ô(‰ˆˆ3àŒH˜ŠMˆM˜cœi¨œl¨c°A©g¸©kÒ9Ð9Ð9Ø-ñ :Ô9Ð9õ !-¨]Ñ ;Ô ;Ñˆˆ=˜#ð ˜=¨¨¨­B¬J¨Ô7Ñ7ˆ
Ý”•r”{ 1‘~”~Ñ&Ô&ð 	­2¬6µ"´+¸jÑ2IÔ2IÑ+JÔ+Jð 	Ý”)×'Ò'Ø:ñô ð ð
 #&Ñˆ
�Kåœ6 *Ñ-Ô-µÒ3ÐØ! ! ! !Ð%5Ð"5Ô6ˆØ˜zÐ*:Ô;Ñ;ˆÝœ6Ð"2°AÑ6Ô6Ð6ˆØ +ØŒ]˜ZÑ'¨>¸!¸!¸!½R¼Z¸-Ô+HÑHñ!
Ðð " M°!°!°!µR´Z°-Ô$@Ñ@Øð
ð 	
r3   c           
      ó:  — |j         | j        fk    s
J d¦   «         ‚| j        j         \  }}t                               | t          j        |t          j        |dz   ¦  «        gg¦  «        j        ¦  «        \  }}||df         ||dz   d…df         |d|…df         |fS )aÓ  
        Solve the interpolation system.

        Parameters
        ----------
        interpolation : `cobyqa.models.Interpolation`
            Interpolation set.
        values : `numpy.ndarray`, shape (npt,)
            Values of the interpolated function at the interpolation points.

        Returns
        -------
        float
            Constant term of the quadratic model.
        `numpy.ndarray`, shape (n,)
            Gradient of the quadratic model at ``interpolation.x_base``.
        `numpy.ndarray`, shape (npt,)
            Implicit Hessian matrix of the quadratic model.

        Raises
        ------
        `numpy.linalg.LinAlgError`
            If the interpolation system is ill-defined.
        rc   r   r   N)	r7   r<   r$   ra   rŸ   r   Úblockr   rX   )rZ   rk   r    r<   rq   rŒ   s         r1   rf   zQuadratic._get_modelB  sÊ   € ð4 Œ|ØÔð 
ò 
ð 
ð 
à0ñ
ô 
ð 
ð Ô"Ô(‰ˆˆ3Ý&×4Ò4ØÝŒHð Ýœ  Q¡™œððñô ô ñ

ô 

Ñˆˆ?ð ��a�Œy˜!˜C !™G˜H˜H a˜Kœ.¨!¨D¨S¨D°!¨G¬*°oÐEÐEr3   N)rC   rD   rE   rF   r2   rs   rG   r    r<   ry   r|   rx   r‚   r�   r’   ÚstaticmethodrŸ   rf   rI   r3   r1   ra   ra   ö   s  € € € € € ðð ð 2ð  2ð  2ðD
ð 
ð 
ð: ð	ð 	ñ „Xð	ð ð	!ð 	!ñ „Xð	!ðBð Bð Bð*
ð 
ð 
ð$
ð 
ð 
ð2
ð 
ð 
ð02ð 2ð 2ðh*ð *ð *ð0 ð>
ð >
ñ „\ð>
ð@ ð(Fð (Fñ „\ð(Fð (Fð (Fr3   ra   c                   ól  — e Zd ZdZd„ Zed„ ¦   «         Zed„ ¦   «         Zed„ ¦   «         Zed„ ¦   «         Z	ed„ ¦   «         Z
ed„ ¦   «         Zed	„ ¦   «         Zed
„ ¦   «         Zd„ Zd„ Zd„ Zd„ Zd„ 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„ Zd„ Zd#d„Z d„ Z!d#d „Z"d#d!„Z#d"„ Z$dS )$ÚModelsz6
    Models for a nonlinear optimization problem.
    c           	      óä  — |t           j                 | _        t          ||¦  «        | _        | j                             d¦  «        } |||¦  «        \  }}}t          j        |t           j	                 t          j
        ¦  «        | _        t          j        |t           j	                 |j        ft          j
        ¦  «        | _        t          j        |t           j	                 |j        ft          j
        ¦  «        | _        t          |t           j	                 ¦  «        D �]�}||t           j                 k    rt"          ‚|dk    r'|| j        |<   || j        |dd…f<   || j        |dd…f<   nJ| j                             |¦  «        } |||¦  «        \  | j        |<   | j        |dd…f<   | j        |dd…f<   |j        rh|                     | j                             |¦  «        | j        |dd…f         | j        |dd…f         ¦  «        |t           j                 k    rt0          ‚| j        |         |t           j                 k    rh|                     | j                             |¦  «        | j        |dd…f         | j        |dd…f         ¦  «        |t           j                 k    rt4          ‚�Œ‘t7          | j        | j        |t           j                 ¦  «        | _        t          j        | j        t6          ¬¦  «        | _        t          j        | j         t6          ¬¦  «        | _!        t          | j        ¦  «        D ]?}	t7          | j        | j        dd…|	f         |t           j                 ¦  «        | j        |	<   Œ@t          | j         ¦  «        D ]?}	t7          | j        | j        dd…|	f         |t           j                 ¦  «        | j!        |	<   Œ@| j        r|  "                    ¦   «          dS dS )aE  
        Initialize the models.

        Parameters
        ----------
        pb : `cobyqa.problem.Problem`
            Problem to be solved.
        options : dict
            Options of the solver.
        penalty : float
            Penalty parameter used to select the point in the filter to forward
            to the callback function.

        Raises
        ------
        `cobyqa.utils.MaxEvalError`
            If the maximum number of evaluations is reached.
        `cobyqa.utils.TargetSuccess`
            If a nearly feasible point has been found with an objective
            function value below the target.
        `cobyqa.utils.FeasibleSuccess`
            If a feasible point has been found for a feasibility problem.
        `numpy.linalg.LinAlgError`
            If the interpolation system is ill-defined.
        r   N)Údtype)#r   r   r   r
   Ú_interpolationrZ   rB   r   Úfullr!   ÚnanÚ_fun_valru   Ú_cub_valÚ_ceq_valr#   ÚMAX_EVALr   Úfun_valÚcub_valÚceq_valÚis_feasibilityÚmaxcvÚFEASIBILITY_TOLr   ÚTARGETr   ra   Ú_funrY   Úm_nonlinear_ubÚ_cubÚm_nonlinear_eqÚ_ceqÚ_check_interpolation_conditions)
r%   r&   r'   ÚpenaltyÚx_evalÚfun_initÚcub_initÚceq_initr-   Úis
             r1   r2   zModels.__init__s  s±  € ð6 �gœmÔ,ˆŒÝ+¨B°Ñ8Ô8ˆÔð Ô#×)Ò)¨!Ñ,Ô,ˆØ') r¨&°'Ñ':Ô':Ñ$ˆ�(˜HÝœ ­¬Ô 4µb´fÑ=Ô=ˆŒÝœ ­¬Ô!5°x´}Ð EÅrÄvÑNÔNˆŒÝœ ­¬Ô!5°x´}Ð EÅrÄvÑNÔNˆŒÝ�w�wœ{Ô+Ñ,Ô,ð &	$ñ &	$ˆAØ�G�GÔ,Ô-Ò-Ð-Ý"Ð"Ø�AŠvˆvØ"*�”˜Q‘Ø%-�”˜Q   ˜TÑ"Ø%-�”˜Q   ˜TÑ"Ð"àÔ+×1Ò1°!Ñ4Ô4�ØJLÈ"ØØñKô KÑG�”˜Q‘ ¤¨a°°°¨dÑ!3°T´\À!ÀQÀQÀQÀ$Ñ5Gð Ô!ð	&à—H’HØÔ&×,Ò,¨QÑ/Ô/Ø”L  A A A Ô&Ø”L  A A A Ô&ñô ð
 �7Ô2Ô3ò4ð 4õ &Ð%ð
 ”˜aÔ  G­G¬NÔ$;Ò;Ð;Ø—H’HØÔ&×,Ò,¨QÑ/Ô/Ø”L  A A A Ô&Ø”L  A A A Ô&ñô ð
 �7Ô2Ô3ò4ð 4õ $Ð#ùõ ØÔØŒMØ•G”MÔ"ñ
ô 
ˆŒ	õ
 ”H˜TÔ0½	ÐBÑBÔBˆŒ	Ý”H˜TÔ0½	ÐBÑBÔBˆŒ	Ý�tÔ*Ñ+Ô+ð 	ð 	ˆAÝ$ØÔ"Ø”˜Q˜Q˜Q ˜TÔ"Ø�œÔ&ñô ˆDŒI�a‰LˆLõ
 �tÔ*Ñ+Ô+ð 	ð 	ˆAÝ$ØÔ"Ø”˜Q˜Q˜Q ˜TÔ"Ø�œÔ&ñô ˆDŒI�a‰LˆLð
 Œ;ð 	3Ø×0Ò0Ñ2Ô2Ð2Ð2Ð2ð	3ð 	3r3   c                 ó   — | j         j        S )z~
        Dimension of the problem.

        Returns
        -------
        int
            Dimension of the problem.
        )rZ   r    r8   s    r1   r    zModels.nÖ  s   € ð Ô!Ô#Ð#r3   c                 ó   — | j         j        S )r;   )rZ   r<   r8   s    r1   r<   z
Models.nptâ  s   € ð Ô!Ô%Ð%r3   c                 ó&   — | j         j        d         S )z¢
        Number of nonlinear inequality constraints.

        Returns
        -------
        int
            Number of nonlinear inequality constraints.
        r   )r¯   r7   r8   s    r1   r¶   zModels.m_nonlinear_ubî  ó   € ð Œ|Ô! !Ô$Ð$r3   c                 ó&   — | j         j        d         S )zž
        Number of nonlinear equality constraints.

        Returns
        -------
        int
            Number of nonlinear equality constraints.
        r   )r°   r7   r8   s    r1   r¸   zModels.m_nonlinear_eqú  rÄ   r3   c                 ó   — | j         S )zŠ
        Interpolation set.

        Returns
        -------
        `cobyqa.models.Interpolation`
            Interpolation set.
        )r§   r8   s    r1   rZ   zModels.interpolation  s   € ð Ô"Ð"r3   c                 ó   — | j         S )zà
        Values of the objective function at the interpolation points.

        Returns
        -------
        `numpy.ndarray`, shape (npt,)
            Values of the objective function at the interpolation points.
        )rª   r8   s    r1   r®   zModels.fun_val  s   € ð Œ}Ðr3   c                 ó   — | j         S )a1  
        Values of the nonlinear inequality constraint functions at the
        interpolation points.

        Returns
        -------
        `numpy.ndarray`, shape (npt, m_nonlinear_ub)
            Values of the nonlinear inequality constraint functions at the
            interpolation points.
        )r«   r8   s    r1   r¯   zModels.cub_val  ó   € ð Œ}Ðr3   c                 ó   — | j         S )a-  
        Values of the nonlinear equality constraint functions at the
        interpolation points.

        Returns
        -------
        `numpy.ndarray`, shape (npt, m_nonlinear_eq)
            Values of the nonlinear equality constraint functions at the
            interpolation points.
        )r¬   r8   s    r1   r°   zModels.ceq_val,  rÉ   r3   c                 ó|   — | j         r|j        | j        fk    s
J d¦   «         ‚|                      || j        ¦  «        S )a�  
        Evaluate the quadratic model of the objective function at a given
        point.

        Parameters
        ----------
        x : `numpy.ndarray`, shape (n,)
            Point at which to evaluate the quadratic model of the objective
            function.

        Returns
        -------
        float
            Value of the quadratic model of the objective function at `x`.
        ro   )r   r7   r    rµ   rZ   ©r%   rq   s     r1   Úfunz
Models.fun:  sF   € ð  Œ;ð 	JØ”7˜tœv˜iÒ'Ð'Ð'Ð)IÑ'Ô'Ð'Ø�yŠy˜˜DÔ.Ñ/Ô/Ð/r3   c                 ó†   — | j         r|j        | j        fk    s
J d¦   «         ‚| j                             || j        ¦  «        S )aÆ  
        Evaluate the gradient of the quadratic model of the objective function
        at a given point.

        Parameters
        ----------
        x : `numpy.ndarray`, shape (n,)
            Point at which to evaluate the gradient of the quadratic model of
            the objective function.

        Returns
        -------
        `numpy.ndarray`, shape (n,)
            Gradient of the quadratic model of the objective function at `x`.
        ro   )r   r7   r    rµ   ry   rZ   rÌ   s     r1   Úfun_gradzModels.fun_gradN  sH   € ð  Œ;ð 	JØ”7˜tœv˜iÒ'Ð'Ð'Ð)IÑ'Ô'Ð'ØŒy�~Š~˜a Ô!3Ñ4Ô4Ð4r3   c                 ó@   — | j                              | j        ¦  «        S )zû
        Evaluate the Hessian matrix of the quadratic model of the objective
        function.

        Returns
        -------
        `numpy.ndarray`, shape (n, n)
            Hessian matrix of the quadratic model of the objective function.
        )rµ   r|   rZ   r8   s    r1   Úfun_hesszModels.fun_hessb  s   € ð Œy�~Š~˜dÔ0Ñ1Ô1Ð1r3   c                 ó†   — | j         r|j        | j        fk    s
J d¦   «         ‚| j                             || j        ¦  «        S )a'  
        Evaluate the right product of the Hessian matrix of the quadratic model
        of the objective function with a given vector.

        Parameters
        ----------
        v : `numpy.ndarray`, shape (n,)
            Vector with which the Hessian matrix of the quadratic model of the
            objective function is multiplied from the right.

        Returns
        -------
        `numpy.ndarray`, shape (n,)
            Right product of the Hessian matrix of the quadratic model of the
            objective function with `v`.
        r~   )r   r7   r    rµ   rx   rZ   ©r%   r€   s     r1   Úfun_hess_prodzModels.fun_hess_prodn  sJ   € ð" Œ;ð 	JØ”7˜tœv˜iÒ'Ð'Ð'Ð)IÑ'Ô'Ð'ØŒy×"Ò" 1 dÔ&8Ñ9Ô9Ð9r3   c                 ó†   — | j         r|j        | j        fk    s
J d¦   «         ‚| j                             || j        ¦  «        S )aÑ  
        Evaluate the curvature of the quadratic model of the objective function
        along a given direction.

        Parameters
        ----------
        v : `numpy.ndarray`, shape (n,)
            Direction along which the curvature of the quadratic model of the
            objective function is evaluated.

        Returns
        -------
        float
            Curvature of the quadratic model of the objective function along
            `v`.
        r~   )r   r7   r    rµ   r‚   rZ   rÓ   s     r1   Úfun_curvzModels.fun_curvƒ  sH   € ð" Œ;ð 	JØ”7˜tœv˜iÒ'Ð'Ð'Ð)IÑ'Ô'Ð'ØŒy�~Š~˜a Ô!3Ñ4Ô4Ð4r3   c                 ó¼   — | j         r|j        | j        fk    s
J d¦   «         ‚t          | j        | j        | j         ¦  «        }|                     || j        ¦  «        S )ap  
        Evaluate the gradient of the alternative quadratic model of the
        objective function at a given point.

        Parameters
        ----------
        x : `numpy.ndarray`, shape (n,)
            Point at which to evaluate the gradient of the alternative
            quadratic model of the objective function.

        Returns
        -------
        `numpy.ndarray`, shape (n,)
            Gradient of the alternative quadratic model of the objective
            function at `x`.

        Raises
        ------
        `numpy.linalg.LinAlgError`
            If the interpolation system is ill-defined.
        ro   )r   r7   r    ra   rZ   r®   ry   )r%   rq   Úmodels      r1   Úfun_alt_gradzModels.fun_alt_grad˜  s^   € ð, Œ;ð 	JØ”7˜tœv˜iÒ'Ð'Ð'Ð)IÑ'Ô'Ð'Ý˜$Ô,¨d¬l¸D¼KÑHÔHˆØ�zŠz˜!˜TÔ/Ñ0Ô0Ð0r3   Nc                 óì   ‡ ‡— ‰ j         r8‰j        ‰ j        fk    s
J d¦   «         ‚|�|j        ‰ j        fk    s
J d¦   «         ‚t	          j        ˆ ˆfd„‰                      |¦  «        D ¦   «         ¦  «        S )a;  
        Evaluate the quadratic models of the nonlinear inequality functions at
        a given point.

        Parameters
        ----------
        x : `numpy.ndarray`, shape (n,)
            Point at which to evaluate the quadratic models of the nonlinear
            inequality functions.
        mask : `numpy.ndarray`, shape (m_nonlinear_ub,), optional
            Mask of the quadratic models to consider.

        Returns
        -------
        `numpy.ndarray`
            Values of the quadratic model of the nonlinear inequality
            functions.
        ro   Nú!The shape of `mask` is not valid.c                 ó2   •— g | ]} |‰‰j         ¦  «        ‘ŒS rI   ©rZ   ©Ú.0rØ   r%   rq   s     €€r1   ú
<listcomp>zModels.cub.<locals>.<listcomp>Ì  ó(   ø€ ÐKÐKÐK¨eˆUˆU�1�dÔ(Ñ)Ô)ÐKÐKÐKr3   ©r   r7   r    r¶   r   ÚarrayÚ_get_cub©r%   rq   Úmasks   `` r1   Úcubz
Models.cub³  s¡   øø€ ð& Œ;ð 	3Ø”7˜tœv˜iÒ'Ð'Ð'Ð)IÑ'Ô'Ð'Ø�< 4¤:ØÔ#ð2ò $ð $ð $à2ñ$ô $ð $õ ŒxØKÐKÐKÐKÐK°t·}²}ÀTÑ7JÔ7JÐKÑKÔKñ
ô 
ð 	
r3   c                 óü   ‡ ‡— ‰ j         r8‰j        ‰ j        fk    s
J d¦   «         ‚|�|j        ‰ j        fk    s
J d¦   «         ‚t	          j        ˆ ˆfd„‰                      |¦  «        D ¦   «         d‰ j        f¦  «        S )a`  
        Evaluate the gradients of the quadratic models of the nonlinear
        inequality functions at a given point.

        Parameters
        ----------
        x : `numpy.ndarray`, shape (n,)
            Point at which to evaluate the gradients of the quadratic models of
            the nonlinear inequality functions.
        mask : `numpy.ndarray`, shape (m_nonlinear_eq,), optional
            Mask of the quadratic models to consider.

        Returns
        -------
        `numpy.ndarray`
            Gradients of the quadratic model of the nonlinear inequality
            functions.
        ro   NrÛ   c                 óF   •— g | ]}|                      ‰‰j        ¦  «        ‘ŒS rI   ©ry   rZ   rÞ   s     €€r1   rà   z#Models.cub_grad.<locals>.<listcomp>è  ó:   ø€ ð /ð /ð /Øð �ZŠZ˜˜4Ô-Ñ.Ô.ð /ð /ð /r3   éÿÿÿÿ©r   r7   r    r¶   r   Úreshaperä   rå   s   `` r1   Úcub_gradzModels.cub_gradÏ  ó»   øø€ ð& Œ;ð 	3Ø”7˜tœv˜iÒ'Ð'Ð'Ð)IÑ'Ô'Ð'Ø�< 4¤:ØÔ#ð2ò $ð $ð $à2ñ$ô $ð $õ Œzð/ð /ð /ð /ð /ØŸ-š-¨Ñ-Ô-ð/ñ /ô /à�”ˆLñ
ô 
ð 	
r3   c                 óÎ   ‡ — ‰ j         r|�|j        ‰ j        fk    s
J d¦   «         ‚t          j        ˆ fd„‰                      |¦  «        D ¦   «         d‰ j        ‰ j        f¦  «        S )a¶  
        Evaluate the Hessian matrices of the quadratic models of the nonlinear
        inequality functions.

        Parameters
        ----------
        mask : `numpy.ndarray`, shape (m_nonlinear_ub,), optional
            Mask of the quadratic models to consider.

        Returns
        -------
        `numpy.ndarray`
            Hessian matrices of the quadratic models of the nonlinear
            inequality functions.
        NrÛ   c                 óD   •— g | ]}|                      ‰j        ¦  «        ‘ŒS rI   ©r|   rZ   ©rß   rØ   r%   s     €r1   rà   z#Models.cub_hess.<locals>.<listcomp>  ó(   ø€ ÐMÐMÐM°ˆU�ZŠZ˜Ô*Ñ+Ô+ÐMÐMÐMr3   rì   )r   r7   r¶   r   rî   rä   r    ©r%   ræ   s   ` r1   Úcub_hesszModels.cub_hessí  ó‹   ø€ ð  Œ;ð 	3Ø�< 4¤:ØÔ#ð2ò $ð $ð $à2ñ$ô $ð $õ ŒzØMÐMÐMÐM¸¿ºÀtÑ9LÔ9LÐMÑMÔMØ�”˜œÐ ñ
ô 
ð 	
r3   c                 óü   ‡ ‡— ‰ j         r8‰j        ‰ j        fk    s
J d¦   «         ‚|�|j        ‰ j        fk    s
J d¦   «         ‚t	          j        ˆ ˆfd„‰                      |¦  «        D ¦   «         d‰ j        f¦  «        S )aÂ  
        Evaluate the right product of the Hessian matrices of the quadratic
        models of the nonlinear inequality functions with a given vector.

        Parameters
        ----------
        v : `numpy.ndarray`, shape (n,)
            Vector with which the Hessian matrices of the quadratic models of
            the nonlinear inequality functions are multiplied from the right.
        mask : `numpy.ndarray`, shape (m_nonlinear_ub,), optional
            Mask of the quadratic models to consider.

        Returns
        -------
        `numpy.ndarray`
            Right products of the Hessian matrices of the quadratic models of
            the nonlinear inequality functions with `v`.
        r~   NrÛ   c                 óF   •— g | ]}|                      ‰‰j        ¦  «        ‘ŒS rI   ©rx   rZ   ©rß   rØ   r%   r€   s     €€r1   rà   z(Models.cub_hess_prod.<locals>.<listcomp>  ó:   ø€ ð ð ð àð —’  4Ô#5Ñ6Ô6ðð ð r3   rì   rí   ©r%   r€   ræ   s   `` r1   Úcub_hess_prodzModels.cub_hess_prod  ó½   øø€ ð& Œ;ð 	3Ø”7˜tœv˜iÒ'Ð'Ð'Ð)IÑ'Ô'Ð'Ø�< 4¤:ØÔ#ð2ò $ð $ð $à2ñ$ô $ð $õ Œzðð ð ð ð à!Ÿ]š]¨4Ñ0Ô0ðñ ô ð �”ˆLñ
ô 
ð 	
r3   c                 óì   ‡ ‡— ‰ j         r8‰j        ‰ j        fk    s
J d¦   «         ‚|�|j        ‰ j        fk    s
J d¦   «         ‚t	          j        ˆ ˆfd„‰                      |¦  «        D ¦   «         ¦  «        S )az  
        Evaluate the curvature of the quadratic models of the nonlinear
        inequality functions along a given direction.

        Parameters
        ----------
        v : `numpy.ndarray`, shape (n,)
            Direction along which the curvature of the quadratic models of the
            nonlinear inequality functions is evaluated.
        mask : `numpy.ndarray`, shape (m_nonlinear_ub,), optional
            Mask of the quadratic models to consider.

        Returns
        -------
        `numpy.ndarray`
            Curvature of the quadratic models of the nonlinear inequality
            functions along `v`.
        r~   NrÛ   c                 óF   •— g | ]}|                      ‰‰j        ¦  «        ‘ŒS rI   ©r‚   rZ   rü   s     €€r1   rà   z#Models.cub_curv.<locals>.<listcomp>?  rë   r3   râ   rþ   s   `` r1   Úcub_curvzModels.cub_curv&  ó²   øø€ ð& Œ;ð 	3Ø”7˜tœv˜iÒ'Ð'Ð'Ð)IÑ'Ô'Ð'Ø�< 4¤:ØÔ#ð2ò $ð $ð $à2ñ$ô $ð $õ Œxð/ð /ð /ð /ð /ØŸ-š-¨Ñ-Ô-ð/ñ /ô /ñ
ô 
ð 	
r3   c                 óì   ‡ ‡— ‰ j         r8‰j        ‰ j        fk    s
J d¦   «         ‚|�|j        ‰ j        fk    s
J d¦   «         ‚t	          j        ˆ ˆfd„‰                      |¦  «        D ¦   «         ¦  «        S )a)  
        Evaluate the quadratic models of the nonlinear equality functions at a
        given point.

        Parameters
        ----------
        x : `numpy.ndarray`, shape (n,)
            Point at which to evaluate the quadratic models of the nonlinear
            equality functions.
        mask : `numpy.ndarray`, shape (m_nonlinear_eq,), optional
            Mask of the quadratic models to consider.

        Returns
        -------
        `numpy.ndarray`
            Values of the quadratic model of the nonlinear equality functions.
        ro   NrÛ   c                 ó2   •— g | ]} |‰‰j         ¦  «        ‘ŒS rI   rÝ   rÞ   s     €€r1   rà   zModels.ceq.<locals>.<listcomp>[  rá   r3   ©r   r7   r    r¸   r   rã   Ú_get_ceqrå   s   `` r1   Úceqz
Models.ceqC  s¡   øø€ ð$ Œ;ð 	3Ø”7˜tœv˜iÒ'Ð'Ð'Ð)IÑ'Ô'Ð'Ø�< 4¤:ØÔ#ð2ò $ð $ð $à2ñ$ô $ð $õ ŒxØKÐKÐKÐKÐK°t·}²}ÀTÑ7JÔ7JÐKÑKÔKñ
ô 
ð 	
r3   c                 óü   ‡ ‡— ‰ j         r8‰j        ‰ j        fk    s
J d¦   «         ‚|�|j        ‰ j        fk    s
J d¦   «         ‚t	          j        ˆ ˆfd„‰                      |¦  «        D ¦   «         d‰ j        f¦  «        S )aZ  
        Evaluate the gradients of the quadratic models of the nonlinear
        equality functions at a given point.

        Parameters
        ----------
        x : `numpy.ndarray`, shape (n,)
            Point at which to evaluate the gradients of the quadratic models of
            the nonlinear equality functions.
        mask : `numpy.ndarray`, shape (m_nonlinear_eq,), optional
            Mask of the quadratic models to consider.

        Returns
        -------
        `numpy.ndarray`
            Gradients of the quadratic model of the nonlinear equality
            functions.
        ro   NrÛ   c                 óF   •— g | ]}|                      ‰‰j        ¦  «        ‘ŒS rI   rê   rÞ   s     €€r1   rà   z#Models.ceq_grad.<locals>.<listcomp>w  rë   r3   rì   ©r   r7   r    r¸   r   rî   r	  rå   s   `` r1   Úceq_gradzModels.ceq_grad^  rð   r3   c                 óÎ   ‡ — ‰ j         r|�|j        ‰ j        fk    s
J d¦   «         ‚t          j        ˆ fd„‰                      |¦  «        D ¦   «         d‰ j        ‰ j        f¦  «        S )a²  
        Evaluate the Hessian matrices of the quadratic models of the nonlinear
        equality functions.

        Parameters
        ----------
        mask : `numpy.ndarray`, shape (m_nonlinear_eq,), optional
            Mask of the quadratic models to consider.

        Returns
        -------
        `numpy.ndarray`
            Hessian matrices of the quadratic models of the nonlinear equality
            functions.
        NrÛ   c                 óD   •— g | ]}|                      ‰j        ¦  «        ‘ŒS rI   ró   rô   s     €r1   rà   z#Models.ceq_hess.<locals>.<listcomp>‘  rõ   r3   rì   )r   r7   r¸   r   rî   r	  r    rö   s   ` r1   Úceq_hesszModels.ceq_hess|  rø   r3   c                 óü   ‡ ‡— ‰ j         r8‰j        ‰ j        fk    s
J d¦   «         ‚|�|j        ‰ j        fk    s
J d¦   «         ‚t	          j        ˆ ˆfd„‰                      |¦  «        D ¦   «         d‰ j        f¦  «        S )a¼  
        Evaluate the right product of the Hessian matrices of the quadratic
        models of the nonlinear equality functions with a given vector.

        Parameters
        ----------
        v : `numpy.ndarray`, shape (n,)
            Vector with which the Hessian matrices of the quadratic models of
            the nonlinear equality functions are multiplied from the right.
        mask : `numpy.ndarray`, shape (m_nonlinear_eq,), optional
            Mask of the quadratic models to consider.

        Returns
        -------
        `numpy.ndarray`
            Right products of the Hessian matrices of the quadratic models of
            the nonlinear equality functions with `v`.
        r~   NrÛ   c                 óF   •— g | ]}|                      ‰‰j        ¦  «        ‘ŒS rI   rû   rü   s     €€r1   rà   z(Models.ceq_hess_prod.<locals>.<listcomp>®  rý   r3   rì   r  rþ   s   `` r1   Úceq_hess_prodzModels.ceq_hess_prod•  r   r3   c                 óì   ‡ ‡— ‰ j         r8‰j        ‰ j        fk    s
J d¦   «         ‚|�|j        ‰ j        fk    s
J d¦   «         ‚t	          j        ˆ ˆfd„‰                      |¦  «        D ¦   «         ¦  «        S )at  
        Evaluate the curvature of the quadratic models of the nonlinear
        equality functions along a given direction.

        Parameters
        ----------
        v : `numpy.ndarray`, shape (n,)
            Direction along which the curvature of the quadratic models of the
            nonlinear equality functions is evaluated.
        mask : `numpy.ndarray`, shape (m_nonlinear_eq,), optional
            Mask of the quadratic models to consider.

        Returns
        -------
        `numpy.ndarray`
            Curvature of the quadratic models of the nonlinear equality
            functions along `v`.
        r~   NrÛ   c                 óF   •— g | ]}|                      ‰‰j        ¦  «        ‘ŒS rI   r  rü   s     €€r1   rà   z#Models.ceq_curv.<locals>.<listcomp>Î  rë   r3   r  rþ   s   `` r1   Úceq_curvzModels.ceq_curvµ  r  r3   c                 ó®  — t          | j        | j        | j        ¦  «        | _        t          | j        ¦  «        D ]4}t          | j        | j        dd…|f         | j        ¦  «        | j        |<   Œ5t          | j	        ¦  «        D ]4}t          | j        | j
        dd…|f         | j        ¦  «        | j        |<   Œ5| j        r|                      ¦   «          dS dS )a9  
        Set the quadratic models of the objective function, nonlinear
        inequality constraints, and nonlinear equality constraints to the
        alternative quadratic models.

        Raises
        ------
        `numpy.linalg.LinAlgError`
            If the interpolation system is ill-defined.
        N)ra   rZ   r®   r   rµ   r#   r¶   r¯   r·   r¸   r°   r¹   rº   )r%   rÀ   s     r1   Úreset_modelszModels.reset_modelsÒ  sê   € õ ˜dÔ0°$´,ÀÄÑLÔLˆŒ	Ý�tÔ*Ñ+Ô+ð 	ð 	ˆAÝ$ØÔ"Ø”˜Q˜Q˜Q ˜TÔ"Ø”ñô ˆDŒI�a‰LˆLõ
 �tÔ*Ñ+Ô+ð 	ð 	ˆAÝ$ØÔ"Ø”˜Q˜Q˜Q ˜TÔ"Ø”ñô ˆDŒI�a‰LˆLð
 Œ;ð 	3Ø×0Ò0Ñ2Ô2Ð2Ð2Ð2ð	3ð 	3r3   c           	      ó  — | j         rŽd|cxk    r| j        k     sn J d¦   «         ‚|j        | j        fk    s
J d¦   «         ‚t	          |t
          ¦  «        s
J d¦   «         ‚|j        | j        fk    s
J d¦   «         ‚|j        | j        fk    s
J d¦   «         ‚t          j	        | j        ¦  «        }t          j	        | j
        j        ¦  «        }t          j	        | j        j        ¦  «        }||                      |¦  «        z
  ||<   ||                      |¦  «        z
  ||dd…f<   ||                      |¦  «        z
  ||dd…f<   || j        |<   || j
        |dd…f<   || j        |dd…f<   t          j        | j        j        dd…|f         ¦  «        }	|| j        j        z
  | j        j        dd…|f<   | j                             | j        ||	|¦  «        }
t-          | j        ¦  «        D ]6}|
p1| j        |                              | j        ||	|dd…|f         ¦  «        }
Œ7t-          | j        ¦  «        D ]6}|
p1| j        |                              | j        ||	|dd…|f         ¦  «        }
Œ7| j         r|                      ¦   «          |
S )aÿ  
        Update the interpolation set.

        This method updates the interpolation set by replacing the `knew`-th
        interpolation point with `xnew`. It also updates the function values
        and the quadratic models.

        Parameters
        ----------
        k_new : int
            Index of the updated interpolation point.
        x_new : `numpy.ndarray`, shape (n,)
            New interpolation point. Its value is interpreted as relative to
            the origin, not the base point.
        fun_val : float
            Value of the objective function at `x_new`.
            Objective function value at `x_new`.
        cub_val : `numpy.ndarray`, shape (m_nonlinear_ub,)
            Values of the nonlinear inequality constraints at `x_new`.
        ceq_val : `numpy.ndarray`, shape (m_nonlinear_eq,)
            Values of the nonlinear equality constraints at `x_new`.

        Raises
        ------
        `numpy.linalg.LinAlgError`
            If the interpolation system is ill-defined.
        r   r„   ú"The shape of `x_new` is not valid.z The function value is not valid.z$The shape of `cub_val` is not valid.z$The shape of `ceq_val` is not valid.N)r   r<   r7   r    Ú
isinstanceÚfloatr¶   r¸   r   r   r¯   r°   rÍ   rç   r
  r®   r   rZ   r$   r   rµ   r�   r#   r·   r¹   rº   )r%   r‡   Úx_newr®   r¯   r°   Úfun_diffÚcub_diffÚceq_diffrˆ   rŒ   rÀ   s               r1   Úupdate_interpolationzModels.update_interpolationí  s  € ð8 Œ;ð 	6Ø˜Ð(Ð(Ò(Ð( ¤Ò(Ð(Ð(Ð(Ð(Ð*KÑ(Ô(Ð(Ø”; 4¤6 )Ò+Ð+Ð+Ø4ñ ,Ô+Ð+å˜g¥uÑ-Ô-ð 3ð 3Ø2ñ3ô 3ð 3à”=ØÔ#ð%ò ð ð à5ñô ð ð ”=ØÔ#ð%ò ð ð à5ñô ð õ
 ”8˜DœHÑ%Ô%ˆÝ”8˜DœLÔ.Ñ/Ô/ˆÝ”8˜DœLÔ.Ñ/Ô/ˆØ! D§H¢H¨U¡O¤OÑ3ˆ�‰Ø$ t§x¢x°¡¤Ñ6ˆ�˜˜˜�ÑØ$ t§x¢x°¡¤Ñ6ˆ�˜˜˜�Ñð &ˆŒ�UÑØ!(ˆŒ�U˜A˜A˜A�XÑØ!(ˆŒ�U˜A˜A˜A�XÑõ ”'˜$Ô,Ô0°°°°E°Ô:Ñ;Ô;ˆØ+0°4Ô3EÔ3LÑ+LˆÔÔ˜q˜q˜q %˜xÑ(ð œ)×*Ò*ØÔØØØñ	
ô 
ˆõ �tÔ*Ñ+Ô+ð 	ð 	ˆAØ-ð °´¸1´×1DÒ1DØÔ"ØØØ˜˜˜˜A˜”ñ	2ô 2ˆOˆOõ �tÔ*Ñ+Ô+ð 	ð 	ˆAØ-ð °´¸1´×1DÒ1DØÔ"ØØØ˜˜˜˜A˜”ñ	2ô 2ˆOˆOð Œ;ð 	3Ø×0Ò0Ñ2Ô2Ð2ØÐr3   c                 óÌ  — | j         r;|j        | j        fk    s
J d¦   «         ‚|�d|cxk    r| j        k     sn J d¦   «         ‚|| j        j        z
  }t          j        | j        | j        z   dz   df¦  «        }d| j        j        j	        |z  dz  z  |d| j        …df<   d|| j        df<   ||| j        dz   d…df<   t                               | j        |¦  «        d         }d||z  dz  z  |dd…df         |dd…df         z  z
  }|€tt          j        | j        | j        z   dz   | j        ¦  «        }t          j        t                               | j        |¦  «        d         ¦  «        }|d| j        …df         }	n_t          j        | j        | j        z   dz   d| ¦  «        }t                               | j        |¦  «        d         |df         }||df         }	||z  |	dz  z   S )	aÎ  
        Compute the normalized determinants of the new interpolation systems.

        Parameters
        ----------
        x_new : `numpy.ndarray`, shape (n,)
            New interpolation point. Its value is interpreted as relative to
            the origin, not the base point.
        k_new : int, optional
            Index of the updated interpolation point. If `k_new` is not
            specified, all the possible determinants are computed.

        Returns
        -------
        {float, `numpy.ndarray`, shape (npt,)}
            Determinant(s) of the new interpolation system.

        Raises
        ------
        `numpy.linalg.LinAlgError`
            If the interpolation system is ill-defined.

        Notes
        -----
        The determinants are normalized by the determinant of the current
        interpolation system. For stability reasons, the calculations are done
        using the formula (2.12) in [1]_.

        References
        ----------
        .. [1] M. J. D. Powell. On updating the inverse of a KKT matrix.
           Technical Report DAMTP 2004/NA01, Department of Applied Mathematics
           and Theoretical Physics, University of Cambridge, Cambridge, UK,
           2004.
        r  Nr   r„   r   r   r   rP   )r   r7   r    r<   rZ   r   r   rY   r$   rX   ra   rŸ   ÚeyeÚdiag)
r%   r  r‡   r‘   Únew_colÚinv_new_colÚbetaÚ	coord_vecÚalphaÚtaus
             r1   ÚdeterminantszModels.determinants@  s;  € ðH Œ;ð 	1Ø”; 4¤6 )Ò+Ð+Ð+Ø4ñ ,Ô+Ð+ð �  eÐ!6Ð!6Ò!6Ð!6¨d¬hÒ!6Ð!6Ð!6Ð!6Ð!6Ø0ñ "7Ô!6Ð!6ð ˜Ô*Ô1Ñ1ˆÝ”(˜DœH t¤vÑ-°Ñ1°1Ð5Ñ6Ô6ˆà�tÔ)Ô-Ô/°%Ñ7¸CÑ?Ñ?ð 	�
�$”(�
˜A�Ñà"ˆ�”˜!�ÑØ$)ˆ�”˜1‘��˜qÐ Ñ!Ý×-Ò-¨dÔ.@À'ÑJÔJÈ1ÔMˆØ�e˜e‘m¨Ñ+Ñ+¨g°a°a°a¸°d¬m¸kÈ!È!È!ÈQÈ$Ô>OÑ.OÑOˆð ˆ=Ýœ˜tœx¨$¬&Ñ0°1Ñ4°d´hÑ?Ô?ˆIÝ”GÝ×'Ò'ØÔ&Øñô ð ôñô ˆEð ˜j ¤˜j¨!˜mÔ,ˆCˆCåœ˜tœx¨$¬&Ñ0°1Ñ4°a¸%¸Ñ@Ô@ˆIÝ×+Ò+ØÔ"Øñô ð ô	ð
 �QˆhôˆEð ˜e Q˜hÔ'ˆCØ�t‰|˜c 3™hÑ&Ð&r3   c                 ó  — | j         r|j        | j        fk    s
J d¦   «         ‚| j                             | j        |¦  «         | j        D ]}|                     | j        |¦  «         Œ| j        D ]}|                     | j        |¦  «         Œ|| j        j        z
  }| j        xj        |z  c_        | j        xj	        |dd…t          j        f         z  c_	        |t          j                 r|                      ¦   «          dS dS )zü
        Shift the base point without changing the interpolation set.

        Parameters
        ----------
        new_x_base : `numpy.ndarray`, shape (n,)
            New base point.
        options : dict
            Options of the solver.
        r�   N)r   r7   r    rµ   r’   rZ   r·   r¹   r   r$   r   r{   r   r   rº   )r%   r�   r'   rØ   r‘   s        r1   r’   zModels.shift_x_baseŠ  s6  € ð Œ;ð 	9ØÔ#Ø”ð(ò ð ð à8ñô ð ð
 	Œ	×Ò˜tÔ1°:Ñ>Ô>Ð>Ø”Yð 	?ð 	?ˆEØ×Ò˜tÔ1°:Ñ>Ô>Ð>Ð>Ø”Yð 	?ð 	?ˆEØ×Ò˜tÔ1°:Ñ>Ô>Ð>Ð>ð ˜TÔ/Ô6Ñ6ˆØÔÐ!Ô! UÑ*Ð!Ô!ØÔÐÔ %¨¨¨­2¬:¨Ô"6Ñ6ÐÔØ•7”=Ô!ð 	3Ø×0Ò0Ñ2Ô2Ð2Ð2Ð2ð	3ð 	3r3   c                 ó.   — |€| j         n| j         |         S )ao  
        Get the quadratic models of the nonlinear inequality constraints.

        Parameters
        ----------
        mask : `numpy.ndarray`, shape (m_nonlinear_ub,), optional
            Mask of the quadratic models to return.

        Returns
        -------
        `numpy.ndarray`
            Quadratic models of the nonlinear inequality constraints.
        )r·   rö   s     r1   rä   zModels._get_cub¨  ó   € ð !˜LˆtŒyˆy¨d¬i¸¬oÐ=r3   c                 ó.   — |€| j         n| j         |         S )ak  
        Get the quadratic models of the nonlinear equality constraints.

        Parameters
        ----------
        mask : `numpy.ndarray`, shape (m_nonlinear_eq,), optional
            Mask of the quadratic models to return.

        Returns
        -------
        `numpy.ndarray`
            Quadratic models of the nonlinear equality constraints.
        )r¹   rö   s     r1   r	  zModels._get_ceq¸  r/  r3   c                 óæ  — d}d}d}t          | j        ¦  «        D �].}t          j        |t          j        |                      | j                             |¦  «        ¦  «        | j        |         z
  ¦  «        g¦  «        }t          j        t          j        |  	                    | j                             |¦  «        ¦  «        | j
        |dd…f         z
  ¦  «        |¬¦  «        }t          j        t          j        |                      | j                             |¦  «        ¦  «        | j        |dd…f         z
  ¦  «        |¬¦  «        }�Œ0dt          j        t          ¦  «        z  t          | j        | j        ¦  «        z  }||t          j        t          j        | j        ¦  «        d¬¦  «        z  k    rt!          j        dt$          d¦  «         ||t          j        t          j        | j
        ¦  «        d¬¦  «        z  k    rt!          j        dt$          d¦  «         ||t          j        t          j        | j        ¦  «        d¬¦  «        z  k    rt!          j        d	t$          d¦  «         dS dS )
zM
        Check the interpolation conditions of all quadratic models.
        r…   NrN   g      $@rP   zJThe interpolation conditions for the objective function are not satisfied.r   zVThe interpolation conditions for the inequality constraint function are not satisfied.zTThe interpolation conditions for the equality constraint function are not satisfied.)r#   r<   r   rT   r˜   rÍ   rZ   rB   r®   rç   r¯   r
  r°   ÚsqrtrW   r    ÚwarningsÚwarnÚRuntimeWarning)r%   Ú	error_funÚ	error_cubÚ	error_ceqr-   Útols         r1   rº   z&Models._check_interpolation_conditionsÈ  s[  € ð ˆ	Øˆ	Øˆ	Ý�t”x‘”ð 	ñ 	ˆAÝœàÝ”FØŸš Ô!3×!9Ò!9¸!Ñ!<Ô!<Ñ=Ô=ÀÄÈQÄÑOñô ðñô ˆIõ œÝ”Ø—H’H˜TÔ/×5Ò5°aÑ8Ô8Ñ9Ô9¸D¼LÈÈAÈAÈAÈÔ<NÑNñô ð "ð	ñ ô ˆIõ œÝ”Ø—H’H˜TÔ/×5Ò5°aÑ8Ô8Ñ9Ô9¸D¼LÈÈAÈAÈAÈÔ<NÑNñô ð "ð	ñ ô ˆI‰Ið •R”W�S‘\”\Ñ!¥C¨¬°´Ñ$9Ô$9Ñ9ˆØ�s�RœV¥B¤F¨4¬<Ñ$8Ô$8À#ÐFÑFÔFÑFÒFÐFÝŒMð!åØñ	ô ð ð �s�RœV¥B¤F¨4¬<Ñ$8Ô$8À#ÐFÑFÔFÑFÒFÐFÝŒMð.åØñ	ô ð ð �s�RœV¥B¤F¨4¬<Ñ$8Ô$8À#ÐFÑFÔFÑFÒFÐFÝŒMð.åØñ	ô ð ð ð ð GÐFr3   )N)%rC   rD   rE   rF   r2   rG   r    r<   r¶   r¸   rZ   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º   rI   r3   r1   r¤   r¤   n  s®  € € € € € ðð ða3ð a3ð a3ðF ð	$ð 	$ñ „Xð	$ð ð	&ð 	&ñ „Xð	&ð ð	%ð 	%ñ „Xð	%ð ð	%ð 	%ñ „Xð	%ð ð	#ð 	#ñ „Xð	#ð ð	ð 	ñ „Xð	ð ðð ñ „Xðð ðð ñ „Xðð0ð 0ð 0ð(5ð 5ð 5ð(
2ð 
2ð 
2ð:ð :ð :ð*5ð 5ð 5ð*1ð 1ð 1ð6
ð 
ð 
ð 
ð8
ð 
ð 
ð 
ð<
ð 
ð 
ð 
ð2
ð 
ð 
ð 
ð@
ð 
ð 
ð 
ð:
ð 
ð 
ð 
ð6
ð 
ð 
ð 
ð<
ð 
ð 
ð 
ð2
ð 
ð 
ð 
ð@
ð 
ð 
ð 
ð:3ð 3ð 3ð6Qð Qð QðfH'ð H'ð H'ð H'ðT3ð 3ð 3ð<>ð >ð >ð >ð >ð >ð >ð >ð 1ð 1ð 1ð 1ð 1r3   r¤   )r3  Únumpyr   Úscipy.linalgr   Úsettingsr   Úutilsr   r   r   Úfinfor  ÚepsrW   r
   rR   r_   ra   r¤   rI   r3   r1   ú<module>r@     s9  ðØ €€€à Ð Ð Ð Ø Ð Ð Ð Ð Ð à Ð Ð Ð Ð Ð Ø ?Ð ?Ð ?Ð ?Ð ?Ð ?Ð ?Ð ?Ð ?Ð ?ð €b„hˆu�o„oÔ€ðr,ð r,ð r,ð r,ð r,ñ r,ô r,ð r,ðj ˜D°4ÀÐ	FÐ	F€ð.7ð .7ð .7ðbuFð uFð uFð uFð uFñ uFô uFð uFðpKð Kð Kð Kð Kñ Kô Kð Kð Kð Kr3   