solver-osqp
A OSQP wrapper for Python that ships prebuilt
binaries. It exposes OSQP's first-order ADMM solver through a thin,
numpy-friendly, MATLAB-quadprog-like interface, in the C++ namespace
marinholab::solvers::osqp and the Python package marinholab.solvers.osqp.
Installation
Python (PyPI)
pip install marinholab-solvers-osqp
C++ (Ubuntu .deb from the SmartArmStack PPA)
The C++ part (marinholab::solvers::osqp, with OSQP bundled) is distributed as
the libmarinholab-solver-osqp .deb from the
SmartArmStack APT repository hosted at
smartarmstack.github.io. On Ubuntu (Noble/24.04), add it and install:
sudo apt-get install -y --no-install-recommends curl ca-certificates gnupg
curl -s --compressed "https://smartarmstack.github.io/smart_arm_stack_ROS2/KEY.gpg" \
| gpg --dearmor \
| sudo tee /etc/apt/trusted.gpg.d/smartarmstack_lgpl.gpg >/dev/null
curl -s --compressed "https://smartarmstack.github.io/smart_arm_stack_ROS2/smartarmstack_lgpl.list" \
| sudo tee /etc/apt/sources.list.d/smartarmstack_lgpl.list >/dev/null
sudo apt-get update
sudo apt-get install -y libmarinholab-solver-osqp
curl, ca-certificates and gnupg are installed first because a bare Ubuntu
(and every ubuntu: Docker image) ships without them: gpg is what dearmors
the signing key -- apt cannot read the armored KEY.gpg directly -- and sudo
is absent from containers, where the commands should instead be run as root
without the sudo prefix.
This is the same repository the SmartArmStack ROS2 packages come from; see smartarmstack.github.io for the full list of available packages.
Building against it needs the toolchain and Eigen (the public header exposes Eigen types in its API):
sudo apt-get install -y --no-install-recommends build-essential cmake libeigen3-dev
Then, in your CMakeLists.txt:
find_package(marinholab_solver_osqp REQUIRED)
target_link_libraries(your_target PRIVATE marinholab::solvers::osqp)
The package links nothing but libc/libstdc++/libm at run time -- OSQP and its
linear-solver are bundled statically -- so it does not need to be able to
find_package(osqp).
docker/consumer/ is a small working project that does
exactly this and checks the numbers it gets back. bash docker/test-ppa.sh
builds it in a clean container against the published package, and
bash docker/build-deb.sh --test does the same against a locally built .deb.
Overview
Given a symmetric matrix H, a vector f, and (optionally) inequality and
equality constraint matrices, the solver solves the quadratic program
min_x 0.5 * x' H x + f' x
s.t. A x <= b
Aeq x = beq
Internally the inequality and equality rows are stacked into OSQP's single
l <= A x <= u form. Once a problem has been solved once, subsequent solves on
the same Solver instance reuse the OSQP solver and update its data in place
by default (Configuration.use_hotstart = True), which is the main performance
benefit for repeated, related QPs. OSQP additionally warm-starts from the
previous iterate between osqp_solve() calls
(Configuration.warm_starting = 1).
Quickstart
import numpy as np
from marinholab.solvers import osqp
solver = osqp.Solver()
H = np.eye(2) # positive definite Hessian
f = np.array([-1.0, -1.0]) # linear term
A = np.array([[1.0, 0.0]]) # x[0] <= 0.2
b = np.array([0.2])
x = solver.solve_quadratic_program(H, f, A, b,
Aeq=np.zeros((1, 2)),
beq=np.zeros((1,)))
# x ≈ [0.2, 1.0]
Omitting constraints
Any of the four constraint arguments (A, b, Aeq, beq) can be None,
meaning "no such constraint". The matrix and its right-hand side must be
omitted (or provided) together:
# Unconstrained
x = solver.solve_quadratic_program(H, f, None, None, None, None)
# Equality constraints only
x = solver.solve_quadratic_program(H, f, None, None, Aeq, beq)
Warm-starting
solve_quadratic_program accepts optional x0 and y0 warm-starts for the
primal and dual variables. The dual solution returned by get_info() can be
used to warm-start the next solve:
x = solver.solve_quadratic_program(H, f, A, b, None, None)
y0 = solver.get_info().dual_solution
x = solver.solve_quadratic_program(H, f, A, b, None, None, x0=x, y0=y0)
Solution information
solver.get_info() returns an Info with the objective and dual-objective
values, the primal and dual residual norms, and the dual solution
(dual_solution):
solver.solve_quadratic_program(H, f, A, b, Aeq, beq)
info = solver.get_info()
info.obj_val, info.dual_obj_val, info.prim_res, info.dual_res, info.dual_solution
C++ API
The same solver is available directly in C++ (the Python wrapper is a thin pybind11 layer over it). It is built with Eigen and OSQP:
#include <marinholab/solvers/osqp.h>
namespace osqp = marinholab::solvers::osqp;
osqp::Configuration config;
config.set("eps_abs", 1.0e-9); // the rest keeps its defaults
config.set("polishing", true);
osqp::Solver solver(config);
Eigen::MatrixXd H = Eigen::MatrixXd::Identity(2, 2);
Eigen::VectorXd f(2);
f << -1.0, -1.0;
Eigen::MatrixXd A(1, 2);
A << 1.0, 0.0; // x[0] <= 0.2
Eigen::VectorXd b(1);
b << 0.2;
Eigen::MatrixXd Aeq = Eigen::MatrixXd::Zero(1, 2);
Eigen::VectorXd beq = Eigen::VectorXd::Zero(1);
Eigen::VectorXd x = solver.solve_quadratic_program(H, f, A, b, Aeq, beq);
// x ≈ [0.2, 1.0]
osqp::Solver::Info info = solver.get_info(); // obj_val, prim_res, dual_solution, ...
The API mirrors the Python one: solve_quadratic_program(H, f, A, b, Aeq, beq, x0, y0) solves the QP above and get_info() reports the solution quality.
Configuration exposes the same fields documented below.
A standalone, self-contained C++ program using this API lives in
example/example.cpp (target example_osqp). It is
built only when BUILD_EXAMPLES=ON so it does not affect pip install .:
cmake -B build -GNinja -DCMAKE_BUILD_TYPE=Release -DBUILD_EXAMPLES=ON
cmake --build build --target example_osqp
./build/example/example_osqp # prints x ≈ [0.2, 1.0] and the residuals
Type checking (Pyright)
The Python wrapper is fully type-annotated and ships a PEP 561 py.typed
marker plus a _core.pyi type stub for the compiled _core extension, so
downstream projects can be checked against it. To type-check the package:
pyright # configuration in pyrightconfig.json (python 3.9, mode basic)
This must pass with 0 errors / 0 warnings. Keep _core.pyi in sync with
the pybind11 surface in src/core.cpp.
Configuration
All of OSQP's OSQPSettings fields are exposed, plus one wrapper-specific
setting. Options are set by name. Create a Configuration, set the options
you need, and pass it to the solver:
config = osqp.Configuration()
config.set("eps_abs", 1.0e-9) # tighter absolute tolerance
config.set("eps_rel", 1.0e-9) # tighter relative tolerance
config.set("max_iter", 20000) # more ADMM iterations
config.set("polishing", True) # polish the ADMM solution
solver = osqp.Solver(config)
Values may be given as bool, int, float, or str (enum options take the enum
value name, e.g. "OSQP_DIRECT_SOLVER", or a LinsysSolverType member;
set() also converts strings such as "1e-9" or "false"). Unset options
keep OSQP's own defaults. config.keys() and config.defaults() list the
full option names and their defaults.
The enum types are re-exported for convenience: osqp.LinsysSolverType,
osqp.PreconditionerType, and osqp.Status.
Wrapper-specific option
| Option | Default | Type | Description |
|---|---|---|---|
use_hotstart |
True |
bool |
Reuse the existing OSQP solver and update its data in place instead of re-running osqp_setup() when the problem shape is unchanged. |
OSQP options (linear algebra & control)
These map 1:1 onto OSQP's OSQPSettings fields. Defaults match OSQP's own
defaults for a standard double-precision, direct-solver build (see
osqp_set_default_settings()), except verbose, which defaults to off so the
solver is quiet by default. See the
OSQP documentation for a full description of each
option.
| Option | Default | Type | Description |
|---|---|---|---|
device |
0 |
int |
Device identifier; currently used for CUDA devices. |
linsys_solver |
OSQP_DIRECT_SOLVER |
LinsysSolverType |
Linear system solver to use. |
allocate_solution |
1 |
int |
Whether the solution is allocated during osqp_setup(). |
verbose |
0 |
int |
Whether solver progress is written out (quiet by default). |
profiler_level |
0 |
int |
Level of detail for profiler annotations. |
warm_starting |
1 |
int |
Warm-start from the previous solution between consecutive solves. |
scaling |
10 |
int |
Heuristic data-scaling iterations; 0 disables scaling. |
polishing |
0 |
int |
Whether the ADMM solution is polished to improve accuracy. |
OSQP options (ADMM parameters)
| Option | Default | Type | Description |
|---|---|---|---|
rho |
0.1 |
float |
ADMM penalty parameter (scalar). |
rho_is_vec |
1 |
int |
Whether rho is a scalar or a vector. |
sigma |
1e-06 |
float |
ADMM regularization parameter (improves conditioning). |
alpha |
1.6 |
float |
ADMM relaxation parameter. |
OSQP options (CG settings)
| Option | Default | Type | Description |
|---|---|---|---|
cg_max_iter |
20 |
int |
Maximum number of CG iterations per solve. |
cg_tol_reduction |
10 |
int |
Consecutive zero CG iterations before the tolerance is halved. |
cg_tol_fraction |
0.15 |
float |
CG tolerance, as a fraction of the ADMM residuals. |
cg_precond |
OSQP_DIAGONAL_PRECONDITIONER |
PreconditionerType |
Preconditioner used by the CG method. |
OSQP options (adaptive rho)
| Option | Default | Type | Description |
|---|---|---|---|
adaptive_rho |
1 (..._ITERATIONS) |
int |
rho stepsize adaptation method (0 disabled, 1 iterations, 2 time, 3 KKT error). |
adaptive_rho_interval |
50 |
int |
Interval between rho adaptations (iterations-based method). |
adaptive_rho_fraction |
0.4 |
float |
Fraction controlling when non-fixed rho adaptations occur. |
adaptive_rho_tolerance |
5.0 |
float |
Min ratio between new and current rho for it to be adopted. |
OSQP options (termination)
| Option | Default | Type | Description |
|---|---|---|---|
max_iter |
4000 |
int |
Maximum number of ADMM iterations. |
eps_abs |
1e-3 |
float |
Absolute solution tolerance. |
eps_rel |
1e-3 |
float |
Relative solution tolerance. |
eps_prim_inf |
1e-4 |
float |
Primal infeasibility detection tolerance. |
eps_dual_inf |
1e-4 |
float |
Dual infeasibility detection tolerance. |
scaled_termination |
0 |
int |
Whether the scaled termination criteria are used. |
check_termination |
25 |
int |
Interval at which termination is checked; 0 disables the periodic check. |
check_dualgap |
1 |
int |
Whether the duality-gap termination criteria are used. |
time_limit |
1e10 |
float |
Maximum solve time, in seconds. |
OSQP options (polishing)
| Option | Default | Type | Description |
|---|---|---|---|
delta |
1e-6 |
float |
Regularization parameter used by polishing. |
polish_refine_iter |
3 |
int |
Number of iterative refinement steps during polishing. |
Enums
Linear system solvers (LinsysSolverType): OSQP_UNKNOWN_SOLVER,
OSQP_DIRECT_SOLVER, OSQP_INDIRECT_SOLVER.
CG preconditioners (PreconditionerType): OSQP_NO_PRECONDITIONER,
OSQP_DIAGONAL_PRECONDITIONER.
Solver status (Status): OSQP_SOLVED, OSQP_SOLVED_INACCURATE,
OSQP_PRIMAL_INFEASIBLE, OSQP_PRIMAL_INFEASIBLE_INACCURATE,
OSQP_DUAL_INFEASIBLE, OSQP_DUAL_INFEASIBLE_INACCURATE,
OSQP_MAX_ITER_REACHED, OSQP_TIME_LIMIT_REACHED, OSQP_NON_CVX,
OSQP_SIGINT, OSQP_UNSOLVED.
Examples
marinholab/solvers/osqp/example.py— positive-definite solves, theNone-constraint path, warm-starting, a hierarchical (task-priority) example, andget_info(). Run it withosqp_example(installed as a console script).marinholab/solvers/osqp/example_kinematics.py— an optional example showing the solver used in a hierarchical (task-priority) controller for a kinematically redundant robot, built ondqrobotics. It requires the optional dependenciesdqroboticsanddqrobotics-pyplot(pip install --pre dqrobotics dqrobotics-pyplot).
Building from source
The package builds a C++ extension (via CMake + pybind11) and vendors OSQP and pybind11 as git submodules.
git clone --recurse-submodules <repo>
pip install .
Prerequisites: a C++23 compiler, CMake, an Eigen3 installation, and Python.
On Ubuntu: sudo apt-get install cmake libeigen3-dev.
License
The wrapper is under the GNU Lesser General Public License v2.1 (see the
included LICENSE file); the bundled
OSQP library is Apache-2.0.
Metadata
Release files for marinholab-solvers-osqp 26.10.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
| File | Actions Reset | |||
|---|---|---|---|---|
| marinholab_solvers_osqp-26.10.0.4-cp313-cp313-manylinux2014_x86_64.whl | CPython 3.13 | CPython 3.13 | Linux glibc 2.17+ x86-64 | Details for marinholab_solvers_osqp-26.10.0.4-cp313-cp313-manylinux2014_x86_64.whl |
| marinholab_solvers_osqp-26.10.0.4-cp313-cp313-manylinux2014_aarch64.whl | CPython 3.13 | CPython 3.13 | Linux glibc 2.17+ ARM64 | Details for marinholab_solvers_osqp-26.10.0.4-cp313-cp313-manylinux2014_aarch64.whl |
| marinholab_solvers_osqp-26.10.0.4-cp312-cp312-manylinux2014_x86_64.whl | CPython 3.12 | CPython 3.12 | Linux glibc 2.17+ x86-64 | Details for marinholab_solvers_osqp-26.10.0.4-cp312-cp312-manylinux2014_x86_64.whl |
| marinholab_solvers_osqp-26.10.0.4-cp312-cp312-manylinux2014_aarch64.whl | CPython 3.12 | CPython 3.12 | Linux glibc 2.17+ ARM64 | Details for marinholab_solvers_osqp-26.10.0.4-cp312-cp312-manylinux2014_aarch64.whl |
Total release size: 928.9 kB
Release files / marinholab_solvers_osqp-26.10.0.4-cp313-cp313-manylinux2014_x86_64.whl
| Download URL | marinholab_solvers_osqp-26.10.0.4-cp313-cp313-manylinux2014_x86_64.whl |
|---|---|
| Size | 250.6 kB |
| Tags | CPython 3.13 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
c243b45dab6558356c60280f4f643f8150b592d5ec12bdf2d6485253b12ea8d0
|
|
BLAKE2b-256 checksum How to use checksums |
befc7d7b6d14c137976289f5f22c352634f2045d266f54ad2978492b421b267a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.
Transparency logRelease files / marinholab_solvers_osqp-26.10.0.4-cp313-cp313-manylinux2014_aarch64.whl
| Download URL | marinholab_solvers_osqp-26.10.0.4-cp313-cp313-manylinux2014_aarch64.whl |
|---|---|
| Size | 213.9 kB |
| Tags | CPython 3.13 Linux glibc 2.17+ ARM64 |
|
SHA-256 checksum How to use checksums |
ce39f7c30a5a034b5c4f6f956996d3767d768207a8c32f9cdbe61d1f5ee751fd
|
|
BLAKE2b-256 checksum How to use checksums |
61815f05d4d2fe6e3954d26156e39dc070080d4910f72df5958b2e5b485da574
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.
Transparency logRelease files / marinholab_solvers_osqp-26.10.0.4-cp312-cp312-manylinux2014_x86_64.whl
| Download URL | marinholab_solvers_osqp-26.10.0.4-cp312-cp312-manylinux2014_x86_64.whl |
|---|---|
| Size | 250.6 kB |
| Tags | CPython 3.12 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
7201368d4eed4e6872d476672f3fad757fc9a64f8205d2ea801fa79715c04d7d
|
|
BLAKE2b-256 checksum How to use checksums |
45e5870b56a0e443fda81fef8964ea0bc3726aa8b21b8ac2fe2c6a72cb5fb81e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.
Transparency logRelease files / marinholab_solvers_osqp-26.10.0.4-cp312-cp312-manylinux2014_aarch64.whl
| Download URL | marinholab_solvers_osqp-26.10.0.4-cp312-cp312-manylinux2014_aarch64.whl |
|---|---|
| Size | 213.9 kB |
| Tags | CPython 3.12 Linux glibc 2.17+ ARM64 |
|
SHA-256 checksum How to use checksums |
44da3193c3916548647a94f0a091705b0ab15d4ba3c9c40a326c84919371bf60
|
|
BLAKE2b-256 checksum How to use checksums |
6a080dbdf23df17efa32dc576ef11b3317921cb96b3139a7c3d9db8c524d5bec
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.
Transparency logSecurity for marinholab-solvers-osqp 26.10.0.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 4 files in this release have been uploaded with provenance metadata.
Attestation for marinholab_solvers_osqp-26.10.0.4-cp313-cp313-manylinux2014_x86_64.whl
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.