Package: qpsolvers
Quadratic Programming Solvers in PythonThis library provides a one-stop shopsolve_qpfunction 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, orNonein case of failure/unfeasible problem. All solvers require the problem to be convex, meaning the matrix $P$ should bepositive semi-definite. Some solvers further require the problem to be strictly convex, meaning $P$ should be positive definite.Dual multipliers:there is also asolve_problemfunction that returns not only the primal solution, but also its dual multipliers and all other relevant quantities computed by the backend solver.ExampleTo solve a quadratic program, build the matrices that define it and callsolve_qp, selecting the backend QP solver via thesolverkeyword argument:importnumpyasnpfromqpsolversimportsolve_qpM=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 matrixq=np.array([3.0,2.0,3.0])@MG=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 inthis example.InstallationPyPITo install the library with open source QP solvers:pip install qpsolvers[open_source_solvers]To install selected QP solvers, list them between brackets:pip install qpsolvers[clarabel,daqp,proxqp,scs]And to install only the library itself:pip install qpsolvers.When imported, qpsolvers loads all the solvers it can find and lists them inqpsolvers.available_solvers.Condaconda install -c conda-forge qpsolversSolversSolverKeywordAlgorithmAPILicenseWarm-startClarabelclarabelInterior pointSparseApache-2.0✖️CVXOPTcvxoptInterior pointDenseGPL-3.0✔️DAQPdaqpActive setDenseMIT✖️ECOSecosInterior pointSparseGPL-3.0✖️GurobigurobiInterior pointSparseCommercial✖️HiGHShighsActive setSparseMIT✖️HPIPMhpipmInterior pointDenseBSD-2-Clause✔️MOSEKmosekInterior pointSparseCommercial✔️NPPronpproActive setDenseCommercial✔️OSQPosqpAugmented LagrangianSparseApache-2.0✔️PIQPpiqpProximal Interior PointDense & SparseBSD-2-Clause✖️ProxQPproxqpAugmented LagrangianDense & SparseBSD-2-Clause✔️QPALMqpalmAugmented LagrangianSparseLGPL-3.0✔️qpOASESqpoasesActive setDenseLGPL-2.1➖qpSWIFTqpswiftInterior pointSparseGPL-3.0✖️quadprogquadprogActive setDenseGPL-2.0✖️SCSscsAugmented LagrangianSparseMIT✔️Matrix arguments are NumPy arrays for dense solvers and SciPy Compressed Sparse Column (CSC) matrices for sparse ones.Frequently Asked QuestionsCan I print the list of solvers available on my machine?Is it possible to solve a least squares rather than a quadratic program?I have a squared norm in my cost function, how can I apply a QP solver to my problem?I have a non-convex quadratic program, is there a solver I can use?I have quadratic equality constraints, is there a solver I can use?Error: Mircrosoft Visual C++ 14.0 or greater is required on WindowsCan I add penalty terms as in ridge regression or LASSO?BenchmarkThe results below come fromqpbenchmark, a benchmark for QP solvers in Python. In the following tables, solvers are called with their default settings and compared over whole test sets byshifted geometric mean("shm" for short). Lower is better and 1.0 corresponds to the best solver.Maros-Meszaros (hard problems)Check out thefull reportfor high- and low-accuracy solver settings.Success rate (%)Runtime (shm)Primal residual (shm)Dual residual (shm)Duality gap (shm)Cost error (shm)clarabel89.91.01.01.91.01.0cvxopt53.613.85.32.622.96.6gurobi16.757.810.537.594.034.9highs53.611.35.32.621.26.1osqp41.31.858.722.61950.742.4proxqp77.54.62.01.011.52.2scs60.12.137.53.4133.18.4Maros-Meszaros dense (subset of dense problems)Check out thefull reportfor high- and low-accuracy solver settings.Success rate (%)Runtime (shm)Primal residual (shm)Dual residual (shm)Duality gap (shm)Cost error (shm)clarabel100.01.01.078.41.01.0cvxopt66.11267.4292269757.0268292.6269.172.5daqp50.04163.41056090169.5491187.7351.8280.0ecos12.927499.0996322577.2938191.8197.61493.3gurobi37.13511.4497416073.413585671.64964.0190.6highs64.51008.4255341695.6235041.8396.254.5osqp51.6371.75481100037.53631889.324185.1618.4proxqp91.914.11184.31.071.87.2qpoases24.23916.08020840724.223288184.8102.2778.7qpswift25.816109.1860033995.1789471.9170.4875.0quadprog62.91430.6315885538.24734021.72200.0192.3scs72.695.62817718628.1369300.93303.2152.5Citing qpsolversIf you find this project useful, please consider giving it a :star: 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 @bdelhaisse and @MeindertHH and @rimaddo and @urob and @shaoanlu},license={LGPL-3.0},month=feb,title={{qpsolvers: Quadratic Programming Solvers in Python}},url={https://github.com/qpsolvers/qpsolvers},version={4.3.1},year={2024}}ContributingWe welcome contributions! The first step is to install the library and use it. Report any bug in theissue tracker. If you're a developer looking to hack on open source, check out thecontribution guidelinesfor suggestions.We are also looking forward to hearing about your use cases! Please share them inShow and tell🙌