Code Monkey home page Code Monkey logo

dccp's People

Contributors

bmsherman avatar jaehyunp avatar miggy2129 avatar mingen-pan avatar musically-ut avatar stevediamond avatar user799595 avatar xinyueshen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dccp's Issues

Possible bug or limitation

problem_dccp.txt

Hi, I tried to solve the model below and DCCP fails. If I understand the output correctly it seems like it solves a primal version and finds a optimal value close to zero (and this is not possible, the optimal value is 1), after that it tries to solve the KKT conditions to retrieve the multipliers and conclude that the related problem is and Unbounded and hence it fails and return None.

I don't see why the solver fails. Actually the problem is relatively simple. Since p == 0, the constraint on d involving p says that d == 0 too. Hence, the weird weird objective term
0.5*cvx.quad_form(b, M) + minus_norm2, which is actually a way to write -<c, d>, is 0 (as d == 0). The objective reverts to 0.5 || v ||^2 + sum(c), and the problem is actually convex even though it is written with a DC constraint.

The problem is more interesting if p == 1, in this case it is not convex on the feasible set, and hence the problem makes more sense as a DC problem. DCCP does not solve the problem in this case either. I hope that if I can solve the problem with the DCCP when p == 0, it will also be able to solve the problem with p == 1.

Obs: The txt is actually the Python code for the example. I had to add it as .txt because the system does not accept .py.

Example code on front page won't run

Hi,

A very minor niggle: the example code contains myprob.is_dccp() instead of the newer is_dccp(myprob).

Otherwise, thanks for a life-saving package!

pip install dccp not installing solver

I'm having trouble getting dccp solver to run, it's not showing up in cvxpy.installed_solvers(). Anything I'm doing wrong?

(venv)stn821@stn821-hp-linux:/mnt/data/dev/testvirt⟫ python
Python 2.7.10 (default, Oct 14 2015, 16:09:02)
[GCC 5.2.1 20151010] on linux2
Type "help", "copyright", "credits" or "license" for more information.

import cvxpy
cvxpy.installed_solvers()
['ECOS_BB', 'SCS', 'ECOS', 'LS']
quit()
(venv)stn821@stn821-hp-linux:/mnt/data/dev/testvirt⟫ pip freeze
CVXcanon==0.1.1
cvxpy==0.4.5
dccp==0.1.5
dill==0.2.5
ecos==2.0.4
fastcache==1.0.2
multiprocess==0.70.4
numpy==1.11.1
scipy==0.18.0
scs==1.2.6
six==1.10.0
toolz==0.8.0
wsgiref==0.1.2

DCCP: _grad() takes exactly 1 argument (2 given)

Hello,

I have the following DCCP Problem but it returns me an error on the gradient size?

import numpy as np
import cvxpy as cvx
import dccp

np.random.seed(1)
n = 10
rands = np.abs(np.random.randn(n, 1))
Sigma = np.random.randn(n, n)
Sigma = Sigma.T.dot(Sigma)
w = Variable(n)
mu = rands.T*w 
var = quad_form(w, Sigma)

prob = Problem(Maximize(mu),  [var <=  0.01,
                                var >= 0.04,
                                sum(w) == 1,
                                w >=0])
    
print("problem is DCP:", prob.is_dcp())
print("problem is DCCP:", is_dccp(prob))

prob.solve(method = 'dccp')

Below the error message I get

('problem is DCP:', False)
('problem is DCCP:', True)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-71-ce9a78886e65> in <module>()
     19 print("problem is DCCP:", is_dccp(prob))
     20 
---> 21 prob.solve(method = 'dccp')

C:\HOMEWARE\Anaconda2-Windows-x86_64\lib\site-packages\cvxpy\problems\problem.pyc in solve(self, *args, **kwargs)
    245         else:
    246             solve_func = Problem._solve
--> 247         return solve_func(self, *args, **kwargs)
    248 
    249     @classmethod

C:\HOMEWARE\Anaconda2-Windows-x86_64\lib\site-packages\dccp\problem.pyc in dccp(self, max_iter, tau, mu, tau_max, solver, ccp_times, max_slack, **kwargs)
     41         dccp_ini(self, random=(ccp_times>1), solver = solver, **kwargs) # initialization; random initial value is mandatory if ccp_times>1
     42         # iterations
---> 43         result_temp = iter_dccp(self, max_iter, tau, mu, tau_max, solver, **kwargs)
     44         if result_temp[0] is not None:
     45             if (self.objective.NAME == 'minimize' and result_temp[0]<cost_value) \

C:\HOMEWARE\Anaconda2-Windows-x86_64\lib\site-packages\dccp\problem.pyc in iter_dccp(self, max_iter, tau, mu, tau_max, solver, **kwargs)
    353         count_slack = 0
    354         for arg in self.constraints:
--> 355             temp = convexify_constr(arg)
    356             if not arg.is_dcp():
    357                 while temp is None:

C:\HOMEWARE\Anaconda2-Windows-x86_64\lib\site-packages\dccp\constraint.pyc in convexify_constr(constr)
     67         #right hand concave since the right-hand expression captures the minus sign
     68         if constr.expr.args[1].curvature == 'CONCAVE':
---> 69             neg_right = linearize(constr.expr.args[1])
     70             if neg_right is None:
     71                 return None

C:\HOMEWARE\Anaconda2-Windows-x86_64\lib\site-packages\dccp\linearize.pyc in linearize(expr)
     54         "Cannot linearize non-affine expression with missing variable values."
     55             )
---> 56         grad_map = expr.grad
     57         for var in expr.variables():
     58             if var.ndim > 1:

C:\HOMEWARE\Anaconda2-Windows-x86_64\lib\site-packages\cvxpy\atoms\atom.pyc in grad(self)
    266             # A dictionary of gradients w.r.t. variables
    267             # Partial argument / Partial x.
--> 268             grad_arg = arg.grad
    269             for key in grad_arg:
    270                 # None indicates gradient is not defined.

C:\HOMEWARE\Anaconda2-Windows-x86_64\lib\site-packages\cvxpy\atoms\atom.pyc in grad(self)
    260 
    261         # A list of gradients w.r.t. arguments
--> 262         grad_self = self._grad(arg_values)
    263         # The Chain rule.
    264         result = {}

TypeError: _grad() takes exactly 1 argument (2 given)

Fixed addition of slack variables to new objective in problem.py

I fixed a bug that was causing the Minimize not to resolve to a scalar. Had to add the sum_entries function for it to work on a non-scalar variable. Around line 355 in dccp/problem.py

# objective
    if self.objective.NAME == 'minimize':
        for var in var_slack:
            #BUG FIX added sum_entries
            #cost_new += np.ones((var._cols,var._rows)*var*tau)
            cost_new += tau*sum_entries(var)
        obj_new = Minimize(cost_new)
    else:
        for var in var_slack:
            #BUG FIX here too
            cost_new -= taur*sum_entries(var)
        obj_new = Maximize(cost_new)

CCP constraints raise an error

Hello,

Here is the simplest (dummy) problem representing the issue I have:

