ECOS is a lightweight numerical solver for convex second-order cone programs (SOCPs) designed for embedded systems. This library provides its Python interface. It is actively maintained, with version 2.0.14 released in June 2024, and receives regular updates to its Python wrapper.
pip install ecosVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to solve a basic Linear Program (a special case of SOCP) using `ecos.solve`. It minimizes `x[0] + x[1]` subject to non-negativity and a lower bound constraint.
Upgrade your Python environment to Python 3.x.
If pinning, use `ecos>=2.0.7` or explicitly `ecos==2.0.7.post1`. It's generally safer to use the latest stable release.
Prefer `pip install ecos` to use pre-built wheels. If building from source on Windows, use Miniconda or ensure you have the correct Visual Studio compiler matching your Python version.
When using `CVXPY`, explicitly specify `solver=cvxpy.ECOS` in `prob.solve()`. Ensure `ecos` is installed in your environment if it's no longer a default dependency of `CVXPY`.
Ensure that your `G` and `A` sparse matrices are created as `scipy.sparse.csr_matrix` instances (e.g., `from scipy import sparse; G = sparse.csr_matrix(...)`).
Install the correct version of Microsoft Visual C++ Build Tools (e.g., from visualstudio.microsoft.com/downloads/#build-tools) matching your Python version, or try installing a pre-compiled wheel for `ecos` if available (e.g., from unofficial Windows binaries websites if `pip` fails to find one).
Ensure `numpy` and `scipy` are installed before attempting to install `ecos` by running `pip install numpy scipy` first.
Try rescaling your problem data so values have similar magnitudes, adjust solver parameters like `feastol`, `abstol`, `reltol` (tolerances), or increase `max_iters`. Also, ensure your problem is well-posed (feasible and bounded).
After `import ecos`, the main solving function is `ecos.solve()`. Call it directly with your problem parameters, e.g., `solution = ecos.solve(c, G, h, dims)`.