CVXOPT is a Python package for convex optimization. It provides a dense and sparse matrix object type and an extensive library of solvers for linear programs, quadratic programs, semidefinite programs, and general convex optimization problems. The current version is 1.3.3, and it receives active maintenance, primarily through bug fixes and Python version compatibility updates (e.g., Python 3.8+ is generally recommended).
pip install cvxoptVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to solve a simple Linear Program (LP) using `cvxopt.solvers.lp`. It sets up the objective function vector `c`, the inequality constraint matrix `G`, and the right-hand side vector `h`, then invokes the solver to find the optimal solution.
Always convert NumPy arrays to `cvxopt.matrix` using `matrix(numpy_array)` before passing them to CVXOPT solvers. Be mindful of column-major vs. row-major order when converting.
For most users, `pip install cvxopt` should suffice. If experiencing issues or needing optimized performance, consult the official CVXOPT documentation for instructions on linking to specific BLAS/LAPACK implementations (e.g., OpenBLAS, MKL). Consider using a Python distribution like Anaconda, which often bundles optimized numerical libraries.
Benchmark CVXOPT against other solvers for your specific problem scale and type. Consider using `cvxpy` as a modeling layer if you need flexibility to switch between different backend solvers (including CVXOPT) without changing your problem formulation.
Try installing pre-compiled binary wheels if available for your Python version (e.g., from Christoph Gohlke's repository for Windows), or use a robust package manager like `conda` (`conda install -c conda-forge cvxopt`). If installing via `pip` on Windows, ensure you have the appropriate Visual C++ Build Tools installed and a NumPy version linked against MKL or OpenBLAS.
Activate the correct Python virtual environment (if using one) and install cvxopt using `pip install cvxopt`. Verify the installation by running `pip show cvxopt`.
Review the mathematical formulation of your optimization problem. Check the rank of your constraint matrices (e.g., using `numpy.linalg.matrix_rank`) to ensure they are independent and that the problem is well-posed. Address any redundancies or inconsistencies in your constraints. Sometimes, scaling the input matrices can also improve numerical stability.
Replace parentheses `()` with square brackets `[]` when attempting to access elements or slice a NumPy array. If you are mixing `cvxopt.matrix` and `numpy.ndarray` objects, ensure you are using the correct syntax for each type, and explicitly convert between them if necessary (e.g., `cvxopt.matrix(numpy_array)` or `numpy.array(cvxopt_matrix)`).
Install BLAS/LAPACK development libraries (e.g., `sudo apt-get install libblas-dev liblapack-dev` on Ubuntu/Debian, `brew install openblas lapack` on macOS) then reinstall `cvxopt` via `pip install cvxopt`. Alternatively, use `conda install cvxopt`, which typically handles these dependencies automatically.