QDLDL is a Python wrapper for the QDLDL C library, providing a high-performance LDL factorization routine primarily for sparse matrices. It's designed for use in optimization and numerical methods, particularly for solving symmetric indefinite systems like those arising in KKT matrices. The current version is 0.1.9.post1, with updates released periodically to support newer Python versions, architectures, and upstream C library improvements.
pip install qdldlVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to factorize a sparse symmetric indefinite matrix (e.g., a KKT matrix) using `qdldl.qdldl` and then solve a linear system with the obtained factors using `qdldl.solve`. It uses `scipy.sparse.csc_matrix` for efficient sparse matrix representation.
Upgrade `qdldl` to `0.1.7.post4` or newer: `pip install --upgrade qdldl`.
Ensure input matrices are in CSC format. If starting from another sparse format (e.g., CSR), convert using `matrix.tocsc()`.
Consult the `qdldl` release notes on GitHub for specific Python version compatibility. Ensure your Python environment is supported by the installed `qdldl` version, or upgrade `qdldl`.
Consider the numerical stability of your problem and input data. For ill-conditioned systems, preconditioning or alternative solvers may be necessary.
Ensure `pip` and `setuptools` are up-to-date (`pip install --upgrade pip setuptools`). On Windows, install Microsoft Visual C++ Build Tools (e.g., from Visual Studio Installer). On Linux/macOS, ensure a C compiler (like `gcc` or `clang`) is installed. Consider using a `conda` environment if `pip` wheels are consistently unavailable.
First, ensure `qdldl` is installed in your active environment by running `pip install qdldl`. If you've already installed it, verify that you are running your script with the same Python interpreter where the package was installed (e.g., check `which python` and `which pip` in your terminal).
Convert your input matrix to `scipy.sparse.csc_matrix` format before passing it to `qdldl.factor()`. Example: `from scipy.sparse import csc_matrix; P_sparse = csc_matrix(P_dense)`.
Examine the properties of your input matrices (`P` and `A`). Ensure `P` is positive semi-definite on the null space of `A`. Check for singularity, extreme ill-conditioning, or other numerical instabilities. You might need to add a small regularization term (e.g., to the diagonal of `P`) or pre-condition your system.