Skip to content

Commit 543164f

Browse files
authored
Merge pull request #381 from cvxgrp/linear-solver-enum-docs
Update Python docs for LinearSolver enum API
2 parents 19303c4 + 6e3229b commit 543164f

3 files changed

Lines changed: 138 additions & 31 deletions

File tree

docs/src/api/python.rst

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ This module provides the :code:`SCS` class which is initialized using:
1515
1616
solver = scs.SCS(data,
1717
cone,
18-
use_indirect=False,
19-
mkl=False,
20-
apple_ldl=False,
21-
gpu=False,
18+
linear_solver=scs.LinearSolver.AUTO,
2219
verbose=True,
2320
normalize=True,
2421
max_iters=int(1e5),
@@ -42,17 +39,52 @@ the cone length or the array that defines the cone (see the third column in
4239
:ref:`cones` for the keys and what the corresponding values represent). The
4340
:code:`b`, and :code:`c` entries must be 1d numpy arrays and the :code:`P` and
4441
:code:`A` entries must be scipy sparse matrices in CSC format; if they are not
45-
of the proper format, SCS will attempt to convert them. The
46-
:code:`use_indirect` setting switches between the sparse direct
47-
:ref:`linear_solver` (the default) or the sparse indirect solver. If the MKL
48-
Pardiso direct solver for SCS is :ref:`installed <python_install>` then it can
49-
be used by setting :code:`mkl=True`. On macOS the Apple Accelerate sparse
50-
LDL\ :sup:`T` solver is included automatically and can be used by setting
51-
:code:`apple_ldl=True`. If a GPU solver for SCS is :ref:`installed
52-
<python_install>` and a GPU is available then it can be used by setting
53-
:code:`gpu=True`. For the direct GPU solver based on cuDSS set
54-
:code:`use_indirect=False`. The remaining fields are explained in
55-
:ref:`settings`.
42+
of the proper format, SCS will attempt to convert them.
43+
44+
Linear solver selection
45+
-----------------------
46+
47+
The :code:`linear_solver` setting controls which :ref:`linear_solver` backend
48+
SCS uses. It accepts a :code:`scs.LinearSolver` enum value.
49+
The default is :code:`AUTO`, which selects the best available solver for
50+
the platform:
51+
52+
- **macOS**: QDLDL (Apple Accelerate is available via :code:`LinearSolver.ACCELERATE`)
53+
- **Linux / Windows**: MKL Pardiso if available, otherwise QDLDL
54+
55+
.. list-table::
56+
:header-rows: 1
57+
58+
* - Value
59+
- Description
60+
* - :code:`AUTO`
61+
- Auto-detect best available solver (default).
62+
* - :code:`QDLDL`
63+
- Sparse direct solver using `QDLDL <https://github.com/oxfordcontrol/qdldl>`_ (always available).
64+
* - :code:`CPU_INDIRECT`
65+
- Sparse indirect solver using conjugate gradients (runs on CPU).
66+
* - :code:`MKL`
67+
- Intel MKL Pardiso direct solver (requires :ref:`MKL build <python_install>`).
68+
* - :code:`ACCELERATE`
69+
- Apple Accelerate sparse LDL\ :sup:`T` (macOS only, included automatically).
70+
* - :code:`CPU_DENSE`
71+
- Dense direct solver via LAPACK (requires LAPACK build).
72+
* - :code:`GPU_INDIRECT`
73+
- Sparse GPU indirect solver (requires GPU build).
74+
* - :code:`CUDSS`
75+
- Sparse GPU direct solver via cuDSS (requires :ref:`cuDSS build <python_install>`).
76+
77+
Example:
78+
79+
.. code:: python
80+
81+
# Use the default (auto-detect)
82+
solver = scs.SCS(data, cone)
83+
84+
# Explicitly select a solver
85+
solver = scs.SCS(data, cone, linear_solver=scs.LinearSolver.QDLDL)
86+
87+
The remaining fields are explained in :ref:`settings`.
5688

5789
Cone dict
5890
---------

docs/src/install/python.rst

Lines changed: 87 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,45 @@ You can also install directly from source
1717
cd scs-python
1818
python -m pip install .
1919
20+
Linear solver backends
21+
----------------------
22+
23+
The pre-built wheels and a from-source install always include two CPU linear
24+
solvers that require no additional dependencies:
25+
26+
- :code:`QDLDL` — the default sparse direct solver (bundled with SCS).
27+
- :code:`CPU_INDIRECT` — the sparse matrix-free solver based on conjugate
28+
gradients.
29+
30+
The remaining backends require either a platform-specific library (Apple
31+
Accelerate, MKL) or a build-time flag plus an external dependency (LAPACK for
32+
dense, CUDA + cuDSS for GPU). Each section below describes what to install and
33+
how to enable the backend. See :ref:`linear_solver` for an overview of each
34+
solver and :ref:`python_interface` for how to select one at runtime.
35+
2036
Apple Accelerate (macOS)
2137
""""""""""""""""""""""""
2238

2339
On macOS the Apple Accelerate backend is built and included automatically —
2440
no extra install flags are needed. It uses the Accelerate framework's sparse
2541
LDL\ :sup:`T` solver, which is optimized for Apple hardware including Apple
26-
Silicon. See :ref:`here <python_interface>` for how to select Accelerate when
27-
solving.
42+
Silicon. The default :code:`linear_solver=scs.LinearSolver.AUTO` selects the
43+
bundled QDLDL on macOS; opt in to Accelerate explicitly with
44+
:code:`linear_solver=scs.LinearSolver.ACCELERATE`.
2845

2946
MKL
3047
"""
3148

32-
If you have MKL, you can install the MKL Pardiso interface using
49+
The pre-built wheels (:code:`pip install scs`) include MKL on x86_64 Linux and
50+
Windows. When installing from source, you can enable MKL with:
3351

3452
.. code:: bash
3553
3654
python -m pip install -Csetup-args=-Dlink_mkl=true .
3755
38-
See :ref:`here <python_interface>` for how to enable MKL when solving. MKL is
39-
typically faster than the built-in linear system solver.
56+
When using the default :code:`linear_solver=scs.LinearSolver.AUTO`, MKL is
57+
selected automatically on Linux and Windows if available. MKL is
58+
typically faster than the built-in QDLDL linear system solver.
4059

4160
The published Linux x86_64 wheels prefer the threaded MKL variant and include
4261
the Intel OpenMP runtime (:code:`libiomp5`). Windows currently falls back to
@@ -56,21 +75,71 @@ also checks that the process-wide MKL interface layer matches the LP64/ILP64
5675
mode it was compiled for, and fails early if another library already set an
5776
incompatible MKL interface.
5877

59-
GPU
60-
"""
78+
Dense direct (LAPACK)
79+
"""""""""""""""""""""
80+
81+
The :ref:`dense direct solver <dense>` reduces the KKT system to a smaller
82+
Gram matrix and factorizes it with LAPACK's Cholesky routines. It is well
83+
suited to small-to-medium problems with a dense constraint matrix :math:`A`,
84+
where dense BLAS/LAPACK outperforms sparse factorization.
6185

62-
If you have a GPU and cuDSS installed you can install the GPU direct sparse
63-
solver using
86+
Build from source with:
87+
88+
.. code:: bash
89+
90+
python -m pip install -Csetup-args=-Duse_lapack=true .
91+
92+
This requires BLAS and LAPACK development headers to be discoverable by
93+
:code:`pkg-config`. Most platforms satisfy this out of the box (Apple
94+
Accelerate on macOS, OpenBLAS / MKL on Linux, MKL on Windows). Select the
95+
backend at runtime with
96+
:code:`linear_solver=scs.LinearSolver.CPU_DENSE`.
97+
98+
GPU direct (cuDSS)
99+
""""""""""""""""""
100+
101+
The :ref:`cuDSS backend <cudss_solver>` runs the sparse direct factorization
102+
and solves on an NVIDIA GPU via `NVIDIA cuDSS
103+
<https://developer.nvidia.com/cudss>`_. For large problems it is typically
104+
substantially faster than any CPU backend.
105+
106+
**Prerequisites.** The build links against both the CUDA runtime and cuDSS,
107+
so you need all of the following installed and discoverable by
108+
:code:`pkg-config` / the linker before running :code:`pip install`:
109+
110+
1. An NVIDIA GPU with a recent CUDA-capable driver.
111+
2. The `CUDA Toolkit <https://developer.nvidia.com/cuda-downloads>`_
112+
(provides :code:`nvcc`, the CUDA runtime headers, and :code:`cuda.pc`
113+
used by the build).
114+
3. The `cuDSS library <https://developer.nvidia.com/cudss-downloads>`_ (ships
115+
a :code:`cudss.pc` pkg-config file). cuDSS is also available on
116+
`conda-forge <https://anaconda.org/conda-forge/libcudss>`_ as
117+
:code:`libcudss` / :code:`libcudss-dev`.
118+
119+
Make sure the directories containing :code:`cuda.pc` and :code:`cudss.pc` are
120+
on :code:`PKG_CONFIG_PATH`, and that the corresponding shared libraries are on
121+
:code:`LD_LIBRARY_PATH` (Linux) at runtime. A typical Linux environment looks
122+
like:
123+
124+
.. code:: bash
125+
126+
export PATH=/usr/local/cuda/bin:$PATH
127+
export PKG_CONFIG_PATH=/usr/local/cuda/lib64/pkgconfig:/opt/nvidia/cudss/lib64/pkgconfig:$PKG_CONFIG_PATH
128+
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:/opt/nvidia/cudss/lib64:$LD_LIBRARY_PATH
129+
130+
**Install.** Once the prerequisites are in place, build SCS with:
64131

65132
.. code:: bash
66133
67134
python -m pip install -Csetup-args=-Dlink_cudss=true -Csetup-args=-Dint32=true .
68135
69-
See :ref:`here <python_interface>` for how to enable the GPU when solving. The
70-
sparse direct GPU solver is typically very fast.
136+
The :code:`int32=true` flag is required because cuDSS only supports 32-bit
137+
integer indices. Select the backend at runtime with
138+
:code:`linear_solver=scs.LinearSolver.CUDSS`.
71139

72-
See `here <https://colab.research.google.com/drive/1POCgDNFg8fycHMI9T9N6V3iHFhXRthjn?usp=sharing>`_ for an example colab where the cuDSS version of SCS, along with
73-
required dependencies, is installed and used.
140+
See `this Colab notebook <https://colab.research.google.com/drive/1POCgDNFg8fycHMI9T9N6V3iHFhXRthjn?usp=sharing>`_
141+
for a worked end-to-end example that installs CUDA, cuDSS, and the cuDSS
142+
build of SCS, then solves a problem on a GPU.
74143

75144
.. _python_spectral_install:
76145

@@ -107,8 +176,12 @@ You can install with OpenMP parallelization support using
107176
108177
python legacy_setup.py install --scs --openmp
109178
110-
You can install the GPU indirect solver using
179+
You can install the :ref:`GPU indirect solver <gpu_indirect>` using
111180

112181
.. code:: bash
113182
114183
python legacy_setup.py install --scs --gpu
184+
185+
The GPU indirect solver is effectively deprecated; the cuDSS direct solver
186+
above is the recommended GPU backend.
187+

docs/src/linear_solver/index.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,11 @@ To build with CMake::
110110
cmake -DUSE_APPLE_ACCELERATE=ON ..
111111

112112
In Python, the Accelerate backend is included automatically on macOS
113-
(``pip install scs`` is sufficient). Select it at solve time::
113+
(``pip install scs`` is sufficient). On macOS,
114+
``linear_solver=scs.LinearSolver.AUTO`` selects the bundled QDLDL; select
115+
Accelerate explicitly with::
114116

115-
solver = scs.SCS(data, cone, apple_ldl=True)
117+
solver = scs.SCS(data, cone, linear_solver=scs.LinearSolver.ACCELERATE)
116118

117119
.. _indirect:
118120

0 commit comments

Comments
 (0)