{"id":2175,"library":"osqp","title":"OSQP: The Operator Splitting QP Solver","description":"OSQP (Operator Splitting Quadratic Program) is an optimization solver for Quadratic Programs (QPs) using the Alternating Direction Method of Multipliers (ADMM). It's primarily written in C, providing high-level language interfaces for Python, Julia, Matlab, and R. The current Python library version is 1.1.1, with an active development and release cadence of several updates per year, including major versions that introduce breaking changes.","status":"active","version":"1.1.1","language":"en","source_language":"en","source_url":"https://github.com/osqp/osqp-python","tags":["optimization","quadratic programming","solver","convex optimization","numerical","admm"],"install":[{"cmd":"pip install osqp","lang":"bash","label":"Install OSQP"}],"dependencies":[{"reason":"Required for array operations in problem definition.","package":"numpy","optional":false},{"reason":"Required for sparse matrix representation of P and A.","package":"scipy","optional":false}],"imports":[{"symbol":"osqp","correct":"import osqp"},{"symbol":"numpy","correct":"import numpy as np"},{"symbol":"sparse","correct":"from scipy import sparse"}],"quickstart":{"code":"import osqp\nimport numpy as np\nfrom scipy import sparse\n\n# Define problem data\nP = sparse.csc_matrix([[4, 1], [1, 2]])\nq = np.array([1, 1])\nA = sparse.csc_matrix([[1, 1], [1, 0], [0, 1]])\nl = np.array([1, 0, 0])\nu = np.array([1, 0.7, 0.7])\n\n# Create an OSQP object\nm = osqp.OSQP()\n\n# Setup workspace\nm.setup(P=P, q=q, A=A, l=l, u=u, verbose=False)\n\n# Solve problem\nres = m.solve()\n\n# Print results\nprint(f\"Problem status: {res.info.status}\")\nprint(f\"Optimal x: {res.x}\")","lang":"python","description":"This quickstart demonstrates how to define and solve a simple Quadratic Program using OSQP. It initializes problem matrices (P, A as sparse CSC matrices) and vectors (q, l, u as NumPy arrays), sets up the solver, and then solves the problem, printing the solution status and optimal variable `x`."},"warnings":[{"fix":"Consult the official 'Migration guide from v0.6.x' for a complete list of changes and updated API calls. Update `setup`, `update` method calls, and setting parameters accordingly.","message":"Migration from v0.6.x to v1.0 introduced significant API changes, including modified `osqp_setup` function signature, new update functions (`osqp_update_data_vec`, `osqp_update_data_mat` replacing old vector/matrix updates), and renamed settings (e.g., `polish` to `polishing`, `warm_start` to `warm_starting`).","severity":"breaking","affected_versions":"0.6.x to 1.x"},{"fix":"Ensure MKL or CUDA runtime libraries are correctly installed and configured on your system or within your Python environment (e.g., via `conda install cudatoolkit` or manual installation and `LD_LIBRARY_PATH` setup).","message":"Installing optional algebra backends (e.g., `osqp[mkl]` or `osqp[cu12]`) only installs the Python binding; it does NOT automatically install the underlying MKL or CUDA runtime libraries. These libraries must be installed separately and made available to your Python environment for the backends to function.","severity":"gotcha","affected_versions":"All versions with optional backends"},{"fix":"Always verify that your problem formulation results in a convex QP before passing it to OSQP. Consider adding regularization if the convexity is borderline or uncertain.","message":"OSQP is designed for convex Quadratic Programs. While the solver includes heuristics to detect non-convexity, it might fail to reliably identify non-convex problems, especially those with slightly negative eigenvalues of P. Providing non-convex problems can lead to unexpected or incorrect results.","severity":"gotcha","affected_versions":"All versions"},{"fix":"If the sparsity pattern of `P` or `A` needs to change, a new `osqp.OSQP()` object must be created and `m.setup()` called again with the new matrices.","message":"When updating problem matrices `P` or `A` using `m.update()`, only the *values* of existing nonzero entries can be changed. Their sparsity pattern (i.e., which entries are zero and non-zero) cannot be modified without a full problem re-setup.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Set `raise_error=True` in `m.solve(raise_error=True)` to explicitly raise an exception if the solver status is not `OSQP_SOLVED`. Alternatively, always check `res.info.status` to inspect the solver's outcome.","message":"By default, the `problem.solve()` method in v1.x has `raise_error=False`. This means if the solver does not reach an optimal solution (e.g., due to reaching max iterations or being primal/dual infeasible), it will return a result object without raising an exception, potentially hiding issues.","severity":"gotcha","affected_versions":"1.0.0 and later"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}