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

[Feature request] Hide unused parameters as constants #123

Open
JinraeKim opened this issue Feb 12, 2022 · 0 comments
Open

[Feature request] Hide unused parameters as constants #123

JinraeKim opened this issue Feb 12, 2022 · 0 comments

Comments

@JinraeKim
Copy link

I'd like to change the value of "Parameter" x for efficient multiple solves, which is not in the scope of cvxpylayer.
Instead, A is the Parameter for cvxpylayer.
MWE (minimum working example) is as follows.

import numpy as np
import cvxpy as cp
import torch
from cvxpylayers.torch import CvxpyLayer


if __name__ == "__main__":
    n, m = 3, 2
    x = cp.Parameter((1, n))
    A = cp.Parameter((n, m))
    A_tch = torch.randn((n, m))
    u = cp.Variable((1, m))
    obj = cp.Minimize(x @ A @ u.T)
    constraints = [cp.norm(u) <= 1]
    prob = cp.Problem(obj, constraints)
    x.value = np.random.randn(1, n)
    cvxpylayer = CvxpyLayer(prob, parameters=[A], variables=[u])
    sol, = cvxpylayer(A_tch)  # DPP error

Even only injecting A into CvxpyLayer, the MWE gave me an error as it's not DPP.

Traceback (most recent call last):
  File "/Users/jinrae/github/other-projects/parametrised-convex-q-learning/tmp/tmp.py", line 17, in <module>
    cvxpylayer = CvxpyLayer(prob, parameters=[A], variables=[u])
  File "/Users/jinrae/Library/Caches/pypoetry/virtualenvs/parametrised-convex-q-learning-2h6IOcxJ-py3.9/lib/python3.9/site-packages/cvxpylayers/torch/cvxpylayer.py", line 79, in __init__
    raise ValueError('Problem must be DPP.')
ValueError: Problem must be DPP.

Can the CvxpyLayer hide unused cvxpy Parameters as constants for this usage?

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