Skip to content

Commit

Permalink
v0.9.0 updates (#41)
Browse files Browse the repository at this point in the history
* adds optional JSON file read/write support
* adds optional faer-rs support
  • Loading branch information
goulart-paul authored Jun 3, 2024
1 parent d8adc52 commit c3a7b1e
Show file tree
Hide file tree
Showing 21 changed files with 402 additions and 19 deletions.
15 changes: 13 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.13)

# Project properties
set(CLARABEL_PROJECT_VERSION 0.8.0)
set(CLARABEL_PROJECT_VERSION 0.9.0)
project(Clarabel VERSION ${CLARABEL_PROJECT_VERSION})

# Specify the default C++ standard applied to all targets
Expand All @@ -12,7 +12,9 @@ set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED True)

# SDP feature configuration
#----------------------------------------------
# Clarabel feature configuration
#----------------------------------------------
set(CLARABEL_FEATURE_SDP "none" CACHE STRING "Package for SDP to be selected")
set_property(CACHE CLARABEL_FEATURE_SDP PROPERTY STRINGS
none
Expand All @@ -23,6 +25,15 @@ set_property(CACHE CLARABEL_FEATURE_SDP PROPERTY STRINGS
sdp-r
)

option(CLARABEL_FEATURE_SERDE "Enable clarabel `serde` option " OFF)
option(CLARABEL_FEATURE_FAER_SPARSE "Enable `faer-sparse` option" OFF)
option(CLARABEL_FEATURE_SERDE "Enable `faer-sparse` option" OFF)


#----------------------------------------------
#----------------------------------------------


# Get dependencies

# Eigen3
Expand Down
2 changes: 1 addition & 1 deletion Clarabel.rs
Submodule Clarabel.rs updated 41 files
+4 −0 .github/codecov.yml
+1 −1 .github/workflows/ci.yml
+19 −11 .github/workflows/pypi.yaml
+20 −13 .github/workflows/testpypi.yaml
+22 −1 CHANGELOG.md
+8 −0 CITATION.bib
+46 −3 Cargo.toml
+13 −1 README.md
+1 −0 examples/data/hs35.json
+14 −0 examples/python/example_json.py
+1 −1 examples/rust/example_box.rs
+39 −0 examples/rust/example_box_faer.rs
+19 −0 examples/rust/example_json.rs
+6 −1 src/algebra/csc/core.rs
+32 −35 src/algebra/floats.rs
+1 −1 src/algebra/matrix_traits.rs
+4 −4 src/algebra/scalarmath.rs
+3 −0 src/algebra/tests/vector.rs
+9 −9 src/algebra/utils.rs
+2 −2 src/algebra/vecmath.rs
+2 −2 src/julia/ClarabelRs/Project.toml
+47 −0 src/julia/ClarabelRs/src/interface.jl
+5 −0 src/julia/ClarabelRs/src/types.jl
+78 −4 src/julia/interface.rs
+26 −3 src/python/impl_default_py.rs
+2 −0 src/python/module_py.rs
+78 −41 src/qdldl/qdldl.rs
+5 −5 src/qdldl/test.rs
+8 −5 src/solver/core/cones/supportedcone.rs
+7 −2 src/solver/core/kktsolvers/direct/quasidef/directldlkktsolver.rs
+390 −0 src/solver/core/kktsolvers/direct/quasidef/ldlsolvers/faer_ldl.rs
+2 −0 src/solver/core/kktsolvers/direct/quasidef/ldlsolvers/mod.rs
+8 −0 src/solver/core/solver.rs
+135 −0 src/solver/implementations/default/json.rs
+3 −0 src/solver/implementations/default/mod.rs
+2 −2 src/solver/implementations/default/problemdata.rs
+114 −3 src/solver/implementations/default/settings.rs
+1 −1 src/solver/implementations/default/variables.rs
+5 −1 src/solver/mod.rs
+10 −1 src/timers/timers.rs
+3 −2 tests/equilibration_bounds.rs
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,25 @@ where `VCPKG_TOOLCHAIN_PATH` is the path to the vcpkg toolchain file.

### SDP support

To enable SDP features, set the `CLARABEL_FEATURE_SDP` option to one of the following values:
To enable SDP features, set the `-DCLARABEL_FEATURE_SDP` option to one of the following values:
- `sdp-accelerate`
- `sdp-netlib`
- `sdp-openblas`
- `sdp-mkl`
- `sdp-r`

By default, `CLARABEL_FEATURE_SDP` is `none` and SDP support is disabled.
By default, `-DCLARABEL_FEATURE_SDP=none` and SDP support is disabled.

### JSON file input/output support

To enable reading and writing of problem data to JSON files, set
`-DCLARABEL_FEATURE_SERDE=true`.

When reporting issues with the solver, it can be helpful to provide a JSON file that reproduces the problem.

### Alternative linear algebra libraries

To enable the use of the [faer-rs](https://faer-rs.github.io/) sparse linear algebra library as an additional solver option, set `-DCLARABEL_FEATURE_FAER_SPARSE=true`.

### Unit tests

Expand Down
1 change: 1 addition & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
project(clarabel_examples VERSION ${CLARABEL_PROJECT_VERSION})
add_compile_definitions("EXAMPLES_ROOT_DIR=${CMAKE_CURRENT_SOURCE_DIR}")

add_subdirectory(c)
add_subdirectory(cpp)
1 change: 1 addition & 0 deletions examples/c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ set(C_EXAMPLES
example_qp_f64
example_socp
example_sdp
example_json
)

# Compile utils.c as a library
Expand Down
34 changes: 34 additions & 0 deletions examples/c/example_json.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// #define FEATURE_SDP
#include "utils.h"
#include <string.h>
#include <Clarabel.h>
#include <math.h>
#include <stdio.h>

#define STRING(string) #string
#define TO_STRING(string) STRING(string)

int main(void)
{
#ifndef FEATURE_SERDE
printf("This example requires JSON serde support.\n");
return 1;
#else

char filename[1024];
strcpy(filename, TO_STRING(EXAMPLES_ROOT_DIR));
strcat(filename, "/data/hs35.json");

ClarabelDefaultSolver* solver = clarabel_DefaultSolver_read_from_file(filename);
clarabel_DefaultSolver_solve(solver);

// write it back to a file
// char filename_out[1024];
// strcpy(filename_out, TO_STRING(EXAMPLES_ROOT_DIR));
// strcat(filename_out, "/data/output_c.json");
// clarabel_DefaultSolver_write_to_file(solver, filename_out);

clarabel_DefaultSolver_free(solver);
return 0;
#endif
}
2 changes: 2 additions & 0 deletions examples/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ set(CPP_EXAMPLES
example_qp
example_socp
example_sdp
example_faer
example_json
)

# Define an executable target for each example
Expand Down
74 changes: 74 additions & 0 deletions examples/cpp/example_faer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#include "utils.h"

#include <Clarabel>
#include <Eigen/Eigen>
#include <vector>

using namespace clarabel;
using namespace std;
using namespace Eigen;

// NB: this example requires that the solver be built with -DCLARABEL_FEATURE_FAER_SPARSE

int main(void)
{

#ifndef FEATURE_FAER_SPARSE

printf("This example requires faer-rs support.\n");
return 1;

#else


/* From dense matrix:
* [[6., 0.],
* [0., 4.]]
*/
MatrixXd P_dense(2, 2);
P_dense <<
6., 0.,
0., 4.;

SparseMatrix<double> P = P_dense.sparseView();
P.makeCompressed();

Vector<double, 2> q = { -1., -4. };

MatrixXd A_dense(5, 2);
A_dense <<
1., -2., // <-- LHS of equality constraint (lower bound)
1., 0., // <-- LHS of inequality constraint (upper bound)
0., 1., // <-- LHS of inequality constraint (upper bound)
-1., 0., // <-- LHS of inequality constraint (lower bound)
0., -1.; // <-- LHS of inequality constraint (lower bound)

SparseMatrix<double> A = A_dense.sparseView();
A.makeCompressed();

Vector<double, 5> b = { 0., 1., 1., 1., 1. };

vector<SupportedConeT<double>> cones
{
ZeroConeT<double>(1),
NonnegativeConeT<double>(4),
};

// Settings
DefaultSettings<double> settings = DefaultSettings<double>::default_settings();
settings.direct_solve_method = ClarabelDirectSolveMethods::FAER;

// Build solver
DefaultSolver<double> solver(P, q, A, b, cones, settings);

// Solve
solver.solve();

// Get solution
DefaultSolution<double> solution = solver.solution();
utils::print_solution(solution);

return 0;

#endif // FEATURE_FAER_SPARSE
}
38 changes: 38 additions & 0 deletions examples/cpp/example_json.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// #define FEATURE_SDP
#include "utils.h"
#include <cstdio>
#include <Clarabel>

using namespace clarabel;
using namespace std;

#define STRING(string) #string
#define TO_STRING(string) STRING(string)

int main(void)
{
#ifndef FEATURE_SERDE

printf("This example requires JSON serde support.\n");
return 1;

#else

std::string rootdir = TO_STRING(EXAMPLES_ROOT_DIR);
std::string filepath = "/data/hs35.json";
std::string filename = rootdir + filepath;
cout << "Read from file: " << filename << endl;

DefaultSolver<double> solver = DefaultSolver<double>::read_from_file(filename);
solver.solve();

// write it back to a file
// std::string outpath = "/data/output.json";
// std::string filename_out = rootdir + outpath;
// solver.write_to_file(filename_out);

return 0;

#endif // FEATURE_SERDE

}
1 change: 1 addition & 0 deletions examples/data/hs35.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"P":{"m":3,"n":3,"colptr":[0,1,3,5],"rowval":[0,0,1,0,2],"nzval":[4.000000000000001,2.0000000000000004,4.000000000000001,2.0,2.0]},"q":[-8.0,-6.0,-4.0],"A":{"m":4,"n":3,"colptr":[0,2,4,6],"rowval":[0,1,0,2,0,3],"nzval":[1.0,-1.0,1.0,-1.0,2.0,-1.0]},"b":[3.0,0.0,0.0,0.0],"cones":[{"NonnegativeConeT":4}],"settings":{"max_iter":200,"time_limit":1.7976931348623157e308,"verbose":true,"max_step_fraction":0.99,"tol_gap_abs":1e-8,"tol_gap_rel":1e-8,"tol_feas":1e-8,"tol_infeas_abs":1e-8,"tol_infeas_rel":1e-8,"tol_ktratio":1e-6,"reduced_tol_gap_abs":0.00005,"reduced_tol_gap_rel":0.00005,"reduced_tol_feas":0.0001,"reduced_tol_infeas_abs":0.00005,"reduced_tol_infeas_rel":0.00005,"reduced_tol_ktratio":0.0001,"equilibrate_enable":true,"equilibrate_max_iter":10,"equilibrate_min_scaling":0.0001,"equilibrate_max_scaling":10000.0,"linesearch_backtrack_step":0.8,"min_switch_step_length":0.1,"min_terminate_step_length":0.0001,"direct_kkt_solver":true,"direct_solve_method":"qdldl","static_regularization_enable":true,"static_regularization_constant":1e-8,"static_regularization_proportional":4.930380657631324e-32,"dynamic_regularization_enable":true,"dynamic_regularization_eps":1e-13,"dynamic_regularization_delta":2e-7,"iterative_refinement_enable":true,"iterative_refinement_reltol":1e-13,"iterative_refinement_abstol":1e-12,"iterative_refinement_max_iter":10,"iterative_refinement_stop_ratio":5.0,"presolve_enable":true,"chordal_decomposition_enable":true,"chordal_decomposition_merge_method":"clique_graph","chordal_decomposition_compact":true,"chordal_decomposition_complete_dual":true}}
1 change: 0 additions & 1 deletion include/Clarabel
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "cpp/DefaultSettings.h"
#include "cpp/DefaultSolution.h"
#include "cpp/DefaultSolver.h"
// #include "cpp/DefaultSolverEigen.h"
#include "cpp/SupportedConeT.h"

#endif // CLARABEL_H
3 changes: 3 additions & 0 deletions include/c/DefaultSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
typedef enum ClarabelDirectSolveMethods
{
QDLDL,
#ifdef FEATURE_FAER_SPARSE
FAER,
#endif
// MKL, (not supported in Rust yet)
// CHOLMOD, (not supported in Rust yet)
} ClarabelDirectSolveMethods;
Expand Down
34 changes: 34 additions & 0 deletions include/c/DefaultSolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,40 @@ static inline ClarabelDefaultSolver *clarabel_DefaultSolver_new(const ClarabelCs
#endif
}

#ifdef FEATURE_SERDE
// DefaultSolver::read_from_file
ClarabelDefaultSolver_f64 *clarabel_DefaultSolver_f64_read_from_file(const char *filename);
ClarabelDefaultSolver_f32 *clarabel_DefaultSolver_f32_read_from_file(const char *filename);
#ifdef CLARABEL_USE_FLOAT
static inline ClarabelDefaultSolver *clarabel_DefaultSolver_read_from_file(const char *filename)
{
return clarabel_DefaultSolver_f32_read_from_file(filename);
}
#else
static inline ClarabelDefaultSolver *clarabel_DefaultSolver_read_from_file(const char *filename)
{
return clarabel_DefaultSolver_f64_read_from_file(filename);
}
#endif // CLARABEL_USE_FLOAT

// DefaultSolver::write_to_file
void clarabel_DefaultSolver_f64_write_to_file(ClarabelDefaultSolver_f64 *solver, const char *filename);
void clarabel_DefaultSolver_f32_write_to_file(ClarabelDefaultSolver_f32 *solver, const char *filename);
#ifdef CLARABEL_USE_FLOAT
static inline void clarabel_DefaultSolver_write_to_file(ClarabelDefaultSolver *solver, const char *filename)
{
clarabel_DefaultSolver_f32_write_to_file(solver,filename);
}
#else
static inline void clarabel_DefaultSolver_write_to_file(ClarabelDefaultSolver *solver, const char *filename)
{
clarabel_DefaultSolver_f64_write_to_file(solver,filename);
}
#endif // CLARABEL_USE_FLOAT
#endif // FEATURE_SERDE



// DefaultSolver::solve
void clarabel_DefaultSolver_f64_solve(ClarabelDefaultSolver_f64 *solver);

Expand Down
3 changes: 3 additions & 0 deletions include/cpp/DefaultSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ namespace clarabel
enum class ClarabelDirectSolveMethods
{
QDLDL,
#ifdef FEATURE_FAER_SPARSE
FAER,
#endif
// MKL, (not supported in Rust yet)
// CHOLMOD, (not supported in Rust yet)
};
Expand Down
Loading

0 comments on commit c3a7b1e

Please sign in to comment.