{"id":2452,"library":"cvxpy","title":"CVXPY","description":"CVXPY is a Python-embedded modeling language for convex optimization problems. It allows users to express optimization problems in a natural way that follows mathematical notation, automatically transforming them into standard form, calling a solver, and unpacking the results. It is actively maintained with frequent patch releases, and major versions (e.g., 1.8.x) are supported with bugfixes while the next major release (e.g., 1.9) is under development, with older major versions no longer officially supported.","status":"active","version":"1.8.2","language":"en","source_language":"en","source_url":"https://github.com/cvxpy/cvxpy","tags":["optimization","convex-optimization","mathematical-modeling","solver","numerical-computing"],"install":[{"cmd":"pip install cvxpy","lang":"bash","label":"Base installation"},{"cmd":"pip install cvxpy clarabel osqp scs highspy","lang":"bash","label":"With default open-source solvers"},{"cmd":"pip install cvxpy[full]","lang":"bash","label":"With all optional open-source solvers (may require system dependencies for some)"}],"dependencies":[{"reason":"Required runtime environment","package":"python","version":">=3.11"},{"reason":"Core array manipulation and mathematical operations","package":"numpy","version":">=2.0.0"},{"reason":"Scientific computing tools, often used in optimization","package":"scipy","version":">=1.13.0"},{"reason":"Default open-source interior-point solver","package":"clarabel","version":">=0.5.0"},{"reason":"Default open-source operator splitting solver","package":"osqp","version":">=1.0.0"},{"reason":"Default open-source conic solver","package":"scs","version":">=3.2.4.post1"},{"reason":"Default open-source mixed-integer linear programming (MILP) solver","package":"highspy","version":">=1.11.0"}],"imports":[{"note":"Importing all symbols with `*` can lead to namespace pollution and make code harder to read and debug. Using `import cvxpy as cp` is the standard and recommended practice.","wrong":"from cvxpy import *","symbol":"cp","correct":"import cvxpy as cp"},{"note":"NumPy is commonly used alongside CVXPY for data generation and manipulation.","symbol":"np","correct":"import numpy as np"}],"quickstart":{"code":"import cvxpy as cp\nimport numpy as np\n\n# Problem data.\nm = 30\nn = 20\nnp.random.seed(1)\nA = np.random.randn(m, n)\nb = np.random.randn(m)\n\n# Construct the problem.\nx = cp.Variable(n)\nobjective = cp.Minimize(cp.sum_squares(A @ x - b))\nconstraints = [0 <= x, x <= 1]\nprob = cp.Problem(objective, constraints)\n\n# The optimal objective value is returned by `prob.solve()`.\nresult = prob.solve()\n\n# The optimal value for x is stored in `x.value`.\nprint(\"Optimal x:\\n\", x.value)\n# The optimal Lagrange multiplier for a constraint is stored in\n# `constraint.dual_value`.\nprint(\"Dual value for 0 <= x constraint:\\n\", constraints[0].dual_value)","lang":"python","description":"This example demonstrates how to solve a least-squares problem with box constraints using CVXPY. It defines variables, an objective function, and constraints, then solves the problem and prints the optimal variable values and duals."},"warnings":[{"fix":"Ensure your Python environment is 3.11 or newer and NumPy is >= 2.0.0. Upgrade with `pip install --upgrade python numpy` if necessary (after updating Python itself).","message":"CVXPY 1.8.0 dropped support for Python 3.10 and NumPy versions older than 2.0.0.","severity":"breaking","affected_versions":">=1.8.0"},{"fix":"Upgrade to CVXPY 1.8.x or newer for continued support and bug fixes: `pip install --upgrade cvxpy`.","message":"CVXPY 1.7 and older major versions are no longer officially supported since the release of CVXPY 1.8.","severity":"deprecated","affected_versions":"<1.8.0"},{"fix":"Update your code to use the `@` operator for matrix multiplication and `cp.multiply` for element-wise multiplication. Example: `A @ x` instead of `A * x` for matrix-vector product.","message":"Matrix multiplication behavior changed: `*` is deprecated for matrix-matrix or matrix-vector multiplication. Use `@` for matrix multiplication and dot products. Use `*` for scalar multiplication. For element-wise multiplication, use `cp.multiply`.","severity":"gotcha","affected_versions":">=1.1"},{"fix":"Instead of modifying `prob.objective` or `prob.constraints` directly, create a new `cp.Problem(new_objective, new_constraints)`.","message":"Problems in CVXPY are immutable. If you need to change an objective or constraints (e.g., for parametric programming), you must construct a new `cp.Problem` instance.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Replace Python built-ins with their CVXPY equivalents, e.g., `cp.sum(expr)` instead of `sum(expr)`.","message":"For atoms like `cp.sum`, `cp.sum_squares`, `cp.maximum`, `cp.minimum`, always use the CVXPY versions from the `cp` module instead of Python's built-in `sum()`, `max()`, `min()`. The built-in functions do not integrate with CVXPY's modeling language.","severity":"gotcha","affected_versions":"All versions"},{"fix":"If specific solver behavior is critical, explicitly set the solver parameter: `prob.solve(solver='ECOS_BB')` or `prob.solve(solver='GLPK_MI')`, etc.","message":"CVXPY 1.8 changed the default solver for Mixed-Integer Linear Programs (MILPs) from ECOS_BB (or similar) to HiGHS. If you relied on the behavior or performance of a specific default solver, explicitly specify it using `prob.solve(solver='ECOS_BB')`.","severity":"gotcha","affected_versions":">=1.8.0"}],"env_vars":null,"last_verified":"2026-04-10T00:00:00.000Z","next_check":"2026-07-09T00:00:00.000Z"}