Skip to content

Commit 4e6866c

Browse files
authored
Merge pull request #23 from oxfordcontrol/conespec_fix
Robustify solver, add warm-start API, and update docs (v0.11.2)
2 parents 931a112 + 7742361 commit 4e6866c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+3834
-434
lines changed

.Rbuildignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,7 @@
1717
^src/rust/.cargo$
1818
^src/Makevars$
1919
^cran-comments\.md$
20+
21+
^src/rust/\.cargo$
22+
^\.claude$
23+
^CLAUDE\.md$

DESCRIPTION

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: clarabel
22
Type: Package
33
Title: Interior Point Conic Optimization Solver
4-
Version: 0.11.1
4+
Version: 0.11.2
55
Authors@R: c(person("Balasubramanian", "Narasimhan", role = c("aut", "cre"),
66
email = "naras@stanford.edu"),
77
person("Paul", "Goulart", role = c("aut", "cph")),
@@ -26,5 +26,6 @@ Suggests:
2626
tinytest
2727
VignetteBuilder: knitr
2828
SystemRequirements: Cargo (Rust's package manager), rustc (>= 1.70.0), and GNU Make
29-
Imports:
29+
Imports:
30+
cli,
3031
methods

NAMESPACE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
# Generated by roxygen2: do not edit by hand
22

3+
S3method("$<-",savvy_clarabel__sealed)
4+
S3method("[[<-",savvy_clarabel__sealed)
5+
S3method(print,"clarabel::ClarabelSolver__bundle")
36
export(clarabel)
47
export(clarabel_control)
8+
export(clarabel_solver)
9+
export(solver_is_update_allowed)
10+
export(solver_solve)
511
export(solver_status_descriptions)
12+
export(solver_update)
613
importFrom(methods,as)
714
useDynLib(clarabel)
815
useDynLib(clarabel, .registration = TRUE)

NEWS.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
# clarabel 0.11.2
2+
3+
- Added persistent solver API for warm starts: `clarabel_solver()`,
4+
`solver_solve()`, `solver_update()`, `solver_is_update_allowed()`
5+
- Robustified Rust interface: type coercion, error handling,
6+
CscMatrix validation, and regex ordering fixes
7+
- Switched all R-side error messaging to `cli::cli_abort()` with
8+
markup
9+
- Upgraded `savvy` crate from 0.8.13 to 0.9.2
10+
- Added examples to `clarabel_control()` and solver functions
11+
- Added vignette section on updating problem data (warm starts)
12+
113
# clarabel 0.11.1
214

315
- Synced up to v0.11.1 of `Clarabel.rs`

R/000-wrappers.R

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,71 @@ NULL
2323
}
2424
}
2525

26+
# Prohibit modifying environments
2627

27-
clarabel_solve <- function(m, n, Ai, Ap, Ax, b, q, Pi, Pp, Px, cone_spec, r_settings) {
28-
.Call(savvy_clarabel_solve__impl, m, n, Ai, Ap, Ax, b, q, Pi, Pp, Px, cone_spec, r_settings)
28+
#' @export
29+
`$<-.savvy_clarabel__sealed` <- function(x, name, value) {
30+
class <- gsub("__bundle$", "", class(x)[1])
31+
stop(class, " cannot be modified", call. = FALSE)
2932
}
3033

34+
#' @export
35+
`[[<-.savvy_clarabel__sealed` <- function(x, i, value) {
36+
class <- gsub("__bundle$", "", class(x)[1])
37+
stop(class, " cannot be modified", call. = FALSE)
38+
}
39+
40+
41+
`clarabel_solve` <- function(`m`, `n`, `Ai`, `Ap`, `Ax`, `b`, `q`, `Pi`, `Pp`, `Px`, `cone_spec`, `r_settings`) {
42+
.Call(savvy_clarabel_solve__impl, `m`, `n`, `Ai`, `Ap`, `Ax`, `b`, `q`, `Pi`, `Pp`, `Px`, `cone_spec`, `r_settings`)
43+
}
44+
45+
### wrapper functions for ClarabelSolver
46+
47+
`ClarabelSolver_is_update_allowed` <- function(self) {
48+
function() {
49+
.Call(savvy_ClarabelSolver_is_update_allowed__impl, `self`)
50+
}
51+
}
52+
53+
`ClarabelSolver_solve` <- function(self) {
54+
function() {
55+
.Call(savvy_ClarabelSolver_solve__impl, `self`)
56+
}
57+
}
58+
59+
`ClarabelSolver_update_data` <- function(self) {
60+
function(`Px`, `Ax`, `q`, `b`) {
61+
invisible(.Call(savvy_ClarabelSolver_update_data__impl, `self`, `Px`, `Ax`, `q`, `b`))
62+
}
63+
}
64+
65+
`.savvy_wrap_ClarabelSolver` <- function(ptr) {
66+
e <- new.env(parent = emptyenv())
67+
e$.ptr <- ptr
68+
e$`is_update_allowed` <- `ClarabelSolver_is_update_allowed`(ptr)
69+
e$`solve` <- `ClarabelSolver_solve`(ptr)
70+
e$`update_data` <- `ClarabelSolver_update_data`(ptr)
71+
72+
class(e) <- c("clarabel::ClarabelSolver", "ClarabelSolver", "savvy_clarabel__sealed")
73+
e
74+
}
75+
76+
77+
#' A persistent Clarabel solver that can be reused across R calls.
78+
`ClarabelSolver` <- new.env(parent = emptyenv())
79+
80+
### associated functions for ClarabelSolver
81+
82+
`ClarabelSolver`$`new` <- function(`m`, `n`, `Ai`, `Ap`, `Ax`, `b`, `q`, `Pi`, `Pp`, `Px`, `cone_spec`, `r_settings`) {
83+
.savvy_wrap_ClarabelSolver(.Call(savvy_ClarabelSolver_new__impl, `m`, `n`, `Ai`, `Ap`, `Ax`, `b`, `q`, `Pi`, `Pp`, `Px`, `cone_spec`, `r_settings`))
84+
}
85+
86+
87+
class(`ClarabelSolver`) <- c("clarabel::ClarabelSolver__bundle", "savvy_clarabel__sealed")
88+
89+
#' @export
90+
`print.clarabel::ClarabelSolver__bundle` <- function(x, ...) {
91+
cat('clarabel::ClarabelSolver\n')
92+
}
3193

0 commit comments

Comments
 (0)