Arbitrary Precision
COSMO allows you to solve problems with arbitrary floating-point precision, e.g. by using BigFloat
problem data. To do this, the desired floating point type has to be consistent across the model COSMO.Model{<: AbstractFloat}
, the input data and the (optional) settings object COSMO.Settings{<: AbstractFloat}
. As an example, assume we want to solve the following quadratic program:
\[\begin{array}{ll} \text{minimize} & 1/2 x^\top P x + q^\top x \\ \text{subject to} & l \leq A x \leq u \end{array}\]
where $P = \begin{bmatrix} 4 & 1 \\ 1 & 2\end{bmatrix}$, $q = [1, 1]^\top$, $A = \begin{bmatrix} 1 & 1 \\ 1 & 0 \\ 0 & 1\end{bmatrix}$ and $l= [1,0, 0]^\top$, $u=[1, 0.7, 0.7]^\top$. We start by creating the model with the desired precision:
using COSMO, LinearAlgebra, SparseArrays
model = COSMO.Model{BigFloat}()
A COSMO Model with Float precision: BigFloat
Next, we define the problem data as BigFloat
arrays and create the constraint:
q = BigFloat[1; 1.]
P = sparse(BigFloat[4. 1; 1 2])
A = BigFloat[1. 1; 1 0; 0 1]
l = BigFloat[1.; 0; 0]
u = BigFloat[1; 0.7; 0.7]
constraint = COSMO.Constraint(A, zeros(BigFloat, 3), COSMO.Box(l, u))
Constraint{BigFloat}
Size of A: (3, 2)
ConvexSet: COSMO.Box{BigFloat}
Notice that the constraint type parameter is dependent on the input data. The same is true for the constraint set Box
. Next, we define the settings
settings = COSMO.Settings{BigFloat}(verbose = true, kkt_solver = QdldlKKTSolver)
A COSMO.Settings{BigFloat} object. To list the available options type `?` and `help?>COSMO.Settings`.
and assemble and solve the problem:
assemble!(model, P, q, constraint, settings = settings)
result = COSMO.optimize!(model);
------------------------------------------------------------------
COSMO v0.8.9 - A Quadratic Objective Conic Solver
Michael Garstka
University of Oxford, 2017 - 2022
------------------------------------------------------------------
Problem: x ∈ R^{2},
constraints: A ∈ R^{3x2} (4 nnz),
matrix size to factor: 5x5,
Floating-point precision: BigFloat
Sets: Box of dim: 3
Settings: ϵ_abs = 1.0e-05, ϵ_rel = 1.0e-05,
ϵ_prim_inf = 1.0e-04, ϵ_dual_inf = 1.0e-04,
ρ = 0.1, σ = 1e-06, α = 1.6,
max_iter = 5000,
scaling iter = 10 (on),
check termination every 25 iter,
check infeasibility every 40 iter,
KKT system solver: QDLDL
Acc: Anderson Type2{QRDecomp},
Memory size = 5, RestartedMemory,
Safeguarded: true, tol: 2.0
Setup Time: 1165.5ms
Iter: Objective: Primal Res: Dual Res: Rho:
1 -7.8808e-03 1.0079e+00 2.0033e+02 1.0000e-01
25 1.8800e+00 1.2972e-77 7.3280e-77 1.0000e-01
------------------------------------------------------------------
>>> Results
Status: Solved
Iterations: 25
Optimal objective: 1.88
Runtime: 3.289s (3289.4ms)
Moreover, notice that when no type parameter is specified, all objects default to Float64
:
model = COSMO.Model()
A COSMO Model with Float precision: Float64
Two limitations to arbitrary precision:
- Since we call the LAPACK function
syevr
for eigenvalue decompositions, we currently only support solving problems with PSD constraints inFloat32
andFloat64
. - We suggest to use the pure Julia QDLDL linear system solver (
kkt_solver = QdldlKKTSolver
) when working with arbitrary precision types as some of the other available solvers don't support all available precisions.
If you want to use COSMO
directly with MathOptInterface
, you can use: COSMO.Optimizer{<: AbstractFloat}
as your optimizer. Again, the problem data precision of your MathOptInterface-model has to agree with the optimizer's precision.
This page was generated using Literate.jl.