{"id":4490,"library":"cvxopt","title":"CVXOPT: Convex Optimization Package","description":"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).","status":"active","version":"1.3.3","language":"en","source_language":"en","source_url":"https://github.com/cvxopt/cvxopt","tags":["optimization","convex-optimization","mathematics","solvers","numerical-computing"],"install":[{"cmd":"pip install cvxopt","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Required for numerical operations and data structures underlying cvxopt.matrix.","package":"numpy","optional":false}],"imports":[{"note":"While 'import cvxopt.matrix' works, importing `matrix` directly is more common for convenience when frequently using the type.","wrong":"import cvxopt.matrix","symbol":"matrix","correct":"from cvxopt import matrix"},{"note":"Similar to `matrix`, `solvers` is typically imported directly for cleaner access to solver functions like `solvers.lp`.","wrong":"import cvxopt.solvers","symbol":"solvers","correct":"from cvxopt import solvers"}],"quickstart":{"code":"from cvxopt import matrix, solvers\n\n# Minimize -4x_1 - 5x_2\n# Subject to:\n#   x_1 + 2x_2 <= 10\n#   3x_1 + 2x_2 <= 12\n#   x_1 >= 0, x_2 >= 0\n\n# Objective function c (coefficients of x_1, x_2)\nc = matrix([-4.0, -5.0])\n\n# Inequality constraints Gx <= h\n# G for x_1 + 2x_2 <= 10  (row 1)\n# G for 3x_1 + 2x_2 <= 12  (row 2)\n# G for x_1 >= 0  (i.e., -x_1 <= 0, row 3)\n# G for x_2 >= 0  (i.e., -x_2 <= 0, row 4)\nG = matrix([[1.0, 3.0, -1.0, 0.0], \n            [2.0, 2.0, 0.0, -1.0]]) # Note: CVXOPT matrix is column-major\nh = matrix([10.0, 12.0, 0.0, 0.0])\n\n# Solve the linear program\nsol = solvers.lp(c, G, h)\n\n# Print optimal values\nprint('Optimal solution:')\nprint(f'x_1 = {sol[\"x\"][0]}')\nprint(f'x_2 = {sol[\"x\"][1]}')\nprint(f'Optimal objective value = {sol[\"primal objective\"]}')","lang":"python","description":"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."},"warnings":[{"fix":"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.","message":"CVXOPT's solvers primarily operate on its own `cvxopt.matrix` objects, which are distinct from NumPy arrays. While `cvxopt.matrix` can be initialized from NumPy arrays, direct use of NumPy arrays in solver inputs will raise type errors.","severity":"gotcha","affected_versions":"All versions"},{"fix":"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.","message":"Installation of CVXOPT, especially on Windows or when seeking high performance, can sometimes be challenging due to its dependency on external BLAS and LAPACK libraries. While `pip install` often works with pre-compiled wheels, custom builds may require careful configuration.","severity":"gotcha","affected_versions":"All versions"},{"fix":"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.","message":"For very large-scale convex optimization problems or specific problem types, CVXOPT might not offer the same performance or specialized algorithms as commercial solvers (e.g., Gurobi, MOSEK) or other open-source alternatives like CVXPY (which can interface with various backend solvers including CVXOPT).","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"}