
    bi(K                       d dl mZ d dlZd dlZd dlmZmZmZm	Z	 d dl
mZmZmZmZmZmZmZmZmZmZ d dlmZmZ d dlmZmZmZmZ d dlmZ d dlm Z  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/m0Z0 d dl1m2Z2 d dl3m4Z4 d dl5m6Z6 d dl7m8Z8 d dl9m:Z: d dl;m<Z< d dl=m>Z> d dl?m@Z@ d dlAmBZC d dlDmEZE d dlFmGZG d dlHmIZImJZJ d dlKmLZL dZMdZNdZOd  ZPd! ZQd&	 d'd"ZR	 	 	 	 	 	 d(	 	 	 	 	 	 	 	 	 	 	 	 	 d)d#ZS G d$ d%e       ZTy)*    )annotationsN)	EXP_ATOMSNONPOS_ATOMS	PSD_ATOMS	SOC_ATOMS)
PSDSOCEqualityExpCone	FiniteSet
InequalityNonNegNonPos	PowCone3DZero)OpRelEntrConeQuadRelEntrConeQuad)DCPErrorDGPErrorDPPErrorSolverError)Maximize)Chain)complex2real)APPROX_CONES
QuadApprox)EXOTIC_CONESExotic2Common)SOC2PSD)SOCDim3)CvxAttr2Constr)ConeMatrixStuffing)Dcp2Cone)Dgp2Dcp)Valinvec2mixedint)
EvalParams)FlipObjective)qp2symbolic_qp)QpMatrixStuffing)	Reduction)defines)ConstantSolver)Solver)CLARABELPARAM_THRESHOLD)build_non_disciplined_error_msga  You are solving a parameterized problem that is not DPP. Because the problem is not DPP, subsequent solves will not be faster than the first one. For more information, see the documentation on Disciplined Parametrized Programming, at https://www.cvxpy.org/tutorial/dpp/index.htmla  
    You specified your problem should be solved by ECOS. Starting in
    CXVPY 1.6.0, ECOS will no longer be installed by default with CVXPY.
    Please either add ECOS as an explicit install dependency to your project
    or switch to our new default solver, Clarabel, by either not specifying a
    solver argument or specifying ``solver=cp.CLARABEL``. To suppress this
    warning while continuing to use ECOS, you can filter this warning using
    Python's ``warnings`` module until you are using 1.6.0.
    a#  
    Your problem is being solved with the ECOS solver by default. Starting in
    CVXPY 1.5.0, Clarabel will be used as the default solver instead. To continue
    using ECOS, specify the ECOS solver explicitly using the ``solver=cp.ECOS``
    argument to the ``problem.solve`` method.
    c                p   | j                   D ]8  }t        |t        t        f      r|j                  d   j                         r8 y | j                         D ]$  }|j                         s|j                         s$ y | j                         xr' | j                  j                  d   j                         S )z!Is problem a linear program?
    r   F)constraints
isinstancer
   r   argsis_pwl	variablesis_psdis_nsdis_dcp	objective)selfcvars      a/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/cvxpy/reductions/solvers/solving_chain.py_is_lpr?   S   s      1x./166!93C3C3E ~~ ::<3::< KKM=dnn11!4;;=>    c                    t        |       r|d   D cg c]  }||d   vs| c}ry|d   xr t        j                  |       S c c}w )Nconic_solvers
qp_solversF)r?   r(   accepts)problem
candidatesss      r>   _solve_as_qprH   _   sN    g"?3Y1q
<@X7XQY l#G(>(>w(GG Zs
   AAc                @   g }t        j                  |       r|t        j                         gz  }|r|t               gz  }|sU| j	                         sEt        | d      }| j                         r|dz  }n| j                         r|dz  }t        d|z         |rU| j                         sEt        | d      }| j	                         r|dz  }n| j                         r|dz  }t        d|z         t        | j                        t        k(  r|t               gz  }| j                  D ch c]  }t        |       }}t        |v r|t!               gz  }|dn|j#                  d	d      }t%        | |      xr |}	t'        |d
         dkD  }
|	s|
st)        d|z        |S c c}w )a  
    Builds a chain that rewrites a problem into an intermediate
    representation suitable for numeric reductions.

    Parameters
    ----------
    problem : Problem
        The problem for which to build a chain.
    candidates : dict
        Dictionary of candidate solvers divided in qp_solvers
        and conic_solvers.
    gp : bool
        If True, the problem is parsed as a Disciplined Geometric Program
        instead of as a Disciplined Convex Program.
    Returns
    -------
    list of Reduction objects
        A list of reductions that can be used to convert the problem to an
        intermediate form.
    Raises
    ------
    DCPError
        Raised if the problem is not DCP and `gp` is False.
    DGPError
        Raised if the problem is not DGP and `gp` is True.
    DCPzU
