How to patch warm-start capability into cvxpy interface for many solvers ?
Navigate to cvxpy/reductions/solvers/qp_solvers/osqp_qpif.py
Add the following code snippet to the OSQP class:
# add this to the top of the file
from cvxpy .reductions .solvers import utilities
...
...
class OSQP (QpSolver ):
....
....
def apply (self , problem ):
...
...
# Add initial guess.
data ['init_value' ] = utilities .stack_vals (problem .variables , default = 0.0 )
return data , inv_data
def solve_via_data (self , data , warm_start , verbose , solver_opts ):
...
...
try :
solver .setup (P , q , A , lA , uA , verbose = verbose , ** solver_opts )
# add this block
if warm_start and 'init_value' in data :
init_x = data ['init_value' ]
print (f"Using warm start with user-provided initial value: shape={ init_x .shape } " )
solver .warm_start (x = init_x , y = None )
...
...
Navigate to cvxpy/reductions/solvers/qp_solvers/prox_qpif.py
Add the following code snippet to the PROXQP class:
# add this to the top of the file
from cvxpy .reductions .solvers import utilities
...
...
class PROXQP (QpSolver ):
....
....
def apply (self , problem ):
...
...
# Add initial guess.
data ['init_value' ] = utilities .stack_vals (problem .variables , default = 0.0 )
return data , inv_data
def solve_via_data (self , data , warm_start , verbose , solver_opts ):
...
...
if warm_start and 'init_value' in data :
init_x = data ['init_value' ]
print (f"Using warm start with user-provided initial value: shape={ init_x .shape } " )
solver .solve (init_x , None , None )
else :
print (f"Cold-starting PROXQP solver" )
solver .solve ()
...
...