OSQP: The Operator Splitting QP Solver

1.1.1 · active · verified Thu Apr 09

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.

Warnings

Install

Imports

Quickstart

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`.

import osqp
import numpy as np
from scipy import sparse

# Define problem data
P = sparse.csc_matrix([[4, 1], [1, 2]])
q = np.array([1, 1])
A = sparse.csc_matrix([[1, 1], [1, 0], [0, 1]])
l = np.array([1, 0, 0])
u = np.array([1, 0.7, 0.7])

# Create an OSQP object
m = osqp.OSQP()

# Setup workspace
m.setup(P=P, q=q, A=A, l=l, u=u, verbose=False)

# Solve problem
res = m.solve()

# Print results
print(f"Problem status: {res.info.status}")
print(f"Optimal x: {res.x}")

view raw JSON →