
    bi                     ^    d Z ddlZddlZddlmZ ddlmZ ej                  Z	 G d de      Z
y)a  
Tests for DGP (Disciplined Geometric Programming) with DPP (Disciplined Parametrized Programming).

This verifies the fix for issue #3004: DGP problems can now have get_problem_data(gp=True)
called without all parameters having values. This is useful when the problem is DPP.
    N)ParameterError)BaseTestc                   0    e Zd ZdZddZddZddZddZy)
TestDgpDppzPTests for DGP + DPP integration focusing on get_problem_data core functionality.Nc                 j   t        j                  d      }t        j                  d      }t        j                  t        j                  |      ||k\  g      }|j                  t        d      \  }}}|J d|_        |j                  t        dd       | j                  |j                  d       y)zget_problem_data(gp=True) works with uninitialized parameters.

        This was the original failure case in issue #3004. Previously, DGP
        canonicalization eagerly evaluated np.log(param.value), failing when
        param.value was None.
        TposgpN       @r   enforce_dpp)
cp	ParameterVariableProblemMinimizeget_problem_dataSOLVERvaluesolveassertAlmostEqual)selfalphaxproblemdata_s         S/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/cvxpy/tests/test_dgp_dpp.py*test_get_problem_data_without_param_valuesz5TestDgpDpp.test_get_problem_data_without_param_values   s     &KKD!**R[[^a5j\: --f->
a f48qww,    c                 $   t        j                  d      }t        j                  d      }t        j                  t        j                  |      ||k\  g      }d|_        |j                  t        dd       | j                  |j
                  dd       d|_        |j                  t        dd       | j                  |j
                  dd       d|_        |j                  t        dd       | j                  |j
                  dd       y	)
zDGP DPP fast path correctly updates parameters across solves.

        Tests that log-transformed parameter values are properly updated
        in the cached param_prog on each solve.
        Tr         ?r      placesr   g      ?N)	r   r   r   r   r   r   r   r   r   r   r   r   r   s       r   #test_fast_path_with_changing_paramsz.TestDgpDpp.test_fast_path_with_changing_params'   s     &KKD!**R[[^a5j\: f48qwwA6 f48qwwA6 f48qwwA6r!   c                 t   t        j                  d      }t        j                  d      }t        j                  t        j                  |      ||k\  g      }|j                  t        d       t        j                  t        d      5  |j                  t        dd       ddd       y# 1 sw Y   yxY w)zKAttempting to solve without setting parameter values raises ParameterError.Tr   r
   z must have.*value.*before solving)matchr   N)r   r   r   r   r   r   r   pytestraisesr   r   r'   s       r   +test_solve_without_param_value_raises_errorz6TestDgpDpp.test_solve_without_param_value_raises_error@   s    &KKD!**R[[^a5j\: 	  D 1 ]]>1ST 	=MM&TtM<	= 	= 	=s   B..B7c                    t        j                  dd      }t        j                  d      }t        j                  t        j                  |      ||k\  g      }|j                  d      sJ |j                  t        dd       | j                  |j                  dd       d	|_	        |j                  t        dd       | j                  |j                  d	d       y
)a$  DGP problems work correctly with ignore_dpp=True (non-DPP mode).

        This tests backward compatibility: even though the DGP canonicalization
        now supports DPP, forcing non-DPP treatment with ignore_dpp=True should
        still work correctly when parameters have values.
        Tr#   )r	   r   r   dgp)r   
ignore_dppr$   r%   g      @N)
r   r   r   r   r   is_dppr   r   r   r   r'   s       r   &test_non_dpp_mode_with_ignore_dpp_flagz1TestDgpDpp.test_non_dpp_mode_with_ignore_dpp_flagM   s     S1KKD!**R[[^a5j\: ~~e$$$f$7qwwA6 f$7qwwA6r!   )returnN)__name__
__module____qualname____doc__r    r(   r-   r2    r!   r   r   r      s    Z-(72=7r!   r   )r7   r+   cvxpyr   cvxpy.errorr   cvxpy.tests.base_testr   CLARABELr   r   r8   r!   r   <module>r=      s/      & *	P7 P7r!   