Skip to content

Repository files navigation

scs-python

Build StatusDocumentationPyPI DownloadsConda Downloads

Python interface for SCS 3.0.0 and higher. The full documentation is available here.

Installation

pip install scs

To install from source:

git clone --recursive https://github.com/bodono/scs-python.git
cd scs-python
pip install .

Linear solver backends

SCS supports several linear solver backends. The default is AUTO, which selects the best available solver for the platform:

  • macOS: QDLDL (Apple Accelerate is available via LinearSolver.ACCELERATE)
  • Linux / Windows: MKL Pardiso if available, otherwise QDLDL
# Auto-detect best backend (default)solver=scs.SCS(data, cone)
# Explicitly select a solversolver=scs.SCS(data, cone, linear_solver=scs.LinearSolver.QDLDL)

Available values: AUTO, QDLDL, CPU_INDIRECT, MKL, ACCELERATE, CPU_DENSE, GPU_INDIRECT, CUDSS.

The pre-built wheels (pip install scs) include MKL on x86_64 Linux and Windows, and Apple Accelerate on macOS. When installing from source, additional backends can be enabled with build-time flags:

# MKL Pardiso direct solver
pip install . -Csetup-args=-Dlink_mkl=true
# Use 64-bit BLAS/LAPACK integers (ILP64 / BLAS64)
pip install . -Csetup-args=-Duse_blas64=true
# GPU direct solver (cuDSS)
pip install . -Csetup-args=-Dlink_cudss=true -Csetup-args=-Dint32=true
# Dense direct solver (LAPACK)
pip install . -Csetup-args=-Duse_lapack=true
# Spectral cones (logdet, nuclear norm, ell-1, sum-of-largest)
pip install . -Csetup-args=-Duse_spectral_cones=true

Notes:

  • Linux x86_64 wheels are built and tested against threaded MKL, and CI asserts a libiomp5 dependency on the packaged _scs_mkl extension. Windows currently falls back to sequential MKL because Intel's conda pkg-config metadata for the threaded variant is still broken.
  • BLAS64 is a general SCS build mode for ILP64 BLAS/LAPACK libraries, not an MKL-only feature.
  • For the MKL Pardiso backend specifically, BLAS64 must be paired with 64-bit SCS integers (DLONG / int32=false), and SCS now fails early if another library in the process has already fixed MKL to an incompatible LP64/ILP64 interface layer.

Usage

importnumpyasnpimportscipy.sparseasspimportscsm, n=4, 2A=sp.random(m, n, density=0.5, format="csc")
b=np.random.randn(m)
c=np.random.randn(n)
P=sp.eye(n, format="csc")
cone= {"l": m} # non-negative conedata= {"P": P, "A": A, "b": b, "c": c}
solver=scs.SCS(data, cone, verbose=False)
sol=solver.solve()
print(sol["info"]["status"]) # 'solved'print(sol["info"]["aa_stats"]) # Anderson acceleration diagnosticsprint(sol["x"]) # primal solution

Anderson acceleration tuning

SCS applies Anderson acceleration (AA) on top of ADMM. The defaults work well for most problems, but the following settings can be tuned:

SettingDefaultDescription
acceleration_lookback10AA memory size; 0 disables AA.
acceleration_interval10Apply AA every N ADMM iterations.
acceleration_type_111 = type-I AA, 0 = type-II AA.
acceleration_regularization1e-8Tikhonov regularization for the AA least-squares solve. Tuned for type-I; type-II typically prefers 1e-12.
acceleration_relaxation1.0Relaxation factor in [0, 2]; 1.0 is vanilla AA.
# Type-II AA with tighter regularizationsolver=scs.SCS(data, cone,
acceleration_type_1=0,
acceleration_regularization=1e-12)

See the acceleration docs for the underlying algorithm.

Cone types

The cone dict supports the following keys:

KeyTypeDescription
zintZero cone
lintNon-negative cone
bu, blarrayBox cone bounds
qlist[int]Second-order cone lengths
slist[int]PSD cone matrix dimensions
cslist[int]Complex PSD cone matrix dimensions
epintPrimal exponential cone triples
edintDual exponential cone triples
plist[float]Power cone parameters

With -Duse_spectral_cones=true:

KeyTypeDescription
dlist[int]Log-determinant cone matrix dimensions
nuc_m, nuc_nlist[int]Nuclear norm cone row/column dimensions
ell1list[int]ell-1 norm cone dimensions
sl_n, sl_klist[int]Sum-of-largest-eigenvalues dimensions and k values

See the cone documentation for mathematical definitions and data layout details.

Testing

pip install pytest
pytest test/

About

Python interface for SCS

Topics

Resources

Stars

46 stars

Watchers

4 watching

Forks

Releases

Packages

Used by

Contributors

Languages