Skip to main content

Quadratic programming solvers in Python with a unified API.

Project description

Quadratic Programming Solvers in Python

CI Documentation Coverage Conda version PyPI version PyPI downloads

This library provides a 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

From conda-forge

conda install -c conda-forge qpsolvers

From PyPI

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.

Solvers

Solver Keyword Algorithm API License
Clarabel clarabel Interior point Sparse Apache-2.0
COPT copt Interior point Sparse Commercial
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
jaxopt.OSQP jaxopt_osqp Augmented Lagrangian Dense Apache-2.0
KVXOPT kvxopt Interior point Dense & Sparse GPL-3.0
MOSEK mosek Interior point Sparse Commercial
NPPro nppro Active set Dense Commercial
OSQP osqp Augmented Lagrangian Sparse Apache-2.0
PDHCG pdhcg Primal-dual hybrid gradient Dense & 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
qpmad qpmad Active set Dense Apache-2.0
QTQP qtqp Interior point Sparse Apache-2.0
qpax qpax Interior point Dense MIT
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
SIP sip Barrier 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

QP solvers come with their strengths and weaknesses depending on the algorithmic choices they make. To help you find the ones most suited to your problems, you can check out the results from qpbenchmark, a benchmark for QP solvers in Python. The benchmark is divided into test sets, each test set representing a different distribution of quadratic programs with specific dimensions and structure (large sparse problems, optimal control problems, ...):

Citing qpsolvers

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

@software{qpsolvers,
  title = {{qpsolvers: Quadratic Programming Solvers in Python}},
  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 Otta, Pavel 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 Delhaisse, Brian and MeindertHH and rimaddo and urob and shaoanlu and Sandoval, Uriel and Khalil, Ahmed and Kozlov, Lev and Groudiev, Antoine and Sousa Pinto, João and Schwan, Roland and Budhiraja, Rohan and Keustermans, Johannes and Wu, Yubin and Li, Hongpei and Hoarau, Antoine},
  license = {LGPL-3.0},
  url = {https://github.com/qpsolvers/qpsolvers},
  version = {4.13.0},
  year = {2026}
}

Don't forget to add yourself to the BibTeX above and to CITATION.cff if you contribute to this repository.

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.

See also

  • qpbenchmark: Benchmark for quadratic programming solvers available in Python.
  • qpsolvers-eigen: C++ abstraction layer for quadratic programming solvers using Eigen.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

qpsolvers-4.13.0.tar.gz (77.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

qpsolvers-4.13.0-py3-none-any.whl (107.1 kB view details)

Uploaded Python 3

File details

Details for the file qpsolvers-4.13.0.tar.gz.

File metadata

  • Download URL: qpsolvers-4.13.0.tar.gz
  • Upload date:
  • Size: 77.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.32.4

File hashes

Hashes for qpsolvers-4.13.0.tar.gz
Algorithm Hash digest
SHA256 e86c4c16bf7c16fdbb8e6c0e4050bc1bfef72a25755211be66a492ac4c939a1c
MD5 7c3fbf6b26090af47d1e22d4d0d839a9
BLAKE2b-256 d1aa4d60a7065de30f07d7ead935eed364cf94fb0ad5607ddf1461f2bdf7ba17

See more details on using hashes here.

File details

Details for the file qpsolvers-4.13.0-py3-none-any.whl.

File metadata

  • Download URL: qpsolvers-4.13.0-py3-none-any.whl
  • Upload date:
  • Size: 107.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.32.4

File hashes

Hashes for qpsolvers-4.13.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7f23759a3d8835fa14b2c9eb4ba971188fde0c1460589f45897b00a75776eef7
MD5 889362c913849f9c9c3f4a9ce53fe970
BLAKE2b-256 2fd0f234961cb3ffbe381c3d82cd9c40fc7e67200c9f6b62a0f60235e74134b3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page