import cvxpy as cp
import dccp
z = cp.Variable(1)
obj = cp.Minimize(z)
con = [cp.power(z,2) >= 0., z<=1., z>=0.]
prob = cp.Problem(obj, con)
assert dccp.is_dccp(prob)
prob.solve(method='dccp', solver='ECOS')

The error I get is:

TypeError: cannot unpack non-iterable NotImplementedType object

Do you know where this could be from?
Thank you!

dccp method seems to change requirements on Parameter shape

I'm trying to use the dccp extension to minimize a simple quadratic (uncertain about convexity/concavity.

The quadratic can be given by:
f(theta, [1, x, u, xu, x^2, u^2]) = theta*[1, x, u, x*u, x^2, u^2]
(Note that x is functionally constant)

The following code works without the dccp method when f is convex but not when theta is updated such that f is concave. When adding the method parameter the code throws an error that a Parameter value has the wrong dimensions.

    def _get_greedyaction(self, state_k):
        u_k = cp.Variable()
        xhat_k = cp.Constant(state_k)
        th = cp.Constant(self.theta)
        cons = [u_k >= self.actionspace[0],
                u_k <= self.actionspace[1]]

        obj = cp.Minimize(cp.sum(th[0] + th[1]*xhat_k + th[2]*u_k + th[3]*xhat_k*u_k + th[4]*xhat_k**2 + th[5]*u_k**2))

        prob = cp.Problem(obj, cons)
        prob.solve(solver="OSQP", method="dccp")
        return u_k.value
  File "main.py", line 5, in <module>
    a.run()
  File "/Users/aislingpigott/.dragg/dragg/dragg/aggregator.py", line 899, in run
    self.run_rl_agg(self.config["agg_learning_rate"], self.config["agg_exploration_rate"], horizon)
  File "/Users/aislingpigott/.dragg/dragg/dragg/aggregator.py", line 826, in run_rl_agg
    self.rl_update_reward_price()
  File "/Users/aislingpigott/.dragg/dragg/dragg/aggregator.py", line 578, in rl_update_reward_price
    u_k = self._get_greedyaction(self.state)
  File "/Users/aislingpigott/.dragg/dragg/dragg/aggregator.py", line 550, in _get_greedyaction
    prob.solve(method="dccp")
  File "/opt/anaconda3/envs/dragg/lib/python3.6/site-packages/cvxpy/problems/problem.py", line 290, in solve
    return solve_func(self, *args, **kwargs)
  File "/opt/anaconda3/envs/dragg/lib/python3.6/site-packages/dccp/problem.py", line 40, in dccp
    dccp_ini(self, random=(ccp_times>1), solver = solver, **kwargs) # initialization; random initial value is mandatory if ccp_times>1
  File "/opt/anaconda3/envs/dragg/lib/python3.6/site-packages/dccp/problem.py", line 112, in dccp_ini
    value_para[count_para].value = np.random.randn(var.size)*10
  File "/opt/anaconda3/envs/dragg/lib/python3.6/site-packages/cvxpy/expressions/constants/parameter.py", line 63, in value
    self._value = self._validate_value(val)
  File "/opt/anaconda3/envs/dragg/lib/python3.6/site-packages/cvxpy/expressions/leaf.py", line 379, in _validate_value
    (intf.shape(val), self.__class__.__name__)
ValueError: Invalid dimensions (1,) for Parameter value.

better logging and error handling

This is a low-priority enhancement suggestion for the package. Currently it prints out the debug output directly to the console (various parameters, slack), and ideally, they should be logged using the logging package or some other similar ways. Error handling can be done better as well; for example, when the input problem is not DCCP, an appropriate exception should be thrown. I made a similar update just now, if you need references: https://github.com/cvxgrp/qcqp/blob/master/qcqp/qcqp_problem.py

linearize in linearize.py doesn't work with variables of size (1,N)

I patched this for now but it probably needs a better solution.

if var.is_matrix() or True:
# forcing this route for now
flattened = np.transpose(grad_map[var])vec(var - var.value)
tangent = tangent + reshape(flattened, *expr.size)
else:
# THIS appears to be broken for variables like (1,N)
# using the matrix version above works
# TODO: fix this correctly
tangent = tangent + np.transpose(grad_map[var])
(var - var.value)

DCCP problem

My dccp programming returns the following error, what's the reason? Thanks!

return _ecos.csolve((m,n1,p), c, data, indices, colptr, h, dims, **kwargs)
TypeError: argument 12 must be bool, not str

DCCP for non-convex (non-solid) region of L_infinite-norm

Hi,
Thank you very much for an excellent tool.

I tried to a solve simple non-convex (non-solid) constrained optimization by DCCP.
The problem is successfully solved if I use L1 or L2 norm but it fails with SolverError if I use L-inf norm.
(I tried ECOS, CVXOPT, but both solvers failed.)
I expected that it could be solved but do you have any ideas of why it fails?

import cvxpy as cvx
import dccp
import numpy as np
x = cvx.Variable(2)
obj = cvx.Minimize(x[0] + x[1])

# constr = [cvx.norm(x, 2) <= 2, cvx.norm(x, 2) >= 1] # SUCCESS
# constr = [cvx.norm(x, 1) <= 2, cvx.norm(x, 1) >= 1] # SUCCESS
constr = [cvx.norm(x, 'inf') <= 2, cvx.norm(x, 'inf') >= 1]  # FAIL

prob = cvx.Problem(obj, constr)
print("problem is DCP:", prob.is_dcp())
print("problem is DCCP:", dccp.is_dccp(prob))
result = prob.solve(method = 'dccp')
print("x", x.value)
print("cost value =", prob.value)

Problem DCCP status and some numerical(?) errors

Hello. I try an optimization problem with constraints of the form f1 - f2 == 0 (where both f1 and f2 are convex), and I get an error saying :

not a dccp problem

I reformulate the constraint to f1 == f2 and I get a solution.

The above solution works well for some cases. However, in some other cases, the constraint f1 == f2 does not give me the expected solution (the returned solution does not satisfy the specified constraint). However, reforming the same constraint as 1^6 * f1 == 10^6 * f2, that is, just multiplying both sides with big numbers gives a solution which is perfectly fine. Maybe its due to some error in floating point operations?

Thanks in advance for the help!

Problems in circle packing example

Hello, when running circle packing algorithm I get the following error:

I have tried it with both python27 and pytho36

Traceback (most recent call last):
File "C:\anaconda3\envs\python27\lib\site-packages\IPython\core\interactiveshell.py", line 2878, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "", line 1, in
runfile('C:/proyecto/rocks/dccp/examples/circle_packing.py', wdir='C:/proyecto/rocks/dccp/examples')
File "C:\Users\R107333\AppData\Roaming\JetBrains\PyCharm Community Edition 2018.2.4\helpers\pydev_pydev_bundle\pydev_umd.py", line 197, in runfile
pydev_imports.execfile(filename, global_vars, local_vars) # execute the script
File "C:/proyecto/rocks/dccp/examples/circle_packing.py", line 17, in
prob.solve(method = 'dccp', ccp_times = 1)
File "C:\anaconda3\envs\python27\lib\site-packages\cvxpy\problems\problem.py", line 193, in solve
return func(self, *args, **kwargs)
File "C:\proyecto\rocks\dccp\dccp\problem.py", line 31, in dccp
if not is_dccp(self):
File "C:\proyecto\rocks\dccp\dccp\problem.py", line 116, in is_dccp
for arg in constr.expr.args:
AttributeError: 'LeqConstraint' object has no attribute 'expr'

