Skip to content

Installation

DiffAPQP supports Python 3.9 or later and uses CVXPY for modeling and PyTorch for automatic differentiation.

Standard installation

Install the package from PyPI:

python -m pip install diffapqp

The standard installation uses the public CVXPY release and supports the normal CVXPY solver interface. Linux retains the existing fork implementation for solution-map backward parallelism, while Windows and macOS use shared-memory threads without an additional process-executor dependency.

Verify the public API:

from diffapqp import SolMapLayer, ValueFuncLayer

print(SolMapLayer)
print(ValueFuncLayer)

Custom CVXPY update support

Sample-wise warm starts and in-place problem solver data updates for OSQP, SCS, QPALM, and PROXQP require the DiffAPQP CVXPY fork. Install the pinned fork before DiffAPQP:

python -m pip install \
  "cvxpy @ git+https://github.com/xuwkk/cvxpy.git@v1.9.0-lapso.7"
python -m pip install diffapqp

The custom fork requires Python 3.11 or later. It is installed separately because public package indexes do not reliably support Git dependencies in package metadata.

You can check which CVXPY implementation is active:

import cvxpy as cp
from diffapqp import has_cvxpy_fork

print(cp.__version__)
print("DiffAPQP CVXPY fork:", has_cvxpy_fork())
print("Installed solvers:", cp.installed_solvers())

Additional solver installation

The standard installation includes the solver packages required by CVXPY, normally Clarabel, OSQP, and SCS. Other solver backends must be installed separately in the same Python environment. For example:

python -m pip install "diffapqp[gurobi]"  # Gurobi (recommended)
python -m pip install "diffapqp[proxqp]"  # PROXQP

The PROXQP extra installs the tested proxsuite<0.7 compatibility range. Gurobi requires an appropriate licence for unrestricted problem sizes. Use the custom CVXPY fork described above when sample-wise warm-start/update support is required for PROXQP.

CVXPY detects installed solver backends automatically. The CVXPY installation guide provides instructions for other solvers, including QPALM, ECOS, MOSEK, CPLEX, and XPRESS.

Confirm that CVXPY detects the requested solver:

import cvxpy as cp

print(cp.installed_solvers())

Development dependencies

The following extras are intended for repository development and documentation:

python -m pip install "diffapqp[benchmark]"  # cvxpylayers comparisons
python -m pip install "diffapqp[dev]"        # pytest
python -m pip install "diffapqp[docs]"       # MkDocs documentation

Install PyTorch separately first when you require a specific CUDA build, then install DiffAPQP.

Editable installation

For local development:

git clone https://github.com/xuwkk/diffapqp.git
cd diffapqp
python -m pip install -e ".[dev]"

Add the custom CVXPY fork first when developing warm-start/update features:

python -m pip install \
  "cvxpy @ git+https://github.com/xuwkk/cvxpy.git@v1.9.0-lapso.7"
python -m pip install -e ".[dev]"

Compatibility imports

SolMapLayer is the recommended name for the solution-map layer. Layer remains an exact alias, and the former lao package namespace remains available for existing applications:

from diffapqp import SolMapLayer
from diffapqp import Layer  # Backward-compatible alias
from lao import Layer as LegacyLayer

assert SolMapLayer is Layer
assert SolMapLayer is LegacyLayer

New applications should use the diffapqp namespace.