Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Clarabel.rs
Submodule Clarabel.rs updated 34 files
+1 −1 .github/workflows/ci.yml
+2 −2 Cargo.toml
+45 −0 python/clarabel/tests/test_get_info.py
+7 −1 python/clarabel/tests/test_json.py
+0 −1 src/algebra/dense/blas/cholesky.rs
+69 −52 src/algebra/dense/blas/svd.rs
+7 −10 src/algebra/dense/blas/syevr.rs
+88 −15 src/io/mod.rs
+62 −63 src/julia/ClarabelRs/src/interface.jl
+80 −0 src/julia/ClarabelRs/src/types.jl
+3 −3 src/julia/interface.rs
+80 −0 src/julia/types.rs
+200 −14 src/python/impl_default_py.rs
+2 −0 src/python/module_py.rs
+15 −5 src/qdldl/qdldl.rs
+1 −1 src/qdldl/test.rs
+194 −1 src/solver/core/cones/supportedcone.rs
+27 −8 src/solver/core/kktsolvers/direct/quasidef/directldlkktsolver.rs
+84 −0 src/solver/core/kktsolvers/direct/quasidef/ldlsolvers/auto.rs
+45 −24 src/solver/core/kktsolvers/direct/quasidef/ldlsolvers/faer_ldl.rs
+16 −0 src/solver/core/kktsolvers/direct/quasidef/ldlsolvers/mod.rs
+37 −11 src/solver/core/kktsolvers/direct/quasidef/ldlsolvers/qdldl.rs
+7 −5 src/solver/core/kktsolvers/direct/quasidef/mod.rs
+21 −1 src/solver/core/kktsolvers/mod.rs
+11 −7 src/solver/implementations/default/info.rs
+93 −100 src/solver/implementations/default/info_print.rs
+9 −0 src/solver/implementations/default/kktsystem.rs
+13 −6 src/solver/implementations/default/problemdata.rs
+3 −2 src/solver/implementations/default/settings.rs
+6 −4 src/solver/implementations/default/solver.rs
+1 −0 src/solver/mod.rs
+25 −0 tests/basic_qp.rs
+9 −0 tests/mixed_conic.rs
+8 −0 tests/print_streams.rs
10 changes: 9 additions & 1 deletion examples/c/example_qp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// #define CLARABEL_USE_FLOAT

#include "utils.h"

#include <stdio.h>
#include <Clarabel.h>

int main(void)
Expand Down Expand Up @@ -66,6 +66,14 @@ int main(void)
ClarabelDefaultSolution solution = clarabel_DefaultSolver_solution(solver);
print_solution(&solution);

// Get some detailed solve information
ClarabelDefaultInfo_f64 info = clarabel_DefaultSolver_info(solver);
printf("primal residual = %e\n", info.res_primal);
printf("dual residual = %e\n", info.res_dual);
printf("# of threads = %d\n", info.linsolver.threads);
printf("KKT nonzeros = %d\n", info.linsolver.nnzA);
printf("factor nonzeros = %d\n", info.linsolver.nnzL);

// Free the matrices and the solver
clarabel_DefaultSolver_free(solver);

Expand Down
10 changes: 9 additions & 1 deletion examples/cpp/example_qp.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "utils.h"

#include <iostream>
#include <Clarabel>
#include <Eigen/Eigen>
#include <vector>
Expand Down Expand Up @@ -56,5 +56,13 @@ int main(void)
DefaultSolution<double> solution = solver.solution();
utils::print_solution(solution);

// Get some detailed solve information
DefaultInfo<double> info = solver.info();
std::cout << "primal residual = " << info.res_primal << std::endl;
std::cout << "dual residual = " << info.res_dual << std::endl;
std::cout << "# of threads = " << info.linsolver.threads << std::endl;
std::cout << "KKT nonzeros = " << info.linsolver.nnzA << std::endl;
std::cout << "factor nonzeros = " << info.linsolver.nnzL << std::endl;

return 0;
}
1 change: 1 addition & 0 deletions examples/cpp/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ namespace utils
printf("Slacks (s)\t = ");
print_array(solution.s);
}

}

#endif /* UTILS_H */
2 changes: 1 addition & 1 deletion include/Clarabel
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#define CLARABEL_H

#include "cpp/CscMatrix.h"
#include "cpp/DefaultInfo.h"
#include "cpp/DefaultSettings.h"
#include "cpp/DefaultInfo.h"
#include "cpp/DefaultSolution.h"
#include "cpp/DefaultSolver.h"
#include "cpp/SupportedConeT.h"
Expand Down
2 changes: 1 addition & 1 deletion include/Clarabel.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#define CLARABEL_H

#include "c/CscMatrix.h"
#include "c/DefaultInfo.h"
#include "c/DefaultSettings.h"
#include "c/DefaultInfo.h"
#include "c/DefaultSolution.h"
#include "c/DefaultSolver.h"
#include "c/SupportedConeT.h"
Expand Down
17 changes: 17 additions & 0 deletions include/c/DefaultInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,23 @@
#define CLARABEL_DEFAULT_INFO_H

