Welcome to CVXPY 1.0

Join the CVXPY mailing list and Gitter chat for the best CVXPY support!

CVXPY 1.0 is a major rewrite with many new features! See What’s New in CVXPY 1.0 for details on changes.

CVXPY is a Python-embedded modeling language for convex optimization problems. It allows you to express your problem in a natural way that follows the math, rather than in the restrictive standard form required by solvers.

For example, the following code solves a least-squares problem where the variable is constrained by lower and upper bounds:

import cvxpy as cvx
import numpy

# Problem data.
m = 30
n = 20
numpy.random.seed(1)
A = numpy.random.randn(m, n)
b = numpy.random.randn(m)

# Construct the problem.
x = cvx.Variable(n)
objective = cvx.Minimize(cvx.sum_squares(A*x - b))
constraints = [0 <= x, x <= 1]
prob = cvx.Problem(objective, constraints)

# The optimal objective is returned by prob.solve().
result = prob.solve()
# The optimal value for x is stored in x.value.
print x.value
# The optimal Lagrange multiplier for a constraint
# is stored in constraint.dual_value.
print constraints[0].dual_value

This short script is a basic example of what CVXPY can do. CVXPY also supports simple ways to solve problems in parallel, higher-level abstractions such as object oriented convex optimization, and extensions for non-convex optimization.

CVXPY was designed and implemented by Steven Diamond, with input and contributions from Stephen Boyd, Eric Chu, and many others.

CVXPY was inspired by the MATLAB package CVX. See the book Convex Optimization by Boyd and Vandenberghe for general background on convex optimization.

CVXPY relies on the open source solvers ECOS, OSQP, and SCS. Additional solvers are supported, but must be installed separately.