However, the problem does follow DGP rules. Consider calling solve() with `gp=True`.zW
However, the problem does follow DQCP rules. Consider calling solve() with `qcp=True`.z1Problem does not follow DCP rules. Specifically:
DGPzV
However, the problem does follow DCP rules. Consider calling solve() with `gp=False`.z"Problem does not follow DGP rules.Tuse_quad_objrB   r   ^Problem could not be reduced to a QP, and no conic solvers exist among candidate solvers (%s).)r   rD   Complex2Realr$   r9   r0   is_dgpis_dqcpr   r   typer:   r   r'   r2   r   r%   getrH   lenr   )rE   rF   gpsolver_opts
reductionsappendr<   constr_typesuse_quadvalid_qpvalid_conics              r>   _reductions_for_problem_classr\   i   s   8 JG$|00233
	wyk!
gnn&0%@>> B CF__ C DF@6IK 	K	GNN$0%@>> C DF__ C DF;fDEE G(*}''
 &-%8%89DG9L9L (*++
"*tPT0UHGZ0=XHj12Q6KK $&01 2 	2  :s   &Fc                    t        | j                               dk(  rt        t               g      S t	        | |||      }|sdnd}	|s| j                  |	      sJ|rt               g|z   }n|s(t        j                  t               t               g|z   }n|t        t              t        d | j                         D              rt               g|z   }n>t        d | j                         D              }
|
t        k\  rt        j                  d       |dn|j                  d	d      }t!        | |      rc|ra|d
   d   }t"        j$                  |   }|t'        |j(                         t+        j,                         t/        |      |gz  }t        |      S |d   st1        d|z        t3               | j4                  D ]  }j7                  t9        |              D cg c]  }|t:        v s| }}D cg c]  }|t<        v s| }}|D ]-  }t:        |   }j?                  |       jA                  |       / |D ]-  }t<        |   }j?                  |       jA                  |       / g }| jC                         }tD        v st        d |D              r|jG                  tD               tH        v st        d |D              r|jG                  tH               t        fdtJ        tL        tN        fD              st        d |D              r|jG                  tN               tP        v stR        v r|jG                  tR               tT        v s2t        d |D              s t        d | j                         D              r|jG                  tT               tV        v r|jG                  tV               t        | j                         D cg c]  }|jX                   c}g       }t        |      dkD  xs( t        | j4                        dkD  xs t        |      dkD  }tT        |v r2t"        jZ                  r"| |d   D cg c]  }|t\        k7  s| c}|d<   |d   D ]  }t"        j^                  |   }| ja                         r|jb                   n|jd                   |D cg c]	  }| vs| }}|s|jf                  rc|r|jG                  ti                      tj        |v stl        |v r|jG                  to                      |d}n|j                  d	d      }|xr6 |jq                         xr$ | jr                  jt                  jw                         }|ty        |      t'        |j(                         gz  }t{         fd|D              rM|j|                  r!tD        |v r|jG                  t                      |t        ||      |gz  }t        |      c S t{        d |D              stT         v s|t               t        ||      |gz  }t        |      c S  t1        d|d   ddj                  |D cg c]  }|j                   c}      d      c c}w c c}w c c}w c c}w c c}w c c}w )a  Build a reduction chain from a problem to an installed solver.

    Note that if the supplied problem has 0 variables, then the solver
    parameter will be ignored.

    Parameters
    ----------
    problem : Problem
        The problem for which to build a chain.
    candidates : dict
        Dictionary of candidate solvers divided in qp_solvers
        and conic_solvers.
    gp : bool
        If True, the problem is parsed as a Disciplined Geometric Program
        instead of as a Disciplined Convex Program.
    enforce_dpp : bool, optional
        When True, a DPPError will be thrown when trying to parse a non-DPP
        problem (instead of just a warning). Defaults to False.
    ignore_dpp : bool, optional
        When True, DPP problems will be treated as non-DPP,
        which may speed up compilation. Defaults to False.
    canon_backend : str, optional
        'CPP' (default) | 'SCIPY'
        Specifies which backend to use for canonicalization, which can affect
        compilation time. Defaults to None, i.e., selecting the default
        backend.
    solver_opts : dict, optional
        Additional arguments to pass to the solver.
    specified_solver: str, optional
        A solver specified by the user.

    Returns
    -------
    SolvingChain
        A SolvingChain that can be used to solve the problem.

    Raises
    ------
    SolverError
        Raised if no suitable solver exists among the installed solvers, or
        if the target solver is not installed.
    r   rV   dcpdgpc              3  <   K   | ]  }|j                           y wN)