#include "ClarabelTypes.h"
#include "DefaultSettings.h"
#include "DefaultSolution.h"

#include <stdint.h>


typedef struct ClarabelLinearSolverInfo
{
ClarabelDirectSolveMethods name;
uint32_t threads;
bool direct;
uint32_t nnzA;
uint32_t nnzL;
enum ClarabelSolverStatus status;
} ClarabelLinearSolverInfo;


// ClarabelDefaultInfo types
typedef struct ClarabelDefaultInfo_f64
{
Expand All @@ -24,6 +37,8 @@ typedef struct ClarabelDefaultInfo_f64
double ktratio;
double solve_time;
enum ClarabelSolverStatus status;
ClarabelLinearSolverInfo linsolver;
// NB : `PrintStream stream` not passed to C API
} ClarabelDefaultInfo_f64;

typedef struct ClarabelDefaultInfo_f32
Expand All @@ -43,6 +58,8 @@ typedef struct ClarabelDefaultInfo_f32
float ktratio;
double solve_time;
enum ClarabelSolverStatus status;
ClarabelLinearSolverInfo linsolver;
// NB : `PrintStream stream` not passed to C API
} ClarabelDefaultInfo_f32;

#ifdef CLARABEL_USE_FLOAT
Expand Down
1 change: 1 addition & 0 deletions include/c/DefaultSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
// ClarabelDefaultSettings types
typedef enum ClarabelDirectSolveMethods
{
AUTO,
QDLDL,
#ifdef FEATURE_FAER_SPARSE
FAER,
Expand Down
12 changes: 12 additions & 0 deletions include/cpp/DefaultInfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include "DefaultSettings.h"
#include "DefaultSolution.h"

#include <cstdint>
Expand All @@ -8,6 +9,16 @@
namespace clarabel
{


struct LinearSolverInfo
{
ClarabelDirectSolveMethods name;
uint32_t threads;
bool direct;
uint32_t nnzA;
uint32_t nnzL;
};

template<typename T = double>
struct DefaultInfo
{
Expand All @@ -28,6 +39,7 @@ struct DefaultInfo
T ktratio;
double solve_time;
clarabel::SolverStatus status;
clarabel::LinearSolverInfo linsolver;
// NB : `PrintStream stream` not passed to C++ API
};

Expand Down
1 change: 1 addition & 0 deletions include/cpp/DefaultSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace clarabel

enum class ClarabelDirectSolveMethods
{
AUTO,
QDLDL,
#ifdef FEATURE_FAER_SPARSE
FAER,
Expand Down
35 changes: 31 additions & 4 deletions rust_wrapper/src/solver/implementations/default/info.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
use clarabel::{algebra::FloatT, solver::DefaultInfo};
#![allow(non_snake_case)]

use clarabel::{algebra::FloatT, solver::DefaultInfo};
use clarabel::solver::LinearSolverInfo;
use crate::solver::implementations::default::solver::ClarabelSolverStatus;
use super::settings::ClarabelDirectSolveMethods;

#[repr(C)]
pub struct ClarabelLinearSolverInfo {
pub name: ClarabelDirectSolveMethods,
pub threads: u32,
pub direct: bool,
pub nnzA: u32,
pub nnzL: u32,
}

impl From<&LinearSolverInfo> for ClarabelLinearSolverInfo {
fn from(linsolver: &LinearSolverInfo) -> Self {
Self {
name: (&linsolver.name).into(),
threads: linsolver.threads as u32,
direct: linsolver.direct,
nnzA: linsolver.nnzA as u32,
nnzL: linsolver.nnzL as u32,
}
}
}

#[repr(C)]
pub struct ClarabelDefaultInfo<T> {
Expand All @@ -20,10 +44,12 @@ pub struct ClarabelDefaultInfo<T> {

pub solve_time: f64,
pub status: ClarabelSolverStatus,

pub linsolver: ClarabelLinearSolverInfo,
}

impl<T: FloatT> From<&mut DefaultInfo<T>> for ClarabelDefaultInfo<T> {
fn from(info: &mut DefaultInfo<T>) -> Self {
impl<T: FloatT> From<&DefaultInfo<T>> for ClarabelDefaultInfo<T> {
fn from(info: &DefaultInfo<T>) -> Self {
Self {
μ: info.μ,
sigma: info.sigma,
Expand All @@ -39,7 +65,8 @@ impl<T: FloatT> From<&mut DefaultInfo<T>> for ClarabelDefaultInfo<T> {
gap_rel: info.gap_rel,
ktratio: info.ktratio,
solve_time: info.solve_time,
status: ClarabelSolverStatus::from(&mut info.status),
status: ClarabelSolverStatus::from(&info.status),
linsolver: ClarabelLinearSolverInfo::from(&info.linsolver),
}
}
}
28 changes: 27 additions & 1 deletion rust_wrapper/src/solver/implementations/default/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,38 @@ use clarabel::algebra::FloatT;
#[allow(dead_code)]
#[allow(clippy::upper_case_acronyms)]
pub enum ClarabelDirectSolveMethods {
AUTO,
QDLDL,
#[cfg(feature = "faer-sparse")]
FAER,
// MKL, (not supported yet)
// CHOLMOD, (not supported yet)
}

impl From<&ClarabelDirectSolveMethods> for String {
fn from(value: &ClarabelDirectSolveMethods) -> Self {
match value {
ClarabelDirectSolveMethods::AUTO => String::from("auto"),
ClarabelDirectSolveMethods::QDLDL => String::from("qdldl"),
#[cfg(feature = "faer-sparse")]
ClarabelDirectSolveMethods::FAER => String::from("faer"),
}
}
}

impl From<&String> for ClarabelDirectSolveMethods {
fn from(value: &String) -> Self {
match value.as_str() {
"auto" => ClarabelDirectSolveMethods::AUTO,
"qdldl" => ClarabelDirectSolveMethods::QDLDL,
#[cfg(feature = "faer-sparse")]
"faer" => ClarabelDirectSolveMethods::FAER,
_ => ClarabelDirectSolveMethods::AUTO,
}
}
}


#[allow(non_camel_case_types)]
#[cfg(feature = "sdp")]
#[repr(C)]
Expand Down Expand Up @@ -102,10 +127,11 @@ fn _internal_DefaultSettings_default<T: FloatT>() -> ClarabelDefaultSettings<T>
let default = clarabel::solver::DefaultSettings::<T>::default();

let default_direct_solver_setting = match default.direct_solve_method.as_str() {
"auto" => ClarabelDirectSolveMethods::AUTO,
"qdldl" => ClarabelDirectSolveMethods::QDLDL,
//"mkl" => ClarabelDirectSolveMethods::MKL,
//"cholmod" => ClarabelDirectSolveMethods::CHOLMOD,
_ => ClarabelDirectSolveMethods::QDLDL, // Default
_ => ClarabelDirectSolveMethods::AUTO, // Default
};

#[cfg(feature = "sdp")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl<T: FloatT> DefaultSolution<T> {
z_length: solution.z.len(),
s: solution.s.as_mut_ptr(),
s_length: solution.s.len(),
status: ClarabelSolverStatus::from(&mut solution.status),
status: ClarabelSolverStatus::from(&solution.status),
obj_val: solution.obj_val,
obj_val_dual: solution.obj_val_dual,
solve_time: solution.solve_time,
Expand Down
6 changes: 3 additions & 3 deletions rust_wrapper/src/solver/implementations/default/solver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,8 @@ pub enum ClarabelSolverStatus {
ClarabelInsufficientProgress,
}

impl From<&mut SolverStatus> for ClarabelSolverStatus {
fn from(value: &mut SolverStatus) -> Self {
impl From<&SolverStatus> for ClarabelSolverStatus {
fn from(value: &SolverStatus) -> Self {
match value {
SolverStatus::Unsolved => ClarabelSolverStatus::ClarabelUnsolved,
SolverStatus::Solved => ClarabelSolverStatus::ClarabelSolved,
Expand Down Expand Up @@ -418,7 +418,7 @@ fn _internal_DefaultSolver_info<T: FloatT>(solver: *mut c_void) -> ClarabelDefau
let solver = unsafe { &mut *(solver as *mut lib::DefaultSolver<T>) };

// Get the info field and convert it to a C struct.
ClarabelDefaultInfo::<T>::from(&mut solver.info)
ClarabelDefaultInfo::<T>::from(&solver.info)
}

#[no_mangle]
Expand Down
9 changes: 1 addition & 8 deletions rust_wrapper/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,7 @@ pub fn get_solver_settings_from_c<T: FloatT>(
min_terminate_step_length: value.min_terminate_step_length,
max_threads: value.max_threads,
direct_kkt_solver: value.direct_kkt_solver,
direct_solve_method: match value.direct_solve_method {
ClarabelDirectSolveMethods::QDLDL => String::from("qdldl"),
#[cfg(feature = "faer-sparse")]
ClarabelDirectSolveMethods::FAER => String::from("faer"),
// Not supported yet
//ClarabelDirectSolveMethods::MKL => String::from("mkl"),
//ClarabelDirectSolveMethods::CHOLMOD => String::from("cholmod"),
},
direct_solve_method: (&value.direct_solve_method).into(),
static_regularization_enable: value.static_regularization_enable,
static_regularization_constant: value.static_regularization_constant,
static_regularization_proportional: value.static_regularization_proportional,
Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ add_executable(clarabel_cpp_tests
mixed_conic.cpp
data_updating.cpp
sdp_chordal.cpp
get_info.cpp
)
target_link_libraries(clarabel_cpp_tests
libclarabel_c_shared
Expand Down