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 with box constraints:

importcvxpyascpimportnumpyasnp# Problem data.m=30n=20np.random.seed(1)A=np.random.randn(m,n)b=np.random.randn(m)# Construct the problem.x=cp.Variable(n)objective=cp.Minimize(cp.sum_squares(A*x-b))constraints=[0<=x,x<=1]prob=cp.Problem(objective,constraints)# The optimal objective value 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; in addition
to convex programming, CVXPY also supports a generalization of geometric
programming.

For a guided tour of CVXPY, check out the tutorial. Browse the library of examples for applications to machine learning, control, finance, and
more.

Version 1.0 of CVXPY brings the API closer to NumPy
and the architecture closer to software compilers, making it easy for
developers to write custom problem transformations and target custom solvers.
CVXPY 1.0 is not backwards compatible with previous versions
of CVXPY. For more details, see What’s New in 1.0, which includes instructions
for migrating from previous versions of CVXPY.

CVXPY relies on the open source solvers ECOS, OSQP, and SCS.
Additional solvers are supported, but must be installed separately. For
background on convex optimization, see the book Convex Optimization by Boyd and Vandenberghe.

CVXPY was designed and implemented by Steven Diamond, with input and
contributions from Stephen Boyd, Eric Chu, Akshay Agrawal, Robin Verschueren,
and many others; it was inspired by the MATLAB package CVX.