Initial Guess/Warm start in CVXPY: give a hint of the solution
Asked Answered
P

2

8

In this bit of code:

import cvxpy as cvx

# Examples: linear programming
# Create two scalar optimization variables.
x = cvx.Variable()
y = cvx.Variable()

# Create 4 constraints.
constraints = [x >= 0,
               y >= 0,
               x + y >= 1,
              2*x + y >= 1]

# Form objective.
obj = cvx.Minimize(x+y)

# Form and solve problem.
prob = cvx.Problem(obj, constraints)
prob.solve(warm_start= True)  # Returns the optimal value.
print ("status:", prob.status)
print ("optimal value", prob.value)
print ("optimal var", x.value, y.value)

I'm looking for a way to choose the warm start value myself (for example: x = 1/2 and y = 1/2), not the previous solver result.

Is there any way to give the solver this input? And if not, is there a non-commercial alternative to cvxpy?

Poultry answered 13/9, 2018 at 13:15 Comment(2)
Is there a good reason you would like to warm-start the solver? Since the problem is convex, the optimal cost value should not change. If you are solving similar problems where parameters change, you can use the warm_start feature described here.Mainstay
@bstellato, actually, the problem I'm dealing with is much more complex. I want to warm start the solver, because the real optimization takes a lot of time, but I am able to find a good starting point by using another algorithm, which I like to use as my initial guess.Poultry
S
6

To the 2021 readers: today is impossible (in cvxpy) to give a hand to the solver with an initial guess. Warm start right now only works when you solve the same problem with different parameter values, initializing with the previous solution (see https://github.com/cvxpy/cvxpy/issues/1355).

Stere answered 29/4, 2021 at 15:19 Comment(0)
C
4

You can manually assign the values using x.value = 1/2, and then passing the warm_start=True parameter in the available solvers. Keep in mind not all solvers allow this, one that does is for example SCS.

More info available on: https://www.cvxpy.org/tutorial/advanced/index.html

Cown answered 29/10, 2018 at 3:37 Comment(1)
This is only true for cp.Parameters - as shown the page you link to.Verditer

© 2022 - 2025 — McMap. All rights reserved.