is_complex.0params     r>   	<genexpr>z*construct_solving_chain.<locals>.<genexpr>   s     BEUBs   c              3  Z   K   | ]#  }t        j                  |j                         % y wrb   )npprodshaperd   s     r>   rg   z*construct_solving_chain.<locals>.<genexpr>   s     RE2775;;/Rs   )+zkYour problem has too many parameters for efficient DPP compilation. We suggest setting 'ignore_dpp = True'.TrL   rC   )reduce_bounds)canon_backendrB   rM   c              3  ,   K   | ]  }|t         v   y wrb   )r   re   atoms     r>   rg   z*construct_solving_chain.<locals>.<genexpr>/  s     !F$)"3!F   c              3  ,   K   | ]  }|t         v   y wrb   )r   ro   s     r>   rg   z*construct_solving_chain.<locals>.<genexpr>1  s     %JDdi&7%Jrq   c              3  &   K   | ]  }|v  
 y wrb    )re   trX   s     r>   rg   z*construct_solving_chain.<locals>.<genexpr>3  s     
C1
C   c              3  ,   K   | ]  }|t         v   y wrb   )r   ro   s     r>   rg   z*construct_solving_chain.<locals>.<genexpr>4  s     :D4<':rq   c              3  ,   K   | ]  }|t         v   y wrb   )r   ro   s     r>   rg   z*construct_solving_chain.<locals>.<genexpr>9  s     749$7rq   c              3  `   K   | ]&  }|j                         xs |j                          ( y wrb   )r7   r8   )re   vs     r>   rg   z*construct_solving_chain.<locals>.<genexpr>:  s$     I188:++Is   ,.)start)quad_objc              3  &   K   | ]  }|v  
 y wrb   rt   )re   r<   supported_constraintss     r>   rg   z*construct_solving_chain.<locals>.<genexpr>h  s     =!1--=rv   )r|   rm   c              3  .   K   | ]  }|t         k(    y wrb   )r	   )re   r<   s     r>   rg   z*construct_solving_chain.<locals>.<genexpr>s  s     =QV=s   z Either candidate conic solvers (z2) do not support the cones output by the problem (z, z6), or there are not enough constraints in the problem.)DrS   r6   SolvingChainr,   r\   is_dppr&   warningswarnDPP_ERROR_MSGr   any
parameterssumr/   rR   rH   slv_defSOLVER_MAP_QPr!   BOUNDED_VARIABLESr(   Qp2SymbolicQpr)   r   setr2   addrQ   r   r   updateremoveatomsr	   rW   r   r   r   r   r
   r   r   r   domain5DISREGARD_CLARABEL_SDP_SUPPORT_FOR_DEFAULT_RESOLUTIONr.   SOLVER_MAP_CONICis_mixed_integerMI_SUPPORTED_CONSTRAINTSSUPPORTED_CONSTRAINTSREQUIRES_CONSTRr   r   r   r   supports_quad_objr:   exprhas_quadratic_termr#   allSOC_DIM3_ONLYr    r"   r   join__name__)!rE   rF   rT   enforce_dpp
ignore_dpprm   rU   specified_solverrV   dpp_contextn_parametersrY   solversolver_instancer<   ctex_cos
approx_coscosim_cosapp_cosconesr   r=   var_domains
has_constrrG   coneunsupported_constraintsrL   r|   rX   r~   s!                                  @@r>   construct_solving_chainr      s   d 71$(8'9::.w
BTJ  "%uK4$,*4JMM-($,*4J=))	BW-?-?-AB	B l^j0
RW=O=O=QRR?*MMG #*tPT0UHGZ(XL)!,!//7_-N-N)NO((*=9	
 	

 z22 o& "$./ 0 	0 5L    "a!"'>R2+=b>F>+Br\/A"BJB   r"G$B 
   r"G$B  EMMOE
lc!F!FFS,#%JE%J"JW

Cz66&B
CC:E::V<4<#7T
l777IW5F5F5HIISL  	Y W->->-@AcszzA2NKUaW3w':':#;a#?W3{CSVWCWJ
e|MM (2<_2M&_QQRV^Q^q&_
?#_- -;!226:##%$3$L$L!$3$I$I!"#
d2G&GD#
 #
 _<<!!-/2*,0AZ0O!!*,/ "#*~tD# <(I(I(K <!!&&99; (+1R1R-RS J =u=="00SE\%%gi0&V# 
 $z::=%<==#I^B^I&V# 

 $z::[-;^  %_5))u$EtT]]$EF	H I I ?BN B '`#
X %Fs<   #Y+1Y+;Y0	Y0Y5
Y:Y:,	Y?6Y?
Zc                  F     e Zd ZdZdd fdZd	dZd
dZddi fd
dZ xZS )r   ak  A reduction chain that ends with a solver.

    Parameters
    ----------
    reductions : list[Reduction]
        A list of reductions. The last reduction in the list must be a solver
        instance.

    Attributes
    ----------
    reductions : list[Reduction]
        A list of reductions.
    solver : Solver
        The solver, i.e., reductions[-1].
    c                    t         t        |   ||       t        | j                  d   t
              st        d      | j                  d   | _        y )N)rE   rV   z,Solving chains must terminate with a Solver.)superr   __init__r3   rV   r-   
ValueErrorr   )r;   rE   rV   	__class__s      r>   r   zSolvingChain.__init__  sL    lD*76@ 	+ 	B$//"-v6KLLoob)r@   c                H    t        |j                  | j                  z         S )zi
        Create and return a new SolvingChain by concatenating
        chain with this instance.
        r^   )r   rV   )r;   chains     r>   prependzSolvingChain.prepend  s    
 u'7'7$//'IJJr@   c                    | j                  |      \  }}| j                  j                  ||||      }| j                  ||      S )ai  Solves the problem by applying the chain.

        Applies each reduction in the chain to the problem, solves it,
        and then inverts the chain to return a solution of the supplied
        problem.

        Parameters
        ----------
        problem : Problem
            The problem to solve.
        warm_start : bool
            Whether to warm start the solver.
        verbose : bool
            Whether to enable solver verbosity.
        solver_opts : dict
            Solver specific options.

        Returns
        -------
        solution : Solution
            A solution to the problem.
        )applyr   solve_via_datainvert)r;   rE   
warm_startverboserU   datainverse_datasolutions           r>   solvezSolvingChain.solve  sF    . "ZZ0l;;--dJ.5{D{{8\22r@   Fc                T    | j                   j                  |||||j                        S )a  Solves the problem using the data output by the an apply invocation.

        The semantics are:

        .. code :: python

            data, inverse_data = solving_chain.apply(problem)
            solution = solving_chain.invert(solver_chain.solve_via_data(data, ...))

        which is equivalent to writing

        .. code :: python

            solution = solving_chain.solve(problem, ...)

        Parameters
        ----------
        problem : Problem
            The problem to solve.
        data : map
            Data for the solver.
        warm_start : bool
            Whether to warm start the solver.
        verbose : bool
            Whether to enable solver verbosity.
        solver_opts : dict
            Solver specific options.

        Returns
        -------
        raw solver solution
            The information returned by the solver; this is not necessarily
            a Solution object.
        )r   r   _solver_cache)r;   rE   r   r   r   rU   s         r>   r   zSolvingChain.solve_via_data  s/    H {{))$
G*5w7L7LN 	Nr@   )NN)returnNone)r   'SolvingChain')r   boolr   r   )	r   
__module____qualname____doc__r   r   r   r   __classcell__)r   s   @r>   r   r     s1     *K38 @EV[#%%N %Nr@   r   )FN)rT   r   r   zlist[Reduction])FFFNNN)rT   r   r   r   r   r   rm   
str | NonerU   zdict | Noner   r   r   r   )U
__future__r   r   numpyri   cvxpy.atomsr   r   r   r   cvxpy.constraintsr   r	   r
   r   r   r   r   r   r   r   cvxpy.constraints.exponentialr   r   cvxpy.errorr   r   r   r   cvxpy.problems.objectiver   cvxpy.reductions.chainr   cvxpy.reductions.complex2realr   )cvxpy.reductions.cone2cone.approximationsr   r   (cvxpy.reductions.cone2cone.exotic2commonr   r   "cvxpy.reductions.cone2cone.soc2psdr   #cvxpy.reductions.cone2cone.soc_dim3r     cvxpy.reductions.cvx_attr2constrr!   .cvxpy.reductions.dcp2cone.cone_matrix_stuffingr"   "cvxpy.reductions.dcp2cone.dcp2coner#    cvxpy.reductions.dgp2dcp.dgp2dcpr$   4cvxpy.reductions.discrete2mixedint.valinvec2mixedintr%   cvxpy.reductions.eval_paramsr&   cvxpy.reductions.flip_objectiver'   cvxpy.reductions.qp2quad_formr(   0cvxpy.reductions.qp2quad_form.qp_matrix_stuffingr)   cvxpy.reductions.reductionr*   cvxpy.reductions.solversr+   r   (cvxpy.reductions.solvers.constant_solverr,   cvxpy.reductions.solvers.solverr-   cvxpy.settingsr.   r/   cvxpy.utilities.debug_toolsr0   r   ECOS_DEP_DEPRECATION_MSGECOS_DEPRECATION_MSGr?   rH   r\   r   r   rt   r@   r>   <module>r      s3   "   E E   M A A - ( 6 N 7 7 ; M 7 4 4 9 8 M 0 7 C 2 H4   	?HIIZ (-05/48<7;;?JI $JI)-JI )-JI ,6	JI
 *5JI /9JI "0JIZ`N5 `Nr@   