Clarabel Conic Interior Point Solver for Rust / Python
Clarabel is an interior point numerical solver for convex optimization problems, implemented in Rust and featuring a Python interface. It efficiently solves a variety of conic programs including Linear Programs (LPs), Quadratic Programs (QPs), Second-Order Cone Programs (SOCPs), Semidefinite Programs (SDPs), and problems with exponential and power cone constraints. The current version is 0.11.1, and the library maintains an active release cadence.
Warnings
- gotcha Clarabel's default solver settings are optimized for 64-bit float data. Using 32-bit floats (e.g., `np.float32`) may lead to suboptimal performance or numerical inaccuracies unless solver tolerances are explicitly relaxed.
- gotcha When updating problem data (e.g., in iterative algorithms), modifications to the `cones` array are not permitted. Additionally, data updates are disallowed if `settings.chordal_decomposition_enable = True` or `settings.presolve_enable = True`.
- gotcha Clarabel expects sparse matrix data (P and A) to be in Compressed Sparse Column (CSC) format, as produced by `scipy.sparse`. For the quadratic objective matrix `P`, only its upper triangular part should be provided in CSC format.
- breaking From Clarabel version 0.11.0 onwards, the version string is accessed via `clarabel.__version__` (an attribute) instead of `clarabel.__version__()` (a method).
- deprecated Starting with CVXPY 1.5, Clarabel has become the default interior-point solver, replacing ECOS. CVXPY 1.6 will entirely remove ECOS as a dependency. Users relying on ECOS's specific behavior via CVXPY might experience regressions.
Install
-
pip install clarabel
Imports
- clarabel
import clarabel
- numpy
import numpy as np
- sparse
from scipy import sparse
- DefaultSolver
clarabel.DefaultSolver
- __version__
clarabel.__version__
Quickstart
import clarabel
import numpy as np
from scipy import sparse
# Define problem data for a simple QP: minimize 0.5 * x.T * P * x + q.T * x
# subject to A * x + s = b, s in K
P = sparse.csc_matrix([[3., 1., -1.], [1., 4., 2.], [-1., 2., 5.]])
P = sparse.triu(P).tocsc() # Clarabel expects upper triangular part in CSC format
q = np.array([1., 2., -3.])
A = sparse.csc_matrix([
[1., 1., -1.], # Equality constraint (ZeroConeT)
[0., 1., 0.], # Inequality constraint (NonnegativeConeT)
[0., 0., 1.], # Inequality constraint (NonnegativeConeT)
[0., 0., 0.] # Placeholder for SOC (SecondOrderConeT)
])
b = np.array([1., 2., 2., 0.])
# Define cone constraints: ZeroConeT(dim), NonnegativeConeT(dim), SecondOrderConeT(dim)
cones = [clarabel.ZeroConeT(1), clarabel.NonnegativeConeT(2), clarabel.SecondOrderConeT(1)]
# Instantiate and solve the solver
settings = clarabel.DefaultSettings()
settings.verbose = False # Disable verbose output
solver = clarabel.DefaultSolver(P, q, A, b, cones, settings)
solver.solve()
# Print results
print(f"Solution x: {solver.solution.x}")
print(f"Objective value: {solver.solution.obj_val}")
print(f"Solver status: {solver.solution.status}")