qpsolvers / qpsolvers Goto Github PK
View Code? Open in Web Editor NEWQuadratic programming solvers in Python with a unified API
License: GNU Lesser General Public License v3.0
Quadratic programming solvers in Python with a unified API
License: GNU Lesser General Public License v3.0
Currently OSQP settimgs are e.g. overriden to eps_abs=eps_rel=1e-4
while SCS settings are overriden to eps_abs=eps_rel=1e-7
. Solver settings should be left to their default values from the solver itself, especially for benchmarking with default settings.
Hi @stephane-caron,
I have been using qpsolvers for a while, it's a great implementation.
However, I have an unexpected behavior when 'quadprog' and 'cvxopt' solvers are used in some specific cases. The former shows the error
ValueError: constraints are inconsistent, no solution
and the latter returns 'none'.
Minimal example:
import numpy as np
from qpsolvers import solve_qp
n = 6
H = 5.91249627*np.identity(n)
f = np.array([-0.37214733, 15.92113921, 15.84163501,
1.2103246, -0.16915788, -1.21201618]).reshape((n))
Ades = np.array([[-1.85864514e-01, -5.49878560e-01, 2.08186925e-01, -7.03941541e-02, -2.40054190e-02, 9.40351703e-17],
[0.00000000e+00, 5.48184665e-02, 4.37742048e-02, -1.37938157e-02, -3.65468438e-03, 0.00000000e+00]])
bdes = np.array([-0.0691808, -0.01045375])
Aeq = np.array([0., -0.18543256, -0.14807351, 0.04665987, 0.01236258, 0])
beq = np.array([0.03536153])
u = solve_qp(H, f, Ades, bdes, Aeq, beq, solver='cvxopt' ) #solvers 'cvxopt' 'quadprog'
print("Solution: ",u)
This code returns:
Solution: None
Process finished with exit code 0
When I use 'quadprog':
import numpy as np
from qpsolvers import solve_qp
n = 6
H = 5.91249627*np.identity(n)
f = np.array([-0.37214733, 15.92113921, 15.84163501,
1.2103246, -0.16915788, -1.21201618]).reshape((n))
Ades = np.array([[-1.85864514e-01, -5.49878560e-01, 2.08186925e-01, -7.03941541e-02, -2.40054190e-02, 9.40351703e-17],
[0.00000000e+00, 5.48184665e-02, 4.37742048e-02, -1.37938157e-02, -3.65468438e-03, 0.00000000e+00]])
bdes = np.array([-0.0691808, -0.01045375])
Aeq = np.array([0., -0.18543256, -0.14807351, 0.04665987, 0.01236258, 0])
beq = np.array([0.03536153])
u = solve_qp(H, f, Ades, bdes, Aeq, beq, solver='quadprog' ) #solvers 'cvxopt' 'quadprog'
print("Solution: ",u)
Returns:
return solve_qp(qp_G, qp_a, qp_C, qp_b, meq)[0]
File "quadprog/quadprog.pyx", line 102, in quadprog.solve_qp
ValueError: constraints are inconsistent, no solution
The same code in Matlab returns a solution:
clear all
close all
clc
H = 5.91249627*eye(6);
f= [-0.37214733, 15.92113921, 15.84163501, 1.2103246, -0.16915788, -1.21201618];
Ades = [-1.85864514e-01 -5.49878560e-01 2.08186925e-01 -7.03941541e-02 -2.40054190e-02 9.40351703e-17
0.00000000e+00 5.48184665e-02 4.37742048e-02 -1.37938157e-02 -3.65468438e-03 0.00000000e+00];
bdes = [-0.0691808 -0.01045375];
Aeq = [ 0. -0.18543256 -0.14807351 0.04665987 0.01236258 0];
beq = 0.03536153;
u = quadprog(H, f, Ades, bdes, Aeq, beq, [], [], [])
Returns:
Minimum found that satisfies the constraints.
Optimization completed because the objective function is non-decreasing in
feasible directions, to within the default value of the optimality tolerance,
and constraints are satisfied to within the default value of the constraint tolerance.
<stopping criteria details>
u =
0.0709
0.0142
-0.5454
-0.8770
-0.1493
0.2050
Cheers!
when I used pip to install, I got this error:
Building wheels for collected packages: quadprog
Building wheel for quadprog (setup.py) ... error
ERROR: Command errored out with exit status 1:
command: 'd:\users\hp\anaconda3\envs\ccjpython\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\hp\\AppData\\Local\\Temp\\pip-install-3jm_slw_\\quadprog\\setup.py'"'"'; __file__='"'"'C:\\Users\\hp\\AppData\\Local\\Temp\\pip-install-3jm_slw_\\quadprog\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d 'C:\Users\hp\AppData\Local\Temp\pip-wheel-2_vknjs3'
cwd: C:\Users\hp\AppData\Local\Temp\pip-install-3jm_slw_\quadprog\
Complete output (4 lines):
running bdist_wheel
running build
running build_ext
error: [WinError 2] The system cannot find the file specified
ERROR: Failed building wheel for quadprog
Running setup.py clean for quadprog
Failed to build quadprog
Installing collected packages: quadprog, qpsolvers
Running setup.py install for quadprog ... error
ERROR: Command errored out with exit status 1:
command: 'd:\users\hp\anaconda3\envs\ccjpython\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\hp\\AppData\\Local\\Temp\\pip-install-3jm_slw_\\quadprog\\setup.py'"'"'; __file__='"'"'C:\\Users\\hp\\AppData\\Local\\Temp\\pip-install-3jm_slw_\\quadprog\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\hp\AppData\Local\Temp\pip-record-8xy1v0mt\install-record.txt' --single-version-externally-managed --compile --install-headers 'd:\users\hp\anaconda3\envs\ccjpython\Include\quadprog'
cwd: C:\Users\hp\AppData\Local\Temp\pip-install-3jm_slw_\quadprog\
Complete output (4 lines):
running install
running build
running build_ext
error: [WinError 2] The system cannot find the file specified
----------------------------------------
ERROR: Command errored out with exit status 1: 'd:\users\hp\anaconda3\envs\ccjpython\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\hp\\AppData\\Local\\Temp\\pip-install-3jm_slw_\\quadprog\\setup.py'"'"'; __file__='"'"'C:\\Users\\hp\\AppData\\Local\\Temp\\pip-install-3jm_slw_\\quadprog\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\hp\AppData\Local\Temp\pip-record-8xy1v0mt\install-record.txt' --single-version-externally-managed --compile --install-headers 'd:\users\hp\anaconda3\envs\ccjpython\Include\quadprog' Check the logs for full command output.
FAIL: test_all_shapes_scs (tests.test_solve_qp.TestSolveQP)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/frankd/src/qpsolvers/tests/test_solve_qp.py", line 313, in test
self.assertLess(
AssertionError: 1.0663684961909983 not less than 0.0002 : Solver failed on parameters: {'P': (3, 3), 'q': (3,), 'lb': (3,), 'ub': 'None'}
This issue is related to the decision at bodono/scs-python#63 (comment)
Hi all! I just wanted to ping re: quadprog/quadprog#13 that I'm looking for new maintainers to take over quadprog
. Perhaps some of the people involved in this repository would be interested in that role, so I wanted to give you a heads up.
Hi I want do use a Support Vector Machine for a Linear Separable Dataset.
I've already managed to solve it with matlab and the quadprog() function.
Now what I've done is just translate the exact same code to python to be able to solve it on my google colab notebook.
Unfortunately Im getting two errors:
ValueError Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/qpsolvers/quadprog_.py in quadprog_solve_qp(P, q, G, h, A, b, initvals, verbose)
87 try:
---> 88 return solve_qp(qp_G, qp_a, qp_C, qp_b, meq)[0]
89 except ValueError as e:
quadprog/quadprog.pyx in quadprog.solve_qp()
ValueError: matrix G is not positive definite
During handling of the above exception, another exception occurred:
TypeError Traceback (most recent call last)
2 frames
<ipython-input-57-fef196ccfda0> in <module>()
23 print('b\n')
24 print(b)
---> 25 v = solve_qp(H,f,A,b)
/usr/local/lib/python3.6/dist-packages/qpsolvers/__init__.py in solve_qp(P, q, G, h, A, b, lb, ub, solver, initvals, sym_proj, verbose, **kwargs)
260 return qpoases_solve_qp(*args, **kwargs)
261 elif solver == 'quadprog':
--> 262 return quadprog_solve_qp(*args, **kwargs)
263 raise Exception("solver '%s' not recognized" % solver)
264
/usr/local/lib/python3.6/dist-packages/qpsolvers/quadprog_.py in quadprog_solve_qp(P, q, G, h, A, b, initvals, verbose)
88 return solve_qp(qp_G, qp_a, qp_C, qp_b, meq)[0]
89 except ValueError as e:
---> 90 if "matrix G is not positive definite" in e:
91 # quadprog writes G the cost matrix that we write P in this package
92 raise ValueError("matrix P is not positive definite")
TypeError: argument of type 'ValueError' is not iterable
Here is the colab link:
https://colab.research.google.com/drive/10ILReXmCO0JNBKS5SuEZouXB55VyiDnE?usp=sharing
I've added also the working matlab code at the bottom of the notebook so that you can see that its just a one by one translation of the code. I cant figure out why its not working with python since it works perfectly on matlab.
If you look at the matlab documentation for quadprog() it seems its used the same way as the solve_qp() function here:
https://de.mathworks.com/help/optim/ug/quadprog.html
I hope you can help me. I know that this issue might not be a bug but rather a user error
Once they have found a good QP solver for their application, users often import internal <solver>_solve_qp
functions directly (avoiding the key lookup indirection of solve_qp
). If they have box inequality constraints, they then need to reformulate them manually, e.g. by calling the internal concatenate_bounds
function.
Let's refactor the internal function calls as follows:
lb
and ub
kwargs are handled in solve_qp
lb
and ub
kwargsOn a side note, this refactoring is also in preparation for #76.
Hey Stéphane,
passing a dictionary like {"ABSTOL": 1e-5, "RELTOL": 1e-5}
as options when using solver='qpswift'
throws TypeError: absolute tolerance must be between 0 and 1, using default value
, although the tolerance is set in this interval.
The problem only occurs with ABSTOL
, not with RELTOL
.
It seems like there is a small bug with checking the range of ABSTOL
.
Thanks!
Yannik
Howdy,
For a lot of my work, I usually need additional aspects of the solution in addition to the optimal point, such as the active set, and dual variables.
I was wondering if there was any appetite to add something of the following nature as an optional return from the solve function? Such as a keyword arg to export a SolverOutput object instead of the optimal point? I have implementations for gurobi and quadprog in a separate project.
@dataclass
class SolverOutput:
"""
This is the generic Solver information object. This will be the general return object from all of the back end \\
solvers. This was done to remove the need for the user to specialize IO for any particular Solver. It contains\\
all of the information you would need for the optimization solution including, optimal value, optimal solution, the \\
active set, the value of the slack variables, and the Lagrange multipliers associated with every constraint (these are listed)\\
as the dual variables.
Members:
obj: objective value of the optimal solution \n
sol: x*, numpy array \n
Optional Parameters -> None or numpy.ndarray type
slack: the slacks associated with every constraint \n
equality_indices: the active set of the solution, including strongly and weakly active constraints \n
dual: the lagrange multipliers associated with the problem\n
"""
obj: float
sol: numpy.ndarray
slack: Optional[numpy.ndarray]
active_set: Optional[numpy.ndarray]
dual: Optional[numpy.ndarray]
The code added in 469da9b from #50 (comment) should be covered by unit tests:
P
is not definiteq
has some component in the nullspace of P
During the setup of the OSQP solver in osqp_.py
user-supplied kwargs
are overwritten by:
kwargs = {
"eps_abs": eps_abs,
"eps_rel": eps_rel,
"polish": polish,
"verbose": verbose,
}
It would be preferably to update the user-supplied arguments using kwargs.update({...})
Hello, I got a fatal error when installing qpsolvers using "pip install qpsolvers" having downloaded and installed Microsoft Visual Studio Community 2018 using Python environment including CMaker, MSBuild etc. This is the error message:
" running build_ext
-- Selecting Windows SDK version to target Windows 10.0.19043.
CMake Error at CMakeLists.txt:4 (project):
Failed to run MSBuild command:
MSBuild.exe
to get the value of VCTargetsPath:
The system cannot find the file specified.
cl : Command line warning D9002 : ignoring unknown option '-std=c++11'
qdldl.cpp
c\qdldl/include/qdldl.h(5): fatal error C1083: Cannot open include file: 'qdldl_types.h': No such file or directory
error: command 'C:\Program Files\Microsoft Visual "
After looking into the error messages, I tried to download SDK version to target Windows 10.0.19043. But, Windows SDK 10.0.19043 is not available for download. Windows SDK 10.0.19041 is already installed.
How can I select SDK to target Windows SDK 10.0.19041 instead?
Where else can I install Windows SDK 10.0.19043?
What is this unknown option about: cl : Command line warning D9002 : ignoring unknown option '-std=c++11'?
Why is this file: 'qdldl_types.h' missing causing a fatal error C1083?
I'm trying to use the qpOASES interface, in which I see this note
Note
----
This function relies on some updates from the standard distribution of
qpOASES (details below). A fully compatible repository is published at
<https://github.com/stephane-caron/qpOASES>.
The link there is broken however, and the current qpOASES 3.2.1 official Python interface is also broken.
HiGHS can solve convex quadratic programs, and has Python bindings.
It would be great to add it to qpsolvers.
Seems like there is a problem in passing None matrices to some solvers, for example
this works
from qpsolvers import solve_qp
#maybe solve_safer_qp needs checking, no idea on this one
solve_qp(np.eye(10), np.ones(10), solver='quadprog') # it works only in master though, not in the pypi release as it was fixed afterwards)
solve_qp(np.eye(10), np.ones(10), solver='ecos')
this does not
solve_qp(np.eye(10), np.ones(10), solver='osqp')
---------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-1977-b6d562d21732> in <module>()
1 solve_qp(np.eye(10), np.ones(10), solver='quadprog')
----> 2 solve_qp(np.eye(10), np.ones(10), solver='osqp')
3 solve_qp(np.eye(10), np.ones(10), solver='ecos')
~/anaconda3/lib/python3.5/site-packages/qpsolvers/__init__.py in solve_qp(P, q, G, h, A, b, solver, initvals, sym_proj)
168 return mosek_solve_qp(P, q, G, h, A, b, initvals=initvals)
169 elif solver == 'osqp':
--> 170 return osqp_solve_qp(P, q, G, h, A, b, initvals=initvals)
171 elif solver == 'qpoases':
172 return qpoases_solve_qp(P, q, G, h, A, b, initvals=initvals)
~/anaconda3/lib/python3.5/site-packages/qpsolvers/osqp_.py in osqp_solve_qp(P, q, G, h, A, b, initvals)
74 <https://github.com/oxfordcontrol/osqp/issues/10>`_ in your solutions.
75 """
---> 76 l = -inf * ones(len(h))
77 if type(P) is ndarray:
78 warn(conversion_warning("P"))
TypeError: object of type 'NoneType' has no len()
Looks like it is due to this line
Because we never initialize h, the inner wrapper function should probably do it
This issue tracks box constraint support for all solvers interfaced by qpsolvers.
Solver | Keyword | Supports box constraints? | qpsolvers interface is complete? |
---|---|---|---|
CVXOPT | cvxopt |
No | ✔️ |
ECOS | ecos |
No | ✔️ |
Gurobi | gurobi |
Yes | ✔️ |
HiGHS | highs |
Yes | ✔️ |
MOSEK | mosek |
No | ✔️ |
OSQP | osqp |
Yes | ✔️ |
ProxQP | proxqp |
Yes | ✔️ |
qpOASES | qpoases |
Yes | ✔️ |
qpSWIFT | qpswift |
No | ✔️ |
quadprog | quadprog |
No | ✔️ |
SCS | scs |
Yes | ✔️ |
Solvers marked as ❌ are those that support box constraints, yet for which we are still doing a linear_from_box_inequalities
conversion.
Contributions are welcome for turning these ❌ into ✔️, one solver at a time 🙂
I got a very huge matrix P which has 10k+ dimentions.
The solving process takes a lot of time for cvxopt and any other solvers.
So, do I have any way to accelerate the solving process?
Another question is:
when using the default solver with a large matrix P(since it has a vary high dim,determinant of P is very close to zero, e.g. 5..e-324. when increasing the dimension of P, the determinant of P is 0.0, but it is not, the precision of numpy double reachs to the limit), I got the error "G is not a positive definite matrix", while cvxopt does not report this error.
Hi Stephane! I very much enjoy your package.
I found that lb and ub only work with dense matrices. For these inequality constraints, the concatenate function of NumPy is used. This returns a np.ndarray, which in my case is way too large to fit into memory.
Would you consider adding 'vstack' from the SciPy.sparse library instead to solve this problem? E.g. in file __init__.py
:
if lb is not None:
if G is None:
G = -eye(len(q))
h = -lb
else: # G is not None and h is not None
if type(G) is ndarray:
G = concatenate((G, -eye(len(q))), 0)
else:
from scipy import sparse
G = sparse.vstack([G, -sparse.eye(len(q))])
h = concatenate((h, -lb))
if ub is not None:
if G is None:
G = eye(len(q))
h = ub
else: # G is not None and h is not None
if type(G) is ndarray:
G = concatenate((G, eye(len(q))), 0)
else:
from scipy import sparse
G = sparse.vstack([G, -sparse.eye(len(q))])
h = concatenate((h, ub))
Thank you in advance for your consideration!
If you'd prefer, I can make a pr. I did not consider cvxopt.spmatrix.
See #76
Does this library support solving qps in batch? E.g. see this post: https://stackoverflow.com/questions/73076452/solving-many-convex-programs-in-parallel
From @bodono in bodono/scs-python#63 (comment):
Another point is how to restore from the box cone formulation to the original problem when running SCS. This is a minor point, but I wonder if you are dividing by the t scalar variable at termination? I think it's typically better to do that. The box cone is {t * l <= s <= t *u} and we add the constraint that t=1, but if at termination t != 1 then you might need to divide by whatever t is to get a solution that satisfies the conic constraint.
Following the new shapes added to test_all_shapes
in 65c50e2, it seems quadprog
fails when lb
is set but not ub
:
Baseline failed on parameters: {
'P': (3, 3), 'q': (3,),
'G': (3, 3), 'h': (3,),
'A': (2, 3), 'b': (2,),
'lb': (3,), 'ub': 'None',
}
Failed pipeline: https://github.com/stephane-caron/qpsolvers/actions/runs/2972334067
Hello,
Installing quadprog is a pain for some users that cannot use anaconda or build its package because it requires a compiler.
I proposed a PR to quadprog to build the wheel packages, but none of the maintainers reacted since October 2021.
So I've just pushed the wheels to pypi under the distribution name quadprog-wheel, the package name remains quadprog
.
This means that installing it is done with pip install quadprog-wheel
but importing it is still import quadprog
.
Would it be possible for qpsolvers to provide the ability to (optionally?) install quadprog-wheel instead of quadprog?
Cheers.
I'm seeing a name collision when using the osqp solver with this package. Specifically, accessing osqp.constant fails because osqp refers to both the module name and the initialized osqp solver object.
In osqp_.py:
from osqp import OSQP
and
osqp = OSQP()
leads to the above conflict. I'm working on a pull request now that removes the collision.
When adding proxsuite
to the test environment in tox.ini
, all shape tests fail simultaneously:
======================================================================
FAIL: test_all_shapes_cvxopt (tests.test_solve_qp.TestSolveQP)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/.../src/qpsolvers/tests/test_solve_qp.py", line 247, in test
self.assertLess(norm(x - quadprog_solution), 2e-4)
AssertionError: 0.00021352703614369313 not less than 0.0002
======================================================================
FAIL: test_all_shapes_cvxpy (tests.test_solve_qp.TestSolveQP)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/.../src/qpsolvers/tests/test_solve_qp.py", line 247, in test
self.assertLess(norm(x - quadprog_solution), 2e-4)
AssertionError: 456.17143090559387 not less than 0.0002
======================================================================
FAIL: test_all_shapes_ecos (tests.test_solve_qp.TestSolveQP)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/.../src/qpsolvers/tests/test_solve_qp.py", line 247, in test
self.assertLess(norm(x - quadprog_solution), 2e-4)
AssertionError: 151.09703206141177 not less than 0.0002
======================================================================
FAIL: test_all_shapes_osqp (tests.test_solve_qp.TestSolveQP)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/.../src/qpsolvers/tests/test_solve_qp.py", line 247, in test
self.assertLess(norm(x - quadprog_solution), 2e-4)
AssertionError: 0.00021352703614369313 not less than 0.0002
======================================================================
FAIL: test_all_shapes_proxqp (tests.test_solve_qp.TestSolveQP)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/.../src/qpsolvers/tests/test_solve_qp.py", line 247, in test
self.assertLess(norm(x - quadprog_solution), 2e-4)
AssertionError: inf not less than 0.0002
======================================================================
FAIL: test_all_shapes_quadprog (tests.test_solve_qp.TestSolveQP)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/.../src/qpsolvers/tests/test_solve_qp.py", line 247, in test
self.assertLess(norm(x - quadprog_solution), 2e-4)
AssertionError: 89.28461058122137 not less than 0.0002
======================================================================
FAIL: test_all_shapes_scs (tests.test_solve_qp.TestSolveQP)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/.../src/qpsolvers/tests/test_solve_qp.py", line 247, in test
self.assertLess(norm(x - quadprog_solution), 2e-4)
AssertionError: 0.7159031647958832 not less than 0.0002
----------------------------------------------------------------------
Ran 19 tests in 0.270s
Hi, I have a problem about setting the box bounds
I saw the related issue, and know that I can use the trick -Gx<-h
However, the api only allow one G matrix to pass, but I want to bound x using -G1x<h1, G2x<h2
I don't know how to do this.(I want to implement -1<x<1 )
I also saw that gpoases support for the case. However, when I run:
"x = solve_qp(p,q,G,h,A,b,solver='qpoases')"
it tell me:
"ImportError: qpOASES not found"
hi,
I am trying to use your code as interface to test my optimization problem with mutli qp solvers.
From your code I can see that it supports the following problem
minimize (1/2) * x.T * P * x + q.T * x
subject to
G * x <= h
A * x == b
where you set the h vector as upper limit for matrix G, but I have a problem of following format,
minimize (1/2) * x.T * P * x + q.T * x
subject to
l <= G * x <= h
A * x == b
with lx<= x <= ux
Can you please add the functionality to support the lower limit vector for the G matrix. Also lower and upper bounds for x.
Currently ProxQP fails on benchmark_model_predictive_control.py
after updating to 0.2.2.
Possibly related to the API update from Simple-Robotics/proxsuite#39
Is there a way to set the verbosity mode in a more generic way?
If I use solve_qp(..., solver=cvxopt)
I can do that as:
qp_solvers.cvxopt_.options['show_progress'] = True
and for the other solvers? I wish I could manage verbosity independently of the type of solver.
Tip: wouldn't it be better to add a verbose parameter to the solve_qp
method?
Using exactly the example of the README gives
ValueError: constraints are inconsistent, no solution
This is with Python 3.6
Hello,
Thanks for maintaining this nice repo!
I just find one example that the quadprog
solver is stuck in the infinite loop.
Here, I am attaching the zip file for the example problem.
The latest qpsolvers installation (pip3 install qpsolvers
) installs the quadprog
(version 0.1.10).
With this, when I run python3 main.py
, it goes into infinite loop.
However, if I run it with cvxopt
(version 1.2.7) after installing it by (pip3 install cvxopt
), it gives a solution.
I also found that the older version of quadprog
(version 0.1.8) is able to solve the same problem, and the solution is very close to the solution achieved from cvxopt.
It looks like an issue regarding the quadprog
package, and my apologies if I am leaving an issue in the wrong place.
Hello, I have problem with solve_qp when I want to run the following code:
from qpsolvers import solve_qp
P = np.array([4.,5.,5.,8.]).reshape(2,2)
q = np.array([-3.,2.]).reshape(1,2)[0]
G = np.array([1,1,-2,-3,1,0,0,1,-1,0,0,-1]).reshape(6,2)
h = np.array([2400.,-1100.,1200.,1500.,-300.,0.])
A = None
b = None
sol = solve_qp(P,q,G,h,A,b,solver='quadprog')
I got this error:
sol = solve_qp(P,q,G,h,A,b,solver='quadprog')
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/qpsolvers/init.py", line 262, in solve_qp
return quadprog_solve_qp(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/qpsolvers/quadprog_.py", line 90, in quadprog_solve_qp
if "matrix G is not positive definite" in e:
TypeError: argument of type 'ValueError' is not iterable
It seems warm-start is possible ERGO-Code/HiGHS#617
Hi,
I am trying to install qpsolvers in a python3 environment and I get the following error. Would you have any advice on how to address this issue?
Thanks
Damoeñ
$ sudo python3 -m pip install qpsolvers --no-cache-dir
Collecting qpsolvers
Downloading qpsolvers-1.4.tar.gz (10 kB)
Collecting quadprog
Downloading quadprog-0.1.7.tar.gz (18 kB)
Requirement already satisfied: Cython in /usr/local/lib/python3.6/dist-packages (from quadprog->qpsolvers) (0.29.21)
Building wheels for collected packages: qpsolvers, quadprog
Building wheel for qpsolvers (setup.py) ... done
Created wheel for qpsolvers: filename=qpsolvers-1.4-py3-none-any.whl size=20203 sha256=10aac2030cff0078fb710f137d673be6f1168e46af4e64f6c255f616cc5a0cea
Stored in directory: /tmp/pip-ephem-wheel-cache-4n80r92m/wheels/11/d4/29/418e4c67e64a47d93c0311f5ad18484ed23778bfa2fc0e4154
Building wheel for quadprog (setup.py) ... error
ERROR: Command errored out with exit status 1:
command: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-x94moz4w/quadprog/setup.py'"'"'; __file__='"'"'/tmp/pip-install-x94moz4w/quadprog/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-0ksn9k8i
cwd: /tmp/pip-install-x94moz4w/quadprog/
Complete output (14 lines):
running bdist_wheel
running build
running build_ext
cythoning quadprog/quadprog.pyx to quadprog/quadprog.cpp
/usr/local/lib/python3.6/dist-packages/Cython/Compiler/Main.py:369: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: /tmp/pip-install-x94moz4w/quadprog/quadprog/quadprog.pyx
tree = Parsing.p_module(s, pxd, full_module_name)
building 'quadprog' extension
creating build
creating build/temp.linux-x86_64-3.6
creating build/temp.linux-x86_64-3.6/quadprog
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -Iquadprog -I/usr/include/python3.6m -c quadprog/quadprog.cpp -o build/temp.linux-x86_64-3.6/quadprog/quadprog.o
quadprog/quadprog.cpp:4:20: fatal error: Python.h: No such file or directory
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
----------------------------------------
ERROR: Failed building wheel for quadprog
Running setup.py clean for quadprog
Successfully built qpsolvers
Failed to build quadprog
DEPRECATION: Could not build wheels for quadprog which do not use PEP 517. pip will fall back to legacy 'setup.py install' for these. pip 21.0 will remove support for this functionality. A possible replacement is to fix the wheel build issue reported above. You can find discussion regarding this at https://github.com/pypa/pip/issues/8368.
Installing collected packages: quadprog, qpsolvers
Running setup.py install for quadprog ... error
ERROR: Command errored out with exit status 1:
command: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-x94moz4w/quadprog/setup.py'"'"'; __file__='"'"'/tmp/pip-install-x94moz4w/quadprog/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-zjsaublq/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3.6/quadprog
cwd: /tmp/pip-install-x94moz4w/quadprog/
Complete output (12 lines):
running install
running build
running build_ext
skipping 'quadprog/quadprog.cpp' Cython extension (up-to-date)
building 'quadprog' extension
creating build
creating build/temp.linux-x86_64-3.6
creating build/temp.linux-x86_64-3.6/quadprog
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -Iquadprog -I/usr/include/python3.6m -c quadprog/quadprog.cpp -o build/temp.linux-x86_64-3.6/quadprog/quadprog.o
quadprog/quadprog.cpp:4:20: fatal error: Python.h: No such file or directory
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
----------------------------------------
ERROR: Command errored out with exit status 1: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-x94moz4w/quadprog/setup.py'"'"'; __file__='"'"'/tmp/pip-install-x94moz4w/quadprog/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-zjsaublq/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3.6/quadprog Check the logs for full command output.
Hi,
I understand this is not a very major issue. In the benchmarks shown for dense problems, the time taken for ecos, gurobi and mosek solvers are of the order of few milliseconds (2.61, 0.84 and 7.17). I find it difficult to believe considering the solvers are state-of-the-art and the problem itself is very small (only 3-dimensional). Is it because you have not turned off the VERBOSE flags or selected appropriate options for each solver
A small run in Matlab with ecos tells me that if I enable VERBOSE options 'on', the time taken is around 2 ms as reported in your benchmark, and around 0.08 ms if the VERBOSE option is turned off. I was just wondering if the benchmark test is doing a fair job in comparing all the solvers.
Traceback (most recent call last):
File "C:\Program Files\ChimeraX 1.1\bin\lib\site-packages\chimerax\toolshed_utils_init_.py", line 489, in _pip_install
results = _run_pip(command, logger)File "C:\Program Files\ChimeraX 1.1\bin\lib\site-packages\chimerax\toolshed_utils_init_.py", line 540, in _run_pip
raise RuntimeError(s)
RuntimeError: Looking in indexes: https://pypi.org/simple, https://cxtoolshed.rbvi.ucsf.edu/pypi/
Processing z:\plugin_dl\dist\chimerax_dlstruct-0.1-py3-none-any.whl
Requirement already satisfied: ChimeraX-Core~=1.0 in c:\program files\chimerax 1.1\bin\lib\site-packages (from ChimeraX-DLStruct==0.1) (1.1)
Requirement already satisfied: numpy~=1.16.4 in c:\users\ymu\appdata\local\ucsf\chimerax\1.1\site-packages (from ChimeraX-DLStruct==0.1) (1.16.6)
Requirement already satisfied: torch~=1.7.1 in c:\users\ymu\appdata\local\ucsf\chimerax\1.1\site-packages (from ChimeraX-DLStruct==0.1) (1.7.1)
Requirement already satisfied: numpy~=1.16.4 in c:\users\ymu\appdata\local\ucsf\chimerax\1.1\site-packages (from ChimeraX-DLStruct==0.1) (1.16.6)
Requirement already satisfied: typing-extensions in c:\users\ymu\appdata\local\ucsf\chimerax\1.1\site-packages (from torch~=1.7.1->ChimeraX-DLStruct==0.1) (3.7.4.3)
Collecting quadprog~=0.1.7
Using cached quadprog-0.1.8.tar.gz (269 kB)
Requirement already satisfied: Cython in c:\program files\chimerax 1.1\bin\lib\site-packages (from quadprog~=0.1.7->ChimeraX-DLStruct==0.1) (0.29.20)
Collecting importlib-metadata~=0.17
Using cached importlib_metadata-0.23-py2.py3-none-any.whl (28 kB)
Requirement already satisfied: zipp>=0.5 in c:\users\ymu\appdata\local\ucsf\chimerax\1.1\site-packages (from importlib-metadata~=0.17->ChimeraX-DLStruct==0.1) (3.4.1)
Building wheels for collected packages: quadprog
Building wheel for quadprog (setup.py): started
Building wheel for quadprog (setup.py): finished with status 'error'
Running setup.py clean for quadprog
Failed to build quadprog
Installing collected packages: quadprog, importlib-metadata, ChimeraX-DLStruct
Running setup.py install for quadprog: started
Running setup.py install for quadprog: finished with status 'error'
ERROR: Command errored out with exit status 1:
command: 'C:\Program Files\ChimeraX 1.1\bin\ChimeraX.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\ymu\AppData\Local\Temp\pip-install-xakoctiw\quadprog_7cb25d8bb3904ea3b64643e58389ec80\setup.py'"'"'; file='"'"'C:\Users\ymu\AppData\Local\Temp\pip-install-xakoctiw\quadprog_7cb25d8bb3904ea3b64643e58389ec80\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' bdist_wheel -d 'C:\Users\ymu\AppData\Local\Temp\pip-wheel-gloxcthl'
cwd: C:\Users\ymu\AppData\Local\Temp\pip-install-xakoctiw\quadprog_7cb25d8bb3904ea3b64643e58389ec80\
Complete output (6 lines):
running bdist_wheel
running build
running build_ext
skipping 'quadprog\quadprog.cpp' Cython extension (up-to-date)
building 'quadprog' extension
error: Microsoft Visual C++ 14.0 is required. Get it with "Build Tools for Visual Studio": https://visualstudio.microsoft.com/downloads/
ERROR: Command errored out with exit status 1: 'C:\Program Files\ChimeraX 1.1\bin\ChimeraX.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\ymu\AppData\Local\Temp\pip-install-xakoctiw\quadprog_7cb25d8bb3904ea3b64643e58389ec80\setup.py'"'"'; file='"'"'C:\Users\ymu\AppData\Local\Temp\pip-install-xakoctiw\quadprog_7cb25d8bb3904ea3b64643e58389ec80\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' install --record 'C:\Users\ymu\AppData\Local\Temp\pip-record-gcrsp7lk\install-record.txt' --single-version-externally-managed --user --prefix= --compile --install-headers 'C:\Users\ymu\AppData\Local\UCSF\ChimeraX\Python37\Include\quadprog' Check the logs for full command output.
WARNING: You are using pip version 20.2.2; however, version 21.0.1 is available.
You should consider upgrading via the 'C:\Program Files\ChimeraX 1.1\bin\ChimeraX.exe -m pip install --upgrade pip' command.
See #76
Hi,
I am getting an error called "ValueError: Buffer has wrong number of dimensions (expected 1, got 2). I don't think there is anything wrong in the way I am declaring my QP. Do you think I am missing something really minor?
Thanks a lot!
Best,
Mohit
Details: bodono/scs-python#36 (comment)
The CI fails with the following error:
distutils.errors.DistutilsOptionError: No configuration found for dynamic 'description'.
Some dynamic fields need to be specified via `tool.setuptools.dynamic`
others must be specified via the equivalent attribute in `setup.py`.
[end of output]
Usually x is column vector, q^T x should requires q is column vector? (same question for h)
But from the example it looks not.
Thanks
With Gurobi's 9.0 update, they have included a matrix API that is much faster. It lets you add the entire constraint set in one go. I have an example implementation that I could contribute here. In my experience, this drops the overhead to the solver drastically.
The solver qpmad looks promising for inclusion. It implements the Goldfarb-Idnani method, and seems to work faster than others (e.g. qpOASES) with dense inputs. There's an R wrapper for it too: https://github.com/anderic1/qpmadr
On the repository page it says that sparse solvers include CVXPY and MOSEK.
But CVXPY isn't a solver, it's a modeling language. What is meant by using CVXPY as a solver?
Also, MOSEK is a sparse solver in general, but unfortunately not for QP's. MOSEK's documentation indicates that QP's are transformed to equivalent SOCP representations, and this transformation will inevitably destroy sparsity in the quadratic terms. Just point this out to explain why MOSEK performed so poorly on the sparse QP's.
After pushing some doc commits today I noticed the CI fails:
FAIL: test_sparse_bounds_scs (tests.test_solve_qp.TestSolveQP)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/runner/work/qpsolvers/qpsolvers/tests/test_solve_qp.py", line 430, in test
self.assertLess(norm(x - known_solution), sol_tolerance)
AssertionError: 1.3095214160904062e-08 not less than 1e-08
When I run tests locally with SCS 3.0.1 all tests pass, but after upgrading to 3.2.0 I see the same errors locally.
@bodono FYI, maybe some defaults changed between 3.0 and 3.2?
The absolute drift is not huge, we can probably set laxer precision settings for SCS so that the CI passes again.
Users can be confused when they pip-install qpsolvers without optional dependencies, import it, and find an empty list of available solvers.
Instead, detect this case and raise an import error to guide them into installing solvers.
The title says it all. This issue seems to have arisen with the newest version of qpsolvers. I'm running this on MacOS 10.15.7, with Python 3.9.7 and qpsolvers 1.7.0 - let me know if you'd like any more information.
I would also like to point out this issue is relevant to me because I help maintain the package pytwoway which uses qpsolvers as a dependency (and I have to send lots of thanks for the package! It is excellent). I will need to update pytwoway's dependencies to either use an older version of qpsolvers or to additionally include cvxopt if it will no longer be included by default in qpsolvers.
This is the output when I try to run
from qpsolvers import solve_qp
without cvxopt
installed (it's the same output for solve_ls
instead of solve_qp
):
In [1]: from qpsolvers import solve_qp
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-2-b46fa005102a> in <module>
----> 1 from qpsolvers import solve_qp
~/opt/anaconda3/envs/temp-env2/lib/python3.9/site-packages/qpsolvers/__init__.py in <module>
21 """Quadratic programming solvers in Python with a unified API"""
22
---> 23 from .solve_ls import solve_ls
24 from .solve_qp import solve_qp
25 from .solve_qp import solve_safer_qp
~/opt/anaconda3/envs/temp-env2/lib/python3.9/site-packages/qpsolvers/solve_ls.py in <module>
27 from numpy import dot, ndarray
28
---> 29 from .solve_qp import solve_qp
30 from .typing import Matrix, Vector
31
~/opt/anaconda3/envs/temp-env2/lib/python3.9/site-packages/qpsolvers/solve_qp.py in <module>
28
29 from .check_problem_constraints import check_problem_constraints
---> 30 from .concatenate_bounds import concatenate_bounds
31 from .exceptions import SolverNotFound
32 from .solvers import dense_solvers
~/opt/anaconda3/envs/temp-env2/lib/python3.9/site-packages/qpsolvers/concatenate_bounds.py in <module>
23 from typing import Optional, Tuple
24
---> 25 import cvxopt
26 import numpy as np
27
ModuleNotFoundError: No module named 'cvxopt'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.