Skip to content

Error using complex variables #69

@pizqleh

Description

@pizqleh

Hello,

I have been working with CVXPY over a convex problem with complex variables and no constraints of the form

min C_a(x),

where x = cp.Variable(n, complex=True). It worked perfectly, even using DCCP.

Now, it turns out that this is an approximation of a convex-concave problem with complex variables and no constraints of the form

min C_{a_1}(x) - C_{a_2}(x),

where x = cp.Variable(n, complex=True).

Then, I tried to solve it with DCCP using the standard reformulation

min C_{a_1}(x) - t
s.t. C_{a_2}(x) = t,

where x = cp.Variable(n, complex=True), t = cp.Variable(1). But I couldn't, the solver threw this error:

File "/Users/P/Desktop/thesis/wave-field-reconstruction/sinusoidal.py", line 139, in minimice_dccp
optimum = p_problem.solve(method='dccp')
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/cvxpy/problems/problem.py", line 396, in solve
return solve_func(self, *args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/dccp/problem.py", line 54, in dccp
result_temp = iter_dccp(
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/dccp/problem.py", line 241, in iter_dccp
temp = convexify_constr(arg)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/dccp/constraint.py", line 76, in convexify_constr
right = linearize(constr.args[1])
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/dccp/linearize.py", line 58, in linearize
grad_map = expr.grad
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/cvxpy/atoms/atom.py", line 399, in grad
grad_arg = arg.grad
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/cvxpy/atoms/atom.py", line 399, in grad
grad_arg = arg.grad
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/cvxpy/atoms/atom.py", line 399, in grad
grad_arg = arg.grad
[Previous line repeated 2 more times]
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/cvxpy/atoms/atom.py", line 393, in grad
grad_self = self._grad(arg_values)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/cvxpy/atoms/affine/affine_atom.py", line 131, in _grad
canon_mat = canonInterface.get_problem_matrix(
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/cvxpy/cvxcore/python/canonInterface.py", line 327, in get_problem_matrix
build_lin_op_tree(lin, linPy_to_linC)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/cvxpy/cvxcore/python/canonInterface.py", line 518, in build_lin_op_tree
make_linC_from_linPy(linPy, linPy_to_linC)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/cvxpy/cvxcore/python/canonInterface.py", line 492, in make_linC_from_linPy
set_linC_data(linC, linPy)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/cvxpy/cvxcore/python/canonInterface.py", line 466, in set_linC_data
set_matrix_data(linC, linPy)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/cvxpy/cvxcore/python/canonInterface.py", line 438, in set_matrix_data
linC.set_dense_data(format_matrix(linPy.data, shape=linPy.shape))
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/cvxpy/cvxcore/python/cvxcore.py", line 200, in set_dense_data
return _cvxcore.LinOp_set_dense_data(self, matrix)
TypeError: Cannot cast array data from dtype('complex128') to dtype('float64') according to the rule 'safe'

Maybe the error is related to the utilization of complex and real variables. It's wierd, beacuse if I put t = cp.Variable() instead of t = cp.Variable(1) I get a different error:

File "/Users/P/Desktop/thesis/wave-field-reconstruction/sinusoidal.py", line 139, in minimizar_dccp
optimum = p_problem.solve(method='dccp')
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/cvxpy/problems/problem.py", line 396, in solve
return solve_func(self, *args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/dccp/problem.py", line 50, in dccp
dccp_ini(
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/dccp/problem.py", line 142, in dccp_ini
value_para[count_para].value = np.random.randn(var.size) * 10
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/cvxpy/expressions/constants/parameter.py", line 82, in value
self._value = self._validate_value(val)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/cvxpy/expressions/leaf.py", line 379, in _validate_value
raise ValueError(
ValueError: Invalid dimensions (1,) for Parameter value.

Thanks in advance,
P.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions