Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError: Can't apply Jacobian with a quadratic objective #153

Open
mr-mikmik opened this issue Dec 5, 2023 · 0 comments
Open

ValueError: Can't apply Jacobian with a quadratic objective #153

mr-mikmik opened this issue Dec 5, 2023 · 0 comments

Comments

@mr-mikmik
Copy link

mr-mikmik commented Dec 5, 2023

Hi all,
I am trying to get gradients on a QP solution, but I am having the following error: ValueError: Can't apply Jacobian with a quadratic objective.
This is the trace:

File python3.8/site-packages/cvxpylayers/torch/cvxpylayer.py:286, in _CvxpyLayerFn.<locals>._CvxpyLayerFnFn.backward(ctx, *dvars)
    284 grad = [[] for _ in range(len(param_order))]
    285 for i in range(ctx.batch_size):
--> 286     del_param_dict = compiler.apply_param_jac(
    287         dcs[i], -dAs[i], dbs[i])
    288     for j, p in enumerate(param_order):
    289         grad[j] += [to_torch(del_param_dict[p.id],
    290                              ctx.dtype, ctx.device).unsqueeze(0)]
File python3.8/site-packages/cvxpy/reductions/dcp2cone/cone_matrix_stuffing.py:222, in ParamConeProg.apply_param_jac(self, delc, delA, delb, active_params)
    214 """Multiplies by Jacobian of parameter mapping.
    215 
    216 Assumes delA is sparse.
   (...)
    219     A dictionary param.id -> dparam
    220 """
    221 if self.P is not None:
--> 222     raise ValueError("Can't apply Jacobian with a quadratic objective.")
    224 if active_params is None:
    225     active_params = {p.id for p in self.parameters}

using cvxpy 1.4.1 and cvxpylayers 0.0.1

I need help understanding why it does not work with quadratic objectives. Any insights will be much appreciated.
Thank you.

Just for reference, this is the form of my program:

$$\begin{array}{ccc} \underset{\mathbf x}{\min} & \frac{1}{2}\mathbf x^T\mathbf Q\mathbf x& \\ \text{s.t.} & \mathbf G \mathbf x \preceq \mathbf h & \\ & \mathbf A\mathbf x = \mathbf b, & \end{array}$$

where $\mathbf x$ is a cp.Variable, $\mathbf Q$ is a constant, and $\mathbf G$, $\mathbf h$, $\mathbf A$, and $\mathbf b$ are cp.Parameter.

For context, the goal is to optimize via the backpropagated gradients a set of parameters that produce $\mathbf G$, $\mathbf h$, $\mathbf A$, and $\mathbf b$.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant