---
title: "CVXPY"
source: https://www.jemoka.com/posts/kbhcvxpy/
---

CVXPY allows us to cast convex optimization tasks into OOP code.
\begin{align} \min \mid Ax - b \mid^{2}_{2} \end{align}
object to:
\(x \geq 0\)
import cvxpy as cp A,b = ... x = cp.Variable(n) obj = cp.norm2(A@x - b)**2 constraints = [x &gt;= 0] prob = cp.Problem(cp.Minimize(obj), constraints) prob.solve() How it works starts with the optimization problem \(P_{1}\) applies a series of problem transformation \(P_{2} &hellip; P_{N}\) final problem \(P_{N}\) should be one of Linear Program, Quadratic Program, SOCP, SDP calls a specialized solver on \(P_{N}\) retrieves the solution of the original problem by reversing transformations
