NumericalError when solving a simple unconstrained quadratic program
I have a 2x2 P matrix = [ 0.67795455, 1.1745795], [ 1.1745795, 2.7052722]
and q = [0.10088674, -0.15378475],
and it gives NumericalError, and [NaN, NaN] as solution. Is Clarabel not suitable for solving a unconstrained quadratic program like this?
The code is below:
use clarabel::solver::{DefaultSettingsBuilder, DefaultSolver, IPSolver};
use clarabel::{algebra::*, solver::SupportedConeT};
use nalgebra::Matrix2;
fn main() {
#[rustfmt::skip]
let P = Matrix2::new(
0.67795455, 1.1745795,
1.1745795, 2.7052722
);
// Define symmetric PSD matrix P
let P = CscMatrix::from(P.row_iter());
let q = vec![0.10088674, -0.15378475];
// No constraints
let A = CscMatrix::zeros((0, P.m));
let b = vec![];
// No cones
let cones: Vec<SupportedConeT<f32>> = vec![];
let settings = DefaultSettingsBuilder::default()
.verbose(true)
.build()
.unwrap();
let mut solver = DefaultSolver::new(&P, &q, &A, &b, &cones, settings);
solver.solve();
println!("Status: {:?}", solver.solution.status);
println!("Solution: {:?}", solver.solution.x);
}
The solver should not have of an issue with unconstrained problems. I wonder if maybe it's because you made a 32 bit instance, which we have not heavily stress tested.
What output do you get if you use:
let cones: Vec<SupportedConeT<f64>> = vec![];
instead? Could you also post here the full output text from the solver?
Edit: I confirm that 32 bit solver instantiation is the problem, and f64 works fine. Note that we don't provide different defaults for 32 bit settings, and it is very likely that the defaults are too tight at lower precision. See the comment here for a suggestion of what settings to use, particularly at the bottom for the 32 bit case.
Yes, the f32 case starts to work once I change some of tol_* to the square root of their default values. (I haven't tested in general though)
And thanks for Clarabel, it is quite amazing! I use it for implementing the physics engine of my robotics simulator, and it is a key component of the joint constraint and contact constraint solver.