Coder Social home page Coder Social logo

qpsolvers / qpsolvers Goto Github PK

View Code? Open in Web Editor NEW
527.0 14.0 81.0 5.53 MB

Quadratic programming solvers in Python with a unified API

License: GNU Lesser General Public License v3.0

Python 100.00%
solver python numerical-optimization quadratic-programming optimization

qpsolvers's Introduction

Quadratic Programming Solvers in Python

Build Documentation Coverage PyPI version PyPI downloads

This library provides a one-stop shop solve_qp function to solve convex quadratic programs:

$$ \begin{split} \begin{array}{ll} \underset{x}{\mbox{minimize}} & \frac{1}{2} x^T P x + q^T x \\ \mbox{subject to} & G x \leq h \\ & A x = b \\ & lb \leq x \leq ub \end{array} \end{split} $$

Vector inequalities apply coordinate by coordinate. The function returns the primal solution $x^*$ found by the backend QP solver, or None in case of failure/unfeasible problem. All solvers require the problem to be convex, meaning the matrix $P$ should be positive semi-definite. Some solvers further require the problem to be strictly convex, meaning $P$ should be positive definite.

Dual multipliers: there is also a solve_problem function that returns not only the primal solution, but also its dual multipliers and all other relevant quantities computed by the backend solver.

Example

To solve a quadratic program, build the matrices that define it and call solve_qp, selecting the backend QP solver via the solver keyword argument:

import numpy as np
from qpsolvers import solve_qp

M = np.array([[1.0, 2.0, 0.0], [-8.0, 3.0, 2.0], [0.0, 1.0, 1.0]])
P = M.T @ M  # this is a positive definite matrix
q = np.array([3.0, 2.0, 3.0]) @ M
G = np.array([[1.0, 2.0, 1.0], [2.0, 0.0, 1.0], [-1.0, 2.0, -1.0]])
h = np.array([3.0, 2.0, -2.0])
A = np.array([1.0, 1.0, 1.0])
b = np.array([1.0])

x = solve_qp(P, q, G, h, A, b, solver="proxqp")
print(f"QP solution: {x = }")

This example outputs the solution [0.30769231, -0.69230769, 1.38461538]. It is also possible to get dual multipliers at the solution, as shown in this example.

Installation

PyPI

PyPI version

To install the library with open source QP solvers:

pip install qpsolvers[open_source_solvers]

This one-size-fits-all installation may not work immediately on all systems (for instance if a solver tries to compile from source). If you run into any issue, check out the following variants:

  • pip install qpsolvers[wheels_only] will only install solvers with pre-compiled binaries,
  • pip install qpsolvers[clarabel,daqp,proxqp,scs] (for instance) will install the listed set of QP solvers,
  • pip install qpsolvers will only install the library itself.

When imported, qpsolvers loads all the solvers it can find and lists them in qpsolvers.available_solvers.

Conda

Conda version

conda install -c conda-forge qpsolvers

Solvers

Solver Keyword Algorithm API License Warm-start
Clarabel clarabel Interior point Sparse Apache-2.0 ✖️
CVXOPT cvxopt Interior point Dense GPL-3.0 ✔️
DAQP daqp Active set Dense MIT ✖️
ECOS ecos Interior point Sparse GPL-3.0 ✖️
Gurobi gurobi Interior point Sparse Commercial ✖️
HiGHS highs Active set Sparse MIT ✖️
HPIPM hpipm Interior point Dense BSD-2-Clause ✔️
MOSEK mosek Interior point Sparse Commercial ✔️
NPPro nppro Active set Dense Commercial ✔️
OSQP osqp Augmented Lagrangian Sparse Apache-2.0 ✔️
PIQP piqp Proximal Interior Point Dense & Sparse BSD-2-Clause ✖️
ProxQP proxqp Augmented Lagrangian Dense & Sparse BSD-2-Clause ✔️
QPALM qpalm Augmented Lagrangian Sparse LGPL-3.0 ✔️
qpOASES qpoases Active set Dense LGPL-2.1
qpSWIFT qpswift Interior point Sparse GPL-3.0 ✖️
quadprog quadprog Active set Dense GPL-2.0 ✖️
SCS scs Augmented Lagrangian Sparse MIT ✔️

Matrix arguments are NumPy arrays for dense solvers and SciPy Compressed Sparse Column (CSC) matrices for sparse ones.

Frequently Asked Questions

Benchmark

The results below come from qpbenchmark, a benchmark for QP solvers in Python. In the following tables, solvers are called with their default settings and compared over whole test sets by shifted geometric mean ("shm" for short). Lower is better and 1.0 corresponds to the best solver.

Maros-Meszaros (hard problems)

Check out the full report for high- and low-accuracy solver settings.

Success rate (%) Runtime (shm) Primal residual (shm) Dual residual (shm) Duality gap (shm) Cost error (shm)
clarabel 89.9 1.0 1.0 1.9 1.0 1.0
cvxopt 53.6 13.8 5.3 2.6 22.9 6.6
gurobi 16.7 57.8 10.5 37.5 94.0 34.9
highs 53.6 11.3 5.3 2.6 21.2 6.1
osqp 41.3 1.8 58.7 22.6 1950.7 42.4
proxqp 77.5 4.6 2.0 1.0 11.5 2.2
scs 60.1 2.1 37.5 3.4 133.1 8.4