List index out of range when solving a problem

I have the following problem (ps, ns are in R^2, rhos are in R>0):

import cvxpy as cvx
import dccp

_ps = np.array(ps)
_ns = np.array(ns)
_rhos = np.array(rhos)

p_h = np.array([1.5, 0.4])
p_h = p_h.reshape((-1, 1))

p = cvx.Variable(p_h.shape)
error = cvx.sum_squares(p - p_h)

delta = cvx.hstack([p for _ in _ps]).T - _ps
axs = cvx.sum(cvx.multiply(_ns, delta), axis=1, keepdims=True)
bxs = cvx.sum(cvx.square(delta), axis=1, keepdims=True)
txs = cvx.multiply(_rhos, bxs)
cxs = axs - txs

prob1 = cvx.Problem(cvx.Minimize(error),
                    [txs >= axs])
print(dccp.is_dccp(prob1))
solution = prob1.solve(method='dccp')
print(solution)

Example values:

ps = array([[1., 0.],
       [0., 0.],
       [2., 0.]], dtype=float32)

ns = array([[-1.,  0.],
       [ 1.,  0.],
       [-1.,  0.]], dtype=float32)

rhos = array([[1.],
       [1.],
       [1.]], dtype=float32)

When running it with dccp (cvxpy-1.0.8 dccp-0.1.6):

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-17-6f4e5a73ace7> in <module>()
      3                     [txs >= axs])
      4 print(dccp.is_dccp(prob1))
----> 5 solution = prob1.solve(method='dccp')
      6 print(solution)

/usr/local/lib/python3.6/dist-packages/cvxpy/problems/problem.py in solve(self, *args, **kwargs)
    245         else:
    246             solve_func = Problem._solve
--> 247         return solve_func(self, *args, **kwargs)
    248 
    249     @classmethod

/usr/local/lib/python3.6/dist-packages/dccp/problem.py in dccp(self, max_iter, tau, mu, tau_max, solver, ccp_times, **kwargs)
     34         cost_value = -float("inf")
     35     for t in range(ccp_times): # for each time of running ccp
---> 36         dccp_ini(self, random=(ccp_times>1), **kwargs) # initialization; random initial value is mandatory if ccp_times>1
     37         # iterations
     38         result_temp = iter_dccp(self, max_iter, tau, mu, tau_max, solver, **kwargs)

/usr/local/lib/python3.6/dist-packages/dccp/problem.py in dccp_ini(self, times, random, **kwargs)
     55     for arg in self.constraints:
     56         for l in range(2):
---> 57             for dom in arg.args[l].domain:
     58                 dom_constr.append(dom) # domain on each side of constraints
     59     var_store = [] # store initial values for each variable

IndexError: list index out of range

unable to select SCS solver

When I run this call:

problem.solve(method='dccp', solver=SCS, max_iters=700, use_indirect=False, warm_start=True)

I get this exception, which implies that my request to use SCS was ignored:

  File "/usr/local/lib/python3.5/dist-packages/cvxpy/problems/problem.py", line 207, in solve
    return func(self, *args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/dccp/problem.py", line 36, in dccp
    dccp_ini(self, random=(ccp_times>1), **kwargs) # initialization; random initial value is mandatory if ccp_times>1
  File "/usr/local/lib/python3.5/dist-packages/dccp/problem.py", line 87, in dccp_ini
    ini_prob.solve(**kwargs)
  File "/usr/local/lib/python3.5/dist-packages/cvxpy/problems/problem.py", line 209, in solve
    return self._solve(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/cvxpy/problems/problem.py", line 331, in _solve
    kwargs)
  File "/usr/local/lib/python3.5/dist-packages/cvxpy/problems/solvers/ecos_intf.py", line 123, in solve
    **solver_opts)
  File "/usr/local/lib/python3.5/dist-packages/ecos.py", line 62, in solve
    return _ecos.csolve((m,n1,p), c, data, indices, colptr, h, dims, A.data, A.indices, A.indptr, b, **kwargs)
TypeError: 'use_indirect' is an invalid keyword argument for this function

My list of installed solvers: 'SCS', 'CVXOPT', 'ECOS', 'GLPK', 'GLPK_MI', 'ECOS_BB', 'LS'.
A quick look at the code comes with this theory: some places assume that solver exists in kwargs, but it is specified separately and would need to be added to kwargs manually.
Thanks for your time.

Getting - TypeError: cannot unpack non-iterable NotImplementedType object

Hi,
I am getting error during DCCP solving for quadratic equality constraint with quadratic objective function.
here is my error log:

