Welcome to CVXPY¶
CVXPY 1.0 is under development. There will be some changes to the user interface.
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:
from cvxpy import * 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 = Variable(n) objective = Minimize(sum_squares(A*x - b)) constraints = [0 <= x, x <= 1] prob = 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.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 from Stephen Boyd and Eric Chu.