PICOS: A Python interface to conic optimization solvers#
![PICOS logo](/_static/picos-logo.png)
PICOS is a Python API that offers a convenient interface to various conic and integer programming solvers. Through PICOS, users can define optimization problems using high-level models, which support intricate vector, matrix variables, and multidimensional algebra. Once the problem is defined, PICOS automatically converts it into a format that’s comprehensible by any suitable solver present during runtime. This flexibility ensures that applications remain adaptable, giving users the liberty to select from multiple commercial or open-source solvers.
As with CVXPY, CORNETO allows to use PICOS as a backend for solving optimization problems. While CVXPY and PICOS have similar philosophy, their specific features, functions, and supported solvers might differ. Users might opt for one over the other based on individual needs or preferences.
CORNETO can be seen also as a multi-backend implementation of PICOS and CVXPY. You can choose the backend you prefer, and CORNETO will take care of the rest.
import corneto as cn
cn.info()
|
|
import numpy as np
from corneto.backend import PicosBackend
backend = PicosBackend()
P = backend.Problem()
A = np.array([[0.12, 0.92, 0.76, 0.98, 0.79], [0.58, 0.57, 0.53, 0.71, 0.55]])
b = np.array([1, 0])
x = backend.Variable("x", A.shape[1])
P += sum(x) == 1, x >= 0
# Convex optimization problem
P.add_objectives(sum(A @ x - b))
picos_model = P.solve(solver="cvxopt", verbosity=1)
===================================
PICOS 2.4.17
===================================
Problem type: Linear Program.
Searching a solution strategy for CVXOPT.
Solution strategy:
1. ExtraOptions
2. CVXOPTSolver
Applying ExtraOptions.
Building a CVXOPT problem instance.
Starting solution search.
-----------------------------------
Python Convex Optimization Solver
via internal CONELP solver
-----------------------------------
pcost dcost gap pres dres k/t
0: 1.3020e+00 1.3020e+00 2e+00 2e-16 1e+00 1e+00
1: 1.1568e+00 1.1401e+00 5e-01 1e-16 3e-01 3e-01
2: 7.4020e-01 7.0348e-01 1e-01 3e-16 8e-02 3e-02
3: 7.0098e-01 7.0046e-01 2e-03 1e-16 1e-03 4e-04
4: 7.0001e-01 7.0000e-01 2e-05 2e-16 1e-05 4e-06
5: 7.0000e-01 7.0000e-01 2e-07 1e-16 1e-07 4e-08
6: 7.0000e-01 7.0000e-01 2e-09 1e-16 1e-09 4e-10
Optimal solution found.
------------[ CVXOPT ]-------------
Solver claims optimal solution for feasible problem.
Applying the solution.
Applied solution is primal feasible.
Search 1.4e-02s, solve 1.8e-02s, overhead 31%.
=============[ PICOS ]=============
P.symbols
{'x': <5×1 Real Variable: x>}
sum(P.symbols["x"].value)
1.0000000000000002
type(P)
corneto.backend._base.ProblemDef
P.objectives
[<1×1 Real Affine Expression: ([2×5]·x - [2×1])[0] + ([2×5]·x - [2×1])[1]>]
P.objectives[0].value
-0.29999999901748486
type(picos_model)
picos.modeling.problem.Problem
picos_model.value
-0.29999999901748486
type(A @ x)
corneto.backend._picos_backend.PicosExpression
type((A @ x).e)
picos.expressions.exp_affine.AffineExpression