{"id":4526,"library":"ecos","title":"Python Wrapper for Embedded Conic Solver (ECOS)","description":"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.","status":"active","version":"2.0.14","language":"en","source_language":"en","source_url":"https://github.com/embotech/ecos-python","tags":["optimization","solver","socp","convex-optimization","embedded-systems"],"install":[{"cmd":"pip install ecos","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"Required for numerical arrays (vectors/matrices) used as input.","package":"numpy","optional":false},{"reason":"Required for sparse matrix representation of constraints.","package":"scipy","optional":false}],"imports":[{"symbol":"ecos","correct":"import ecos"}],"quickstart":{"code":"import numpy as np\nfrom scipy import sparse\nimport ecos\n\n# Define a simple Linear Program (LP) as an SOCP\n# Minimize: x[0] + x[1]\n# Subject to: x[0] >= 0, x[1] >= 0, x[0] + x[1] >= 1\n\n# Objective vector c: Minimize x[0] + x[1]\nc = np.array([1., 1.])\n\n# Inequality constraints Gx <= h (linear cone part)\n# -x[0] <= 0\n# -x[1] <= 0\n# -x[0] - x[1] <= -1  (equivalent to x[0] + x[1] >= 1)\nG = sparse.csr_matrix([\n    [-1., 0.],\n    [0., -1.],\n    [-1., -1.]\n])\nh = np.array([0., 0., -1.])\n\n# Dimensions of the cones\ndims = {\n    'l': 3,  # Number of linear inequality constraints\n    'q': [], # List of second-order cone dimensions\n    'e': 0   # Number of exponential cone constraints\n}\n\n# Solve the problem\nsolution = ecos.solve(c, G, h, dims)\n\n# Print the optimal solution\nprint(f\"Optimal x: {solution['x']}\")\nprint(f\"Optimal value: {solution['info']['pcost']}\")","lang":"python","description":"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."},"warnings":[{"fix":"Upgrade your Python environment to Python 3.x.","message":"Starting with version 2.0.8, the `ecos-python` wrapper officially dropped support for Python 2.7. Users on older Python versions must upgrade to Python 3 or use an older `ecos` version.","severity":"breaking","affected_versions":">=2.0.8"},{"fix":"If pinning, use `ecos>=2.0.7` or explicitly `ecos==2.0.7.post1`. It's generally safer to use the latest stable release.","message":"The 2.0.7 release had issues with version syncing, leading to its removal and re-upload as a post-release (e.g., `2.0.7.post1`). Strict dependency pinning to `2.0.7` might fail.","severity":"gotcha","affected_versions":"2.0.7"},{"fix":"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.","message":"Installing `ecos` from source on Windows can be challenging due to compiler requirements, especially for older Python versions. The official documentation suggests using Miniconda to minimize pain.","severity":"gotcha","affected_versions":"All versions, specifically Windows source installs"},{"fix":"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`.","message":"The `CVXPY` library, which often uses ECOS as a solver, changed its default solver from ECOS to Clarabel in version 1.5 and plans to remove ECOS as a default dependency in 1.6. Users relying on ECOS via CVXPY should be aware.","severity":"gotcha","affected_versions":"CVXPY >= 1.5"},{"fix":"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(...)`).","message":"The `ecos.solve` function expects sparse matrices `G` and `A` to be in `scipy.sparse.csr_matrix` format. While it attempts to convert other formats, providing them in CSR format is more efficient and avoids potential conversion overhead or unexpected behavior.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}