cvxpy_codegen icon indicating copy to clipboard operation
cvxpy_codegen copied to clipboard

Constant expressions involving the <class 'cvxpy.atoms.affine.transpose.transpose'> atom not supported.

Open snietfeld opened this issue 7 years ago • 0 comments

If I modify the example code slightly to add a new parameter that requires a transpose operation, i.e.:

import cvxpy_codegen as cg
m = 10
n = 5
A = cg.Parameter(m, n, name='A')
b = cg.Parameter(m, name='b')
c = cg.Parameter(n, name='c')           # <--------- New param
x = cg.Variable(n, name='x')
f0 = cg.norm(A*x - b) - c.T*x           # <--------- Transpose added
prob = cg.Problem(cg.Minimize(f0))
prob.codegen('least_squares_example')

I get the following exception:

Traceback (most recent call last): File "transpose_test.py", line 10, in prob.codegen('least_squares_example') File "/usr/local/lib/python3.5/dist-packages/cvxpy_codegen-0.0.1-py3.5.egg/cvxpy_codegen/problem.py", line 31, in codegen CodeGenerator(obj, constraints, vars, params).codegen(target_dir) File "/usr/local/lib/python3.5/dist-packages/cvxpy_codegen-0.0.1-py3.5.egg/cvxpy_codegen/code_generator.py", line 100, in codegen self.template_vars.update(param_handler.get_template_vars()) File "/usr/local/lib/python3.5/dist-packages/cvxpy_codegen-0.0.1-py3.5.egg/cvxpy_codegen/param/param_handler.py", line 72, in get_template_vars self.process_expression(root_param) File "/usr/local/lib/python3.5/dist-packages/cvxpy_codegen-0.0.1-py3.5.egg/cvxpy_codegen/param/param_handler.py", line 92, in process_expression data_arg = self.process_expression(expr.atom) File "/usr/local/lib/python3.5/dist-packages/cvxpy_codegen-0.0.1-py3.5.egg/cvxpy_codegen/param/param_handler.py", line 121, in process_expression data_list = get_atom_data(expr, arg_data) File "/usr/local/lib/python3.5/dist-packages/cvxpy_codegen-0.0.1-py3.5.egg/cvxpy_codegen/atoms/atoms.py", line 68, in get_atom_data raise TypeError("Constant expressions involving the %s atom not supported." % str(type(expr))) TypeError: Constant expressions involving the <class 'cvxpy.atoms.affine.transpose.transpose'> atom not supported.

I can get it to run by removing the transpose operator and redefining the parameter as a row vector, i.e.: c = cg.Parameter(1,n, name='c')

...but it would be nice to support the canonical constraint form where c is a column vector. As it is I'll have to always remember to transpose that value in particular before passing in to the C function call or Python wrapper.

snietfeld avatar Dec 10 '17 05:12 snietfeld