`problem is DCP: False
problem is DCCP: True

AttributeError Traceback (most recent call last)
~/anaconda3/envs/fordccp/lib/python3.7/site-packages/cvxpy/utilities/performance_utils.py in _lazyprop(self)
26 try:
---> 27 return getattr(self, attr_name)
28 except AttributeError:

AttributeError: 'AddExpression' object has no attribute '_lazy_canonical_form'

During handling of the above exception, another exception occurred:

AttributeError Traceback (most recent call last)
~/anaconda3/envs/fordccp/lib/python3.7/site-packages/cvxpy/utilities/performance_utils.py in _lazyprop(self)
26 try:
---> 27 return getattr(self, attr_name)
28 except AttributeError:

AttributeError: 'real' object has no attribute '_lazy_canonical_form'

During handling of the above exception, another exception occurred:

TypeError Traceback (most recent call last)
in
9 print("problem is DCP:", myprob.is_dcp()) # false
10 print("problem is DCCP:", dccp.is_dccp(myprob)) # true
---> 11 result = myprob.solve(method = 'dccp')
12 print("x =", x.value)
13 print("cost value =", result[0])

~/anaconda3/envs/fordccp/lib/python3.7/site-packages/cvxpy/problems/problem.py in solve(self, *args, **kwargs)
287 else:
288 solve_func = Problem._solve
--> 289 return solve_func(self, *args, **kwargs)
290
291 @classmethod

~/anaconda3/envs/fordccp/lib/python3.7/site-packages/dccp-1.0.0-py3.7.egg/dccp/problem.py in dccp(self, max_iter, tau, mu, tau_max, solver, ccp_times, max_slack, ep, **kwargs)
40 dccp_ini(self, random=(ccp_times>1), solver = solver, **kwargs) # initialization; random initial value is mandatory if ccp_times>1
41 # iterations
---> 42 result_temp = iter_dccp(self, max_iter, tau, mu, tau_max, solver, ep, max_slack, **kwargs)
43 if result_temp[0] is not None:
44 if (self.objective.NAME == 'minimize' and result_temp[0]<cost_value) \

~/anaconda3/envs/fordccp/lib/python3.7/site-packages/dccp-1.0.0-py3.7.egg/dccp/problem.py in iter_dccp(self, max_iter, tau, mu, tau_max, solver, ep, max_slack_tol, **kwargs)
223 # solve
224 if solver is None:
--> 225 logger.info("iteration=%d, cost value=%.5f, tau=%.5f", it, prob_new.solve(**kwargs), tau)
226 else:
227 logger.info("iteration=%d, cost value=%.5f, tau=%.5f", it, prob_new.solve(solver=solver, **kwargs), tau)

~/anaconda3/envs/fordccp/lib/python3.7/site-packages/cvxpy/problems/problem.py in solve(self, *args, **kwargs)
287 else:
288 solve_func = Problem._solve
--> 289 return solve_func(self, *args, **kwargs)
290
291 @classmethod

~/anaconda3/envs/fordccp/lib/python3.7/site-packages/cvxpy/problems/problem.py in _solve(self, solver, warm_start, verbose, parallel, gp, qcp, **kwargs)
567 self._construct_chains(solver=solver, gp=gp)
568 data, solving_inverse_data = self._solving_chain.apply(
--> 569 self._intermediate_problem)
570 solution = self._solving_chain.solve_via_data(
571 self, data, warm_start, verbose, kwargs)

~/anaconda3/envs/fordccp/lib/python3.7/site-packages/cvxpy/reductions/chain.py in apply(self, problem)
63 inverse_data = []
64 for r in self.reductions:
---> 65 problem, inv = r.apply(problem)
66 inverse_data.append(inv)
67 return problem, inverse_data

~/anaconda3/envs/fordccp/lib/python3.7/site-packages/cvxpy/reductions/matrix_stuffing.py in apply(self, problem)
98 # Batch expressions together, then split apart.
99 expr_list = [arg for c in cons for arg in c.args]
--> 100 Afull, bfull = extractor.affine(expr_list)
101 if 0 not in Afull.shape and 0 not in bfull.shape:
102 Afull = cvxtypes.constant()(Afull)

~/anaconda3/envs/fordccp/lib/python3.7/site-packages/cvxpy/utilities/coeff_extractor.py in affine(self, expr)
75 expr_list = [expr]
76 size = sum([e.size for e in expr_list])
---> 77 op_list = [e.canonical_form[0] for e in expr_list]
78 V, I, J, b = canonInterface.get_problem_matrix(op_list, self.id_map)
79 A = sp.csr_matrix((V, (I, J)), shape=(size, self.N))

~/anaconda3/envs/fordccp/lib/python3.7/site-packages/cvxpy/utilities/coeff_extractor.py in (.0)
75 expr_list = [expr]
76 size = sum([e.size for e in expr_list])
---> 77 op_list = [e.canonical_form[0] for e in expr_list]
78 V, I, J, b = canonInterface.get_problem_matrix(op_list, self.id_map)
79 A = sp.csr_matrix((V, (I, J)), shape=(size, self.N))

~/anaconda3/envs/fordccp/lib/python3.7/site-packages/cvxpy/utilities/performance_utils.py in _lazyprop(self)
27 return getattr(self, attr_name)
28 except AttributeError:
---> 29 setattr(self, attr_name, func(self))
30 return getattr(self, attr_name)
31 return _lazyprop

~/anaconda3/envs/fordccp/lib/python3.7/site-packages/cvxpy/utilities/canonical.py in canonical_form(self)
38 A tuple of (affine expression, [constraints]).
39 """
---> 40 return self.canonicalize()
41
42 def variables(self):

~/anaconda3/envs/fordccp/lib/python3.7/site-packages/cvxpy/atoms/atom.py in canonicalize(self)
296 constraints = []
297 for arg in self.args:
--> 298 obj, constr = arg.canonical_form
299 arg_objs.append(obj)
300 constraints += constr

~/anaconda3/envs/fordccp/lib/python3.7/site-packages/cvxpy/utilities/performance_utils.py in _lazyprop(self)
27 return getattr(self, attr_name)
28 except AttributeError:
---> 29 setattr(self, attr_name, func(self))
30 return getattr(self, attr_name)
31 return _lazyprop

~/anaconda3/envs/fordccp/lib/python3.7/site-packages/cvxpy/utilities/canonical.py in canonical_form(self)
38 A tuple of (affine expression, [constraints]).
39 """
---> 40 return self.canonicalize()
41
42 def variables(self):

~/anaconda3/envs/fordccp/lib/python3.7/site-packages/cvxpy/atoms/atom.py in canonicalize(self)
303 graph_obj, graph_constr = self.graph_implementation(arg_objs,
304 self.shape,
--> 305 data)
306 return graph_obj, constraints + graph_constr
307

TypeError: cannot unpack non-iterable NotImplementedType object
`

Matmul depreciation warning

Hi,

I am using dccp==1.0.0 and cvxpy==1.1.1 (I wasn`t able to make a newer dccp version work ) I cannot get rid of depreciation warning when I use dccp.

UserWarning: 
This use of ``*`` has resulted in matrix multiplication.
Using ``*`` for matrix multiplication has been deprecated since CVXPY 1.1.
    Use ``*`` for matrix-scalar and vector-scalar multiplication.
    Use ``@`` for matrix-matrix and matrix-vector multiplication.
    Use ``multiply`` for elementwise multiplication.
  warnings.warn(__STAR_MATMUL_WARNING__, UserWarning)
  1. I do not have "*" in my problem configuration so I assume dccp uses it somewhere under the hood.
  2. I tried to ignore warnings before the import of dccp
import warnings
warnings.filterwarnings('ignore',category=UserWarning)

But that didn`t help. Could you please help ? I see 14 warnings in a row each time I solve the problem.

log(exp(x)) not DCCP?

Hello.

I have a problem with a rather straight-forward convex objective function and a set of non-convex but DCCP constraints. For the moment, I am trying to solve the unconstrained problem of the form:

image

and this is my formulation:

loss = sum_entries(log(np.ones((N, 1)) + exp(X * theta)) - mul_elemwise(y, X * theta))
prob = Problem(Minimize(loss))
print "Main Problem is DCCP? ", dccp.is_dccp(prob) #False

The original problem is demonstrably convex and DCP; in fact I managed to solve it with MATLAB CVX with ease.

Upon further investigation, I found out that log(exp(X * theta)) is the real culprit:

obj2 = sum_entries(log(exp(X * theta)))
obj3 = sum_entries(exp(X * theta))

prob2 = Problem(Minimize(obj2))
prob3 = Problem(Minimize(obj3))

print "obj2 Problem is DCCP? ", dccp.is_dccp(prob2)  #False
print "obj3 Problem is DCCP? ", dccp.is_dccp(prob3)  #True

So, my questions is: given that both log(.) and exp(.) are elementwise functions in CVXPY, how is it possible that log(exp(x)) is considered non-DCCP even when it is identically equal to x (with domain = R)? Is this a bug or am I missing something?

NotImplementedError for maximizing a convex function with regularization.

When i try to solve a problem of the form with Q positive definite.

min x.T @ x - x.T @ Q @ x
s.t. x_min <= x <= x_max

using the DCCP method. When I plug this directly
into the solver it get an error saying not DCCP. I then
took a look at the paper and transformed the problem
as

min x.T @ x - z
s.t. x_min <= x <= x_max
x.T @ Q @ x == z

but then I get a NotImplementedError. Is there something
missing in the DCCP library? Or is the problem simply
not solvable by this solver. Because as soon as I remove the regularization
term x.T @ x from the objective in the first problem, it can be solved.
Do you have a suggestion what's the problem?

examples/test.py doesn't work

kbriggs:~/Downloads/dccp-master/examples> python test.py
problem is DCP: False
problem is DCCP: True
Traceback (most recent call last):
File "test.py", line 11, in
result = myprob.solve(method = 'dccp',solver = 'MOSEK')
File "/usr/local/lib/python2.7/dist-packages/cvxpy/problems/problem.py", line 171, in solve
return func(self, _args, *_kwargs)
File "/usr/local/lib/python2.7/dist-packages/dccp-0.1.0-py2.7.egg/dccp/problem.py", line 31, in dccp
dccp_ini(self, random=(ccp_times>1)) # initialization; random initial value is mandatory if ccp_times>1
File "/usr/local/lib/python2.7/dist-packages/dccp-0.1.0-py2.7.egg/dccp/problem.py", line 50, in dccp_ini
dom_constr = self.objective.args[0].domain # domain of the objective function
AttributeError: 'pnorm' object has no attribute 'domain'

The programs in Example File can't work.

There are some bugs when I run the example codes. At first, I guess the program is designed under CVXPY 0.4.11 version. But the new bugs will incur after I reinstall the CVXPY 0.4.11. It said, "'LeqConstraint' object has no attribute 'expr'".
Then I install the CVXPY 1.0.19 by Anaconda2 and Anaconda3 . However, none of them can work. For example, all of the codes said "Variable name % must be a string". Can you please tell me how to run the program properly?

AttributeError/TypeError in Python3

The following test problem instance gives an attribute error in NumPy when executed with python3, which might have been caused by how the values are passed to the np.max function. The script runs fine using python2 and terminates without an error. (Though it gives the objective value of None.)

Error message:

iteration= 1 cost value =  -inf tau =  0.005
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/numpy/core/fromnumeric.py", line 2260, in amax
    amax = a.max
AttributeError: 'list' object has no attribute 'max'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "p3test.py", line 20, in <module>
    val = prob.solve(method='dccp')[0]
  File "/usr/local/lib/python3.5/dist-packages/cvxpy-0.4.8-py3.5.egg/cvxpy/problems/problem.py", line 208, in solve
    return func(self, *args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/dccp/problem.py", line 33, in dccp
    result_temp = iter_dccp(self, max_iter, tau, mu, tau_max, solver, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/dccp/problem.py", line 386, in iter_dccp
    max_slack = np.max(max_slack)
  File "/usr/lib/python3/dist-packages/numpy/core/fromnumeric.py", line 2263, in amax
    out=out, keepdims=keepdims)
  File "/usr/lib/python3/dist-packages/numpy/core/_methods.py", line 26, in _amax
    return umr_maximum(a, axis, None, out, keepdims)
TypeError: unorderable types: NoneType() >= NoneType()

Code:

import dccp
import cvxpy as cvx
import numpy as np
import scipy.sparse as sp

np.random.seed(1)
n = 3

x = cvx.Variable(n)
T = cvx.Variable()

obj = cvx.Minimize(T)
F1, F2 = np.random.randn(n, 2*n), np.random.randn(n, 2*n)
F1, F2 = F1.dot(F1.T), F2.dot(F2.T)
Pp, Pm = sp.csr_matrix(F1), sp.csr_matrix(F2)
cons = [cvx.quad_form(x, Pp) <= cvx.quad_form(x, Pm) + T, cvx.square(x)==1]
prob = cvx.Problem(obj, cons)
x.value = np.asmatrix(np.random.randn(n, 1))
val = prob.solve(method='dccp')[0]
print(val)

is_dccp not closed under difference of convex/dccp functions.

Hi CVX group, first of all thanks for the great work on CVXPY and DCCP.

I am trying to test how well the dccp paradigm can be used for inference in a simple graphical model, and I tried to use the cvx dccp package to minimize the following objective

image

Basically x_i are vectors that must lie in the positive simplex and M_i are predefined matrices.
Clearly both the components are convex as the following snippet shows.

import dccp, cvxpy
objective_1 = sum([cvxpy.sum_squares(M * x)
                       for M, x in zip(Mlist, X)])
objective_2 = cvxpy.sum_squares(
        sum([(M * x) for M, x in zip(Mlist, X)]))
>>> print dccp.problem.is_dccp(cvxpy.Problem(cvxpy.Minimize(objective_1)))
     True
>>> print dccp.problem.is_dccp(cvxpy.Problem(cvxpy.Minimize(objective_2)))
     True
>>> print (cvxpy.Problem(cvxpy.Minimize(objective_2))).is_dcp()
     True
>>> print (cvxpy.Problem(cvxpy.Minimize(objective_1))).is_dcp()
     True

Since the objectives are convec their difference should be eligible for dccp but unfortunately that does not happen.

>>> print dccp.problem.is_dccp(cvxpy.Problem(cvxpy.Minimize(objective_2 - objective_1)))
     False

As far as I can tell since I have not put any constraints the difference of two convex functions must be dccp. Am I overlooking something?

The example on the front page doesn't run due to an indexing error

I was trying out the first example provided on the DCCP GitHub page:

import cvxpy as cvx
import dccp
x = cvx.Variable(2)
y = cvx.Variable(2)
myprob = cvx.Problem(cvx.Maximize(cvx.norm(x-y,2)), [0<=x, x<=1, 0<=y, y<=1])
print("problem is DCP:", myprob.is_dcp())   # false
print("problem is DCCP:", dccp.is_dccp(myprob))  # true
result = myprob.solve(method = 'dccp')
print("x =", x.value)
print("y =", y.value)
print("cost value =", result[0])

I ran into an error running this code:

Traceback (most recent call last):
  File "dccp_error.py", line 8, in <module>
    result = myprob.solve(method = 'dccp')
  File "/anaconda3/lib/python3.6/site-packages/cvxpy/problems/problem.py", line 246, in solve
    return solve_func(self, *args, **kwargs)
  File "/anaconda3/lib/python3.6/site-packages/dccp/problem.py", line 40, in dccp
    dccp_ini(self, random=(ccp_times>1), solver = solver, **kwargs) # initialization; random initial value is mandatory if ccp_times>1
  File "/anaconda3/lib/python3.6/site-packages/dccp/problem.py", line 61, in dccp_ini
    for dom in arg.args[l].domain:
IndexError: list index out of range

The error seems to be in this block:

   for arg in self.constraints:
       for l in range(2):
           for dom in arg.args[l].domain:
               dom_constr.append(dom) # domain on each side of constraints

While digging around, I found that arg.args was a list of length 1 and not 2, as the above block seems to require. The comment seems to imply that the code is attempting to add the domain on “each side of the constraints”, but it seems that cvxpy is already parsing it into one side?

It seems to me than simply changing range(2) to range(1) would solve this issue in the source code?

(For context, I am using cvxpy v1.0.6 and dccp v1.0.0, installed via pip.)

import dccp fails when run from a readonly location

Currently importing dccp when python is run from a readonly location raises an error:

C:>python -c "import dccp"
Traceback (most recent call last):
File "", line 1, in
File "C:\Miniconda3\envs\dev37\lib\site-packages\dccp_init_.py", line 1, in
from dccp.problem import is_dccp
File "C:\Miniconda3\envs\dev37\lib\site-packages\dccp\problem.py", line 13, in
logger.addHandler(logging.FileHandler(filename='dccp.log', mode='w'))
File "C:\Miniconda3\envs\dev37\lib\logging_init_.py", line 1087, in init
StreamHandler.init(self, self.open())
File "C:\Miniconda3\envs\dev37\lib\logging_init
.py", line 1116, in _open
return open(self.baseFilename, self.mode, encoding=self.encoding)
PermissionError: [Errno 13] Permission denied: 'C:\dccp.log'

(and when importing from a location with write permissions an empty dccp.log is created.)

This happens because import dccp tries to create an (empty) dccp.log file in this line from problem.py:
logger.addHandler(logging.FileHandler(filename='dccp.log', mode='w')).

My preferred solution would be to drop this line entirely and let the application importing dccp decide which logging handlers to use.
An other (more opt-out kind of ) solution would be to change it into logger.addHandler(logging.FileHandler(filename='dccp.log', mode='w', delay=True)) which prevents the immediate writing of the dccp.log file and gives the application importing dccp the option to drop the handler before an actual write is attempted.

Slight probelm in the README.md

Hello.
There is a small problem in the example given in the root documentation file "README.md":

from cvxpy import *
import dccp
x = Variable(2)
y = Variable(2)
myprob = Problem(Maximize(norm(x-y,2)), [0<=x, x<=1, 0<=y, y<=1])
print "problem is DCP:", myprob.is_dcp()   # false
print "problem is DCCP:", dccp.is_dccp(myprob)  # true
result = myprob.solve(method = 'dccp')
print "x =", x.value
print "y =", y.value
print "cost value =", result[0]

The above returns an Attribute Error in the 7th line; which makes sense because dccp is a module not a class. To fix it, I replaced dccp with dccp.problem in both lines 2 and 7.

Problem.status in None in DCCP

According to https://www.cvxpy.org/api_reference/cvxpy.problems.html, status has to be a string and one of optimal, infeasible, or unbounded. But with solver='dccp', I'm often getting a None value (apparently when the solver has failed, since constraints are violated). What could cause this?

In fact even the first DCCP example has this problem:

import cvxpy as cvx
import dccp
x = cvx.Variable(2)
y = cvx.Variable(2)
myprob = cvx.Problem(cvx.Maximize(cvx.norm(x-y,2)), [0<=x, x<=1, 0<=y, y<=1])
print("problem is DCP:", myprob.is_dcp()) # false
print("problem is DCCP:", dccp.is_dccp(myprob)) # true
result = myprob.solve(method = 'dccp')
print("x =", x.value)
print("y =", y.value)
print("cost value =", result[0])
print("status =",myprob.status) # prints "None"
print("status =",myprob._status) # prints "None"

DCCP problem crashes with attribute error

Hi maintainers!

Actually, I have more than one problem/doubt. I'm going to explain what I'm doing and provide a minimal example.
I have a problem in the form x.T@P@x + q1.T@x + log(1+q2.T@x), which is the sum of a quadratic program with a strictly concave function, hence, a difference of convex functions.
First of all, I have this minimal example:

import dccp
import cvxpy as cp
import osqp
import numpy as np
import mosek

x = cp.Variable(5)
t = cp.Variable(1)
P = 16*np.diag(np.random.rand(5))
q = 7*np.random.rand(5).reshape((5,1))
qlog = 24*np.random.rand(5).reshape((5,1))
objective = cp.quad_form(x,P) + q.T@x - t
A = 2*np.random.rand(5,5)
b = np.random.rand(5)
constraints = [A@x==b, -cp.log(1+qlog.T@x)==t]
problem = cp.Problem(cp.Minimize(objective), constraints)
print(problem.is_dcp())
print(dccp.is_dccp(problem))
problem.solve(verbose=True, solver='SCS', method='dccp')

What happens is that OSQP, ECOS and GUROBI don't even start the optimization because the problem cannot be reduced to a QP and a conic solver is needed. I thought the reason why dccp exists is to transform that problem in a convex one linearizing the concave part at every iteration, so any quadratic solver should do it. Anyway, SCS and MOSEK work. But soon, an exception is thrown:

AttributeError: 'AddExpression' object has no attribute '_lazy_canonical_form' (cvxpy\utilities\performance_utils.py)
During handling of the above exception, another exception occurred:
AttributeError: 'real' object has no attribute '_lazy_canonical_form' (cvxpy\utilities\performance_utils.py)
During handling of the above exception, another exception occurred:
TypeError: cannot unpack non-iterable NotImplementedType object (cvxpy\atoms\atom.py)

I thought there were problems of versions, that maybe the attribute _laxy_canonical_form existed in a previous version of cvxpy. But I found no trace of it. However, I reinstalled Anaconda and now everything is up to date. The problem persists.
Moreover, this is a minimal example that I did to debug my code. In my problem I have matrix P and vectors q1 and q2 built so that dccp tells me that the problem is not dccp. Given that, with only the QP, the problem is correctly solved by OSQP, is it possible that it depends on the value of P and q?
Finally, is the way shown the correct one to define a dccp problem, with the auxiliary variable t?

Thanks in advance,

Giovanni

EDIT: I was doing a bad mistake building my matrix P. After debugging, now I have the same attribute error and type error as the minimal working example. However, what was said was true the same. Dccp told me that the problem was not dccp and it was strange, because OSQP solved the convex part.

Failure on small problem

I ran dccp on this problem

from cvxpy import *
import dccp

x = Variable()

prob = Problem(Minimize(log(x)), [x**2 >= 5])
prob.solve(method="dccp")
print x.value

and I got a weird error message

iteration= 1 cost value =  0.373930353269 tau =  0.005
max slack =  18.0335348159
iteration= 2 cost value = 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "cvxpy/problems/problem.py", line 171, in solve
    return func(self, *args, **kwargs)
  File "/Users/stevend2/anaconda/envs/cvxpy/lib/python2.7/site-packages/dccp-0.1.0-py2.7.egg/dccp/problem.py", line 34, in dccp
    result_temp = iter_dccp(self, max_iter, tau, mu, tau_max, solver)
  File "/Users/stevend2/anaconda/envs/cvxpy/lib/python2.7/site-packages/dccp-0.1.0-py2.7.egg/dccp/problem.py", line 373, in iter_dccp
    print "iteration=",it, "cost value = ", prob_new.solve(), "tau = ", tau
  File "cvxpy/problems/problem.py", line 173, in solve
    return self._solve(*args, **kwargs)
  File "cvxpy/problems/problem.py", line 284, in _solve
    self._update_problem_state(results_dict, sym_data, solver)
  File "cvxpy/problems/problem.py", line 392, in _update_problem_state
    self._handle_no_solution(results_dict[s.STATUS])
  File "cvxpy/problems/problem.py", line 438, in _handle_no_solution
    constr.save_value(None)
AttributeError: 'index' object has no attribute 'save_value'

It's non-deterministic (probably due to the randomized initialization).

circle_packing.py doesn't work

kbriggs:> sudo pip install --upgrade cvxpy
kbriggs:
> sudo pip install dccp

kbriggs:~/python> python circle_packing.py
Traceback (most recent call last):
File "circle_packing.py", line 16, in
prob.solve(method = 'dccp', ccp_times = 3)
File "/usr/local/lib/python2.7/dist-packages/cvxpy/problems/problem.py", line 171, in solve
return func(self, _args, *_kwargs)
File "/usr/local/lib/python2.7/dist-packages/dccp/dccp_problem.py", line 25, in dccp
result = iter_dccp(self, max_iter, tau, mu, tau_max, solver)
File "/usr/local/lib/python2.7/dist-packages/dccp/dccp_problem.py", line 160, in iter_dccp
temp = convexify_constr(arg)
File "/usr/local/lib/python2.7/dist-packages/dccp/convexify_constr.py", line 47, in convexify_constr
lin = linearize(self.args[1])
File "/usr/local/lib/python2.7/dist-packages/dccp/linearize.py", line 41, in linearize
for key in expr.gradient:
AttributeError: 'pnorm' object has no attribute 'gradient'

How to process the constraint like huber(x)>=0

Hi, I met the error below when trying to solve a logistic regression problem with constraint "huber(x)>=0"

TypeError: cannot unpack non-iterable NotImplementedType object.

The problem has passed the DCCP test (dccl.is_dccp(problem) == True), I've tried both python2 and python3 but nothing changed.
Hoping for help, Thanks.

/examples/test.py not working IndexError: list index out of range

I'm new to Python and just following the installation guide and trying this in a Ubuntu VM.
I've installed anaconda 2.7 and trying the test.py in ../dccp/examples. This is the error message below.
Any help is appreciated.

~/dccp/examples$ python test.py
problem is DCP: False
problem is DCCP: True
Traceback (most recent call last):
File "test.py", line 12, in
result = myprob.solve(method = 'dccp', solver = 'SCS', use_indirect = False, warm_start = True)
File "/home/localadmin/anaconda2/lib/python2.7/site-packages/cvxpy/problems/problem.py", line 246, in solve
return solve_func(self, *args, **kwargs)
File "/home/localadmin/anaconda2/lib/python2.7/site-packages/dccp/problem.py", line 36, in dccp
dccp_ini(self, random=(ccp_times>1), **kwargs) # initialization; random initial value is mandatory if ccp_times>1
File "/home/localadmin/anaconda2/lib/python2.7/site-packages/dccp/problem.py", line 57, in dccp_ini
for dom in arg.args[l].domain:
IndexError: list index out of range

Regards

Zi

difference of convex programming

The descriptive text "difference of convex programming" really does need to be changed to "difference-of-convex programming".

The first way parses to my eye as "(difference of (convex programming))", which makes no sense, The correct parsing "((difference of convex) programming)" is enforced by the hyphens.

AttributeError: 'Maximize' object has no attribute 'expr'

Hi,
I want to use dccp to solve a problem but none of the examples work for me. I get the following error: AttributeError: 'Maximize' object has no attribute 'expr' for the line containing 'print("problem is DCCP:", dccp.is_dccp(prob)) '
for anything I try.
Can you please help? Thanks

method is_dccp() is absent

I installed dccp 0.1.5 with pip 9.0.1, and after import dccp there's no dccp.is_dccp() method. I only find constraint, linearize, objective and problem.

solution for polynomial function non-convexity

Hi.
I want to solve a problem which has polynomial function equality constraints.

I tried to solve a simple toy problem that has one polynomial constraint (x^3 == -1) via DCCP.
However, even though cvxpy says the problem is not dcp BUT IS DCCP, it can't solve it.
Do you have any ideas to solve the problem?

[CODE]

import cvxpy as cvx
import dccp

x = cvx.Variable(1)
# prob = cvx.Problem(cvx.Minimize(0), [x**3 == -1]) # I want to consider x < 0 cases
prob = cvx.Problem(cvx.Minimize(0), [cvx.pos(x)**3 == -1 + cvx.pos(-x)**3])  # convex == convex
print("problem is DCP:", prob.is_dcp())
print("problem is DCCP:", dccp.is_dccp(prob))
prob.solve(verbose=False, solver=cvx.SCS, method='dccp')
print("status:", prob.status)
print("optimal value", prob.value)
print("optimal var", x.value)

[Result]

problem is DCP: False
problem is DCCP: True

[Error]

---------------------------------------------------------------------------
DCPError                                  Traceback (most recent call last)
~/Google_Drive_Denso_IT_Laboratory/git/UtotchMain/LearningMPC/LithiumIonBattery.py in 
      457 print("problem is DCP:", prob.is_dcp())
      458 print("problem is DCCP:", dccp.is_dccp(prob))
---> 459 prob.solve(verbose=False, solver=cvx.SCS, method='dccp')
     460 print("status:", prob.status)
     461 print("optimal value", prob.value)

~/.julia/conda/3/lib/python3.8/site-packages/cvxpy/problems/problem.py in solve(self, *args, **kwargs)
    323         else:
    324             solve_func = Problem._solve
--> 325         return solve_func(self, *args, **kwargs)
    326 
    327     @classmethod

~/.julia/conda/3/lib/python3.8/site-packages/dccp/problem.py in dccp(self, max_iter, tau, mu, tau_max, solver, ccp_times, max_slack, ep, **kwargs)
     38         cost_value = -float("inf")
     39     for t in range(ccp_times): # for each time of running ccp
---> 40         dccp_ini(self, random=(ccp_times>1), solver = solver, **kwargs) # initialization; random initial value is mandatory if ccp_times>1
     41         # iterations
     42         result_temp = iter_dccp(self, max_iter, tau, mu, tau_max, solver, ep, max_slack, **kwargs)

~/.julia/conda/3/lib/python3.8/site-packages/dccp/problem.py in dccp_ini(self, times, random, solver, **kwargs)
    116             ini_prob.solve(**kwargs)
    117         else:
--> 118             ini_prob.solve(solver = solver, **kwargs)
    119         var_ind = 0
    120         for var in self.variables():

~/.julia/conda/3/lib/python3.8/site-packages/cvxpy/problems/problem.py in solve(self, *args, **kwargs)
    323         else:
    324             solve_func = Problem._solve
--> 325         return solve_func(self, *args, **kwargs)
    326 
    327     @classmethod

~/.julia/conda/3/lib/python3.8/site-packages/cvxpy/problems/problem.py in _solve(self, solver, warm_start, verbose, gp, qcp, requires_grad, **kwargs)
    637                 return self.value
    638 
--> 639         data, solving_chain, inverse_data = self.get_problem_data(solver, gp)
    640         solution = solving_chain.solve_via_data(
    641             self, data, warm_start, verbose, kwargs)

~/.julia/conda/3/lib/python3.8/site-packages/cvxpy/problems/problem.py in get_problem_data(self, solver, gp)
    423         if key != self._cache.key:
    424             self._cache.invalidate()
--> 425             solving_chain = self._construct_chain(solver=solver, gp=gp)
    426             self._cache.key = key
    427             self._cache.solving_chain = solving_chain

~/.julia/conda/3/lib/python3.8/site-packages/cvxpy/problems/problem.py in _construct_chain(self, solver, gp)
    548         """
    549         candidate_solvers = self._find_candidate_solvers(solver=solver, gp=gp)
--> 550         return construct_solving_chain(self, candidate_solvers, gp=gp)
    551 
    552     def _invalidate_cache(self):

~/.julia/conda/3/lib/python3.8/site-packages/cvxpy/reductions/solvers/solving_chain.py in construct_solving_chain(problem, candidates, gp)
    144     if len(problem.variables()) == 0:
    145         return SolvingChain(reductions=[ConstantSolver()])
--> 146     reductions = _reductions_for_problem_class(problem, candidates, gp)
    147 
    148     # Conclude with matrix stuffing; choose one of the following paths:

~/.julia/conda/3/lib/python3.8/site-packages/cvxpy/reductions/solvers/solving_chain.py in _reductions_for_problem_class(problem, candidates, gp)
     82             append += ("\nHowever, the problem does follow DQCP rules. "
     83                        "Consider calling solve() with `qcp=True`.")
---> 84         raise DCPError(
     85             "Problem does not follow DCP rules. Specifically:\n" + append)
     86 

DCPError: Problem does not follow DCP rules. Specifically:
The following constraints are not DCP:
0.0 <= maximum(var63926, 0.0) , because the following subexpressions are not:
|--  0.0 <= maximum(var63926, 0.0)
0.0 <= maximum(-var63926, 0.0) , because the following subexpressions are not:
|--  0.0 <= maximum(-var63926, 0.0)
However, the problem does follow DQCP rules. Consider calling solve() with `qcp=True`.

examples/path_avoi_control.py doesn't work

kbriggs:> python3 examples/path_avoi_control.py
Traceback (most recent call last):
File "examples/path_avoi_control.py", line 59, in
prob.solve(method='dccp')
File "/usr/local/lib/python3.4/dist-packages/cvxpy/problems/problem.py", line 171, in solve
return func(self, _args, *_kwargs)
File "/usr/local/lib/python3.4/dist-packages/dccp-0.1.0-py3.4.egg/dccp/problem.py", line 31, in dccp
dccp_ini(self, random=(ccp_times>1)) # initialization; random initial value is mandatory if ccp_times>1
File "/usr/local/lib/python3.4/dist-packages/dccp-0.1.0-py3.4.egg/dccp/problem.py", line 50, in dccp_ini
dom_constr = self.objective.args[0].domain # domain of the objective function
AttributeError: 'AddExpression' object has no attribute 'domain'

iter_dccp slack variables

The same bug in another place. The slack variables need to be summed with sum_entries
around line 355 inn problem.py.

Failed for a simple case

Hi,

I'm testing with the following case

import cvxpy as cvx
import dccp
x = cvx.Variable(1)
myprob = cvx.Problem(cvx.Minimize(x**4-3*x**2-x), [0<=x, x<=2])
print("problem is DCP:", myprob.is_dcp())  
print("problem is DCCP:", dccp.is_dccp(myprob))

result = myprob.solve(method = 'dccp', verbose=True)
print("x =", x.value)
print("cost value =", result[0]) 

The function looks like the following
image
and should reach the minimum at around x=1.33.

However the above code always returns x at boundary. Am I doing something wrong?

Accidental global logging configuration.

In problem.py, the logging.basicConfig setup accidentally sets the global preferences for logging for all following uses. Hence, the following code:

import logging
import dccp
logging.error('test')

will simply write the error into the dccp.log file instead of showing it on the console. This, obviously, makes debugging very difficult.

Perhaps creating a instance of the Logger class is warranted here or perhaps the configuration line should be completely removed, letting the user decide how the logging should be handled.

Status of the problem + warm_start

Hello

Is there a way to find out if the problem converged successfully or not. CVXPY has a problem.status filed for this purpose. However, DCCP problems don't seem to have this field (looking for problem.status returns nothing).

Also, the warm_start option provided in CVXPY does not seem to be there in DCCP. Could you please point out if there is a way to use warm_start in DCCP. Essentially, I am trying to solve a constrained problem, by first solving it without constraints, and then using the warm_start option to solve it with constraints (so as to provide a starting point to the constrained problem).

Thank you!

dccp fails if ccp_times>1 in call to solve

If ccp_times is >1, then there is a crash in this line:

if t==0 or len(result_temp)<3 or result[1] < max_slack:

because result_temp[1], which is returned by iter_dccp, is a list of arrays.

Keith

A practical application problem for dccp

Hello @xinyueshen , I want to use DCCP to reproduce the numerical results in this paper.
图片
The objective f(p) - g(p) is D.C function. The result of my code can recognize it as dccp problem. However, the result of variables is none

import cvxpy as cvx
import numpy as np
from dccp.problem import is_dccp
import matplotlib.pyplot as plt
import dccp
import math

##follow the numerical design in Fast global optimal power allocation in wiereless networks by local D.C. Programming
H = np.matrix([[0.431,0.0002,0.2605,0.0039],[0.0002,0.3018,0.0008,0.0054],[0.0129,0.0005,0.4266,0.1007],[0.0011,0.0031,0.0099,0.0634]])


M = 4
ri = 1.0
w = [1.0/6,1.0/6,1.0/3,1.0/3]

p_max = [1.0,1.0,1.0,1.0]
#p_max = [0.7,0.8,0.9,1.0]
sigmal2 = 0.0001

p = cvx.Variable(M)
t = cvx.Variable(1)
constr = []
 ##The constraints: (3c) and (5)
for i in range(M-1):
    laterValue = 0
    for j in range(M-1):
        if j != i:
            laterValue = laterValue + H[j,i]*p[j]
    constr.append(H[i,i]*p[i]+(1-pow(2,ri))*(laterValue+sigmal2)>=0) ## (3c)
    constr.append(p[i]<=p_max[i]) ## (5)
    constr.append(0<=p[i])

## The objective function is reformulated as f(x)-t: t = g(x);
f_p = 0
g_p = 0
for i in range(M-1):
    laterValue_all = 0
    laterValue = 0
    for j in range(M-1):
        laterValue_all = laterValue_all + H[j,i]*p[j]
        if j != i:
            laterValue = laterValue + H[j,i]*p[j]
    f_p = f_p + w[i]*cvx.log(sigmal2 + laterValue_all)/cvx.log(2).value
    g_p = g_p + w[i]*cvx.log(sigmal2 + laterValue)/cvx.log(2).value

constr.append(t==g_p)

prob = cvx.Problem(cvx.Maximize(f_p-t),constr)
print is_dccp(prob)
prob.solve(method='dccp',ep = 1e-2)
print p.value

The result is
图片

Can you please help me? I will really appreciate it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.