Convex.jl Interface
Clarabel.jl implements support for MathOptInterface, and is therefore compatible with Convex.jl. This allows you to describe and modify your optimisation problem with Convex.jl and use Clarabel as the backend solver.
Setting Clarabel.jl Backend
You should construct your problem in the usual way in Convex.jl, and then solve using Clarabel.Optimizer
, i.e. by calling solve!
with
solve!(problem, Clarabel.Optimizer)
where problem
is an object of type Convex.Problem
.
Convex.jl or JuMP?
Clarabel.jl supports both Convex.jl and JuMP via MathOptInterface. Both packages are excellent and can make problem construction considerably easier than via the solver's native interface.
For problems with quadratic objective functions, JuMP is generally preferred when using Clarabel.jl since it will keep the quadratic function in the objective rather than reformulating the problem to a form with a linear cost and additional second-order cone constraints. Clarabel.jl natively supports quadratic objectives and solve times are generally faster if this reformulation is avoided.
Arbitrary Precision Arithmetic
Clarabel.jl supports arbitrary precision arithmetic for Convex.jl. Here is the Basic QP Example implemented using BigFloat
types.
#hide setprecision(BigFloat,256)
using Clarabel, Convex
x = Variable(2)
objective = 3square(x[1]) + 2square(x[2]) - x[1] - 4x[2]
problem = minimize(objective; numeric_type = BigFloat)
problem.constraints = [x[1] == 2x[2]]
problem.constraints += [x >= -1; x <= 1]
solve!(problem, Clarabel.Optimizer{BigFloat}; silent_solver = false)
-------------------------------------------------------------
Clarabel.jl v0.5.0 - Clever Acronym
(c) Paul Goulart
University of Oxford, 2022
-------------------------------------------------------------
problem:
variables = 5
constraints = 14
nnz(P) = 0
nnz(A) = 17
cones (total) = 4
: Zero = 1, numel = 2
: Nonnegative = 1, numel = 6
: SecondOrder = 2, numel = (3,3)
settings:
linear algebra: direct / qdldl, precision: BigFloat (128 bit)
max iter = 200, time limit = Inf, max step = 0.990
tol_feas = 1.0e-08, tol_gap_abs = 1.0e-08, tol_gap_rel = 1.0e-08,
static reg : on, ϵ1 = 1.0e-08, ϵ2 = 4.9e-32
dynamic reg: on, ϵ = 1.0e-13, δ = 2.0e-07
iter refine: on, reltol = 1.0e-13, abstol = 1.0e-12,
max iter = 10, stop ratio = 5.0
equilibrate: on, min_scale = 1.0e-04, max_scale = 1.0e+04
max iter = 10
iter pcost dcost gap pres dres k/t μ step
---------------------------------------------------------------------------------------------
0 5.9257e-39 -1.4716e+01 1.47e+01 6.17e-01 3.25e-01 1.00e+00 3.37e+00 ------
1 -1.0868e+00 -3.6775e+00 2.38e+00 1.44e-01 6.44e-02 4.78e-01 7.87e-01 9.90e-01
2 -7.0595e-01 -8.7396e-01 1.68e-01 8.52e-03 3.91e-03 2.62e-02 5.45e-02 9.41e-01
3 -6.4512e-01 -6.5074e-01 5.62e-03 2.82e-04 1.30e-04 8.81e-04 1.84e-03 9.66e-01
4 -6.4311e-01 -6.4380e-01 6.85e-04 3.44e-05 1.59e-05 1.09e-04 2.24e-04 8.86e-01
5 -6.4289e-01 -6.4301e-01 1.15e-04 5.79e-06 2.67e-06 1.86e-05 3.78e-05 8.43e-01
6 -6.4286e-01 -6.4287e-01 1.14e-05 5.75e-07 2.66e-07 1.89e-06 3.76e-06 9.13e-01
7 -6.4286e-01 -6.4286e-01 2.84e-07 1.44e-08 6.63e-09 4.79e-08 9.38e-08 9.77e-01
8 -6.4286e-01 -6.4286e-01 1.46e-08 1.16e-09 3.40e-10 2.46e-09 4.81e-09 9.49e-01
9 -6.4286e-01 -6.4286e-01 2.53e-09 1.56e-09 5.91e-11 4.30e-10 8.36e-10 8.37e-01
---------------------------------------------------------------------------------------------
Terminated with status = solved
solve time = 37.4ms
This page was generated using Literate.jl.