Maros-Meszaros dense (subset of dense problems)

Check out the full report for high- and low-accuracy solver settings.

Success rate (%) Runtime (shm) Primal residual (shm) Dual residual (shm) Duality gap (shm) Cost error (shm)
clarabel 100.0 1.0 1.0 78.4 1.0 1.0
cvxopt 66.1 1267.4 292269757.0 268292.6 269.1 72.5
daqp 50.0 4163.4 1056090169.5 491187.7 351.8 280.0
ecos 12.9 27499.0 996322577.2 938191.8 197.6 1493.3
gurobi 37.1 3511.4 497416073.4 13585671.6 4964.0 190.6
highs 64.5 1008.4 255341695.6 235041.8 396.2 54.5
osqp 51.6 371.7 5481100037.5 3631889.3 24185.1 618.4
proxqp 91.9 14.1 1184.3 1.0 71.8 7.2
qpoases 24.2 3916.0 8020840724.2 23288184.8 102.2 778.7
qpswift 25.8 16109.1 860033995.1 789471.9 170.4 875.0
quadprog 62.9 1430.6 315885538.2 4734021.7 2200.0 192.3
scs 72.6 95.6 2817718628.1 369300.9 3303.2 152.5

Citing qpsolvers

If you find this project useful, please consider giving it a ⭐ or citing it if your work is scientific:

@software{qpsolvers2024,
  author = {Caron, Stéphane and Arnström, Daniel and Bonagiri, Suraj and Dechaume, Antoine and Flowers, Nikolai and Heins, Adam and Ishikawa, Takuma and Kenefake, Dustin and Mazzamuto, Giacomo and Meoli, Donato and O'Donoghue, Brendan and Oppenheimer, Adam A. and Pandala, Abhishek and Quiroz Omaña, Juan José and Rontsis, Nikitas and Shah, Paarth and St-Jean, Samuel and Vitucci, Nicola and Wolfers, Soeren and Yang, Fengyu and @bdelhaisse and @MeindertHH and @rimaddo and @urob and @shaoanlu},
  license = {LGPL-3.0},
  month = mar,
  title = {{qpsolvers: Quadratic Programming Solvers in Python}},
  url = {https://github.com/qpsolvers/qpsolvers},
  version = {4.3.2},
  year = {2024}
}

Contributing

We welcome contributions! The first step is to install the library and use it. Report any bug in the issue tracker. If you're a developer looking to hack on open source, check out the contribution guidelines for suggestions.

We are also looking forward to hearing about your use cases! Please share them in Show and tell 🙌

qpsolvers's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

qpsolvers's Issues

Error when compiling qpsolvers in python3

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.

Additional solver output

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]

Box constraints for all solvers that support 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 🙂

Error: Microsoft Visual C++ 14.0 is required (compile in ChimeraX)

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.

Installation error

Hello

I am unable to install the package using pip or conda install, getting below error.

Tried installing 'wheel' and updated 'setuptools' but no use.

image

Any suggestion will be helpful.

Installation on Windows 10 with Microsoft Visual Studio

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?

Unit test fails after SCS 3.0 → 3.2 upgrade

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.

How can I set verbosity?

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?

Updating the Gurobi interface

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.

Issue with a quadprog (version 0.1.10)

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.

qp.zip

SCS solution issue one one-sided box inequalities

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)

Unable to figure out error (ValueError)

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

Shape tests failing when installing ProxSuite

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

Check when no solver is installed

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.

lb and ub make matrix G dense

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.

kwargs don't get passed to OSQP

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({...})

cvxopt was moved to an optional dependency but is still required

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'

Box constraints in internal solver functions

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:

  • Currently: lb and ub kwargs are handled in solve_qp
  • Goal: each internal solver function handles its own lb and ub kwargs

On a side note, this refactoring is also in preparation for #76.

Example does not work

Using exactly the example of the README gives

ValueError: constraints are inconsistent, no solution

This is with Python 3.6

OSQP import name collision

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.

Don't override default solver tolerances

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.

Error when setting the absolute tolerance of qpSWIFT

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

Problem about the hypercube bounds

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"

Is q a column vector?

image
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

Confusion regarding solver types on repo landing page

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.

ValueError and TypeError when using solve_qp

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

Broken link for qpOASES

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.

quadprog wheel package

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.

CI failure: dynamic description not working?

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]

TypeError: argument of type 'ValueError' is not iterable

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

Unexpected behavior using 'quadprog' and 'cvxopt' solvers

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!

Dense BenchMarks Comparison

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.

Installation error with Anaconda and Python 3 on Windows

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.

solver running time is too long

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.

Better handling of box cone solutions with SCS

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.

Use lower constraint vector fo G matrix

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.

Uninitialized matrices in OSQP causing a crash

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

https://github.com/stephane-caron/qpsolvers/blob/7d71cdfe5657ca098a4c6c9ff2b6627956d7631d/qpsolvers/osqp_.py#L76

Because we never initialize h, the inner wrapper function should probably do it

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.