-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from oxfordcontrol/pg/v0.3.0-julia-port
Pg/v0.3.0 julia port
- Loading branch information
Showing
66 changed files
with
4,611 additions
and
982 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,4 @@ Cargo.lock | |
.vscode | ||
.env* | ||
notes*.txt | ||
julia | ||
/dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "clarabel" | ||
version = "0.2.0" | ||
version = "0.3.0" | ||
authors = ["Paul Goulart <[email protected]>"] | ||
edition = "2021" | ||
license = "Apache-2.0" | ||
|
@@ -13,7 +13,8 @@ categories = ["mathematics"] | |
[dependencies] | ||
num-traits = "0.2" | ||
derive_builder = "0.11" | ||
amd = "0.2.1" | ||
enum_dispatch = "0.3.8" | ||
amd = "0.2.2" | ||
|
||
[[example]] | ||
name = "lp" | ||
|
@@ -27,17 +28,57 @@ path = "examples/rust/example_qp.rs" | |
name = "socp" | ||
path = "examples/rust/example_socp.rs" | ||
|
||
[[example]] | ||
name = "powcone" | ||
path = "examples/rust/example_powcone.rs" | ||
|
||
[[example]] | ||
name = "expcone" | ||
path = "examples/rust/example_expcone.rs" | ||
|
||
[[example]] | ||
name = "box" | ||
path = "examples/rust/example_box.rs" | ||
|
||
|
||
|
||
# ------------------------------- | ||
# custom build profiles | ||
# ------------------------------- | ||
[profile.release-with-debug] | ||
inherits = "release" | ||
debug = true | ||
|
||
|
||
# ------------------------------ | ||
# Optional python interface | ||
# Optional julia and python interface | ||
# ------------------------------ | ||
|
||
[features] | ||
# enables python interface build via pyo3 | ||
python = ["dep:pyo3"] | ||
|
||
# enables julia interface | ||
julia = ["dep:libc","dep:num-derive","dep:serde", "dep:serde_json"] | ||
|
||
# enables python interface via pyo3. | ||
# should only be used with maturin builds. | ||
python = ["dep:pyo3","dep:num-derive"] | ||
|
||
[dependencies.num-derive] | ||
optional = true | ||
version = "0.2" | ||
|
||
[dependencies.serde] | ||
optional = true | ||
version = "1" | ||
features = ["derive"] | ||
|
||
[dependencies.serde_json] | ||
optional = true | ||
version = "1" | ||
|
||
[dependencies.libc] | ||
optional = true | ||
version = "0.2" | ||
|
||
[dependencies.pyo3] | ||
optional = true | ||
|
@@ -48,14 +89,15 @@ features = ["extension-module", "abi3-py37"] | |
|
||
[lib] | ||
name = "clarabel" | ||
# "cdylib" is necessary to produce a shared library that Python can import. | ||
# "cdylib" is necessary to produce a shared libraries for Python/Julia | ||
# "lib" is necessary to allow the ./examples to build | ||
crate-type = ["cdylib","lib"] | ||
crate-type = ["lib","cdylib"] | ||
|
||
|
||
# ------------------------------ | ||
# enable latex in docs | ||
# credit: https://github.com/victe/rust-latex-doc-minimal-example | ||
# ------------------------------ | ||
|
||
[package.metadata.docs.rs] | ||
rustdoc-args = [ "--html-in-header", "./html/docs-header.html" ] | ||
rustdoc-args = [ "--html-in-header", "./html/rustdocs-header.html" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import clarabel; | ||
import numpy as np; | ||
from scipy import sparse; | ||
|
||
# Exponential cone example | ||
# max x | ||
# s.t. y * exp(x / y) <= z | ||
# y == 1, z == exp(5) | ||
|
||
# Define problem data | ||
P = sparse.csc_matrix([[0., 0., 0.], [0., 0., 0.], [0., 0., 0.]]); | ||
P = sparse.triu(P).tocsc(); | ||
|
||
q = np.array([-1.,0.,0.]); | ||
|
||
A = sparse.csc_matrix( \ | ||
[[ -1., 0., 0.], | ||
[ 0.,-1., 0], | ||
[ 0., 0.,-1.], | ||
[ 0., 1., 0.], | ||
[ 0., 0., 1.]]); | ||
|
||
b = np.array([0.,0.,0.,1.,np.exp(5.)]); | ||
|
||
cones = [clarabel.ExponentialConeT(), clarabel.ZeroConeT(2)] | ||
settings = clarabel.DefaultSettings(); | ||
|
||
solver = clarabel.DefaultSolver(P,q,A,b,cones,settings); | ||
solver.solve() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#![allow(non_snake_case)] | ||
use clarabel::algebra::*; | ||
use clarabel::solver::*; | ||
|
||
// Exponential Cone Example | ||
|
||
// max x | ||
// s.t. y * exp(x / y) <= z | ||
// y == 1, z == exp(5) | ||
|
||
fn main() { | ||
let P = CscMatrix::spalloc(3, 3, 0); // For P = 0 | ||
let q = vec![-1., 0., 0.]; | ||
|
||
let A = CscMatrix::new( | ||
5, // m | ||
3, // n | ||
vec![0, 1, 3, 5], // colptr | ||
vec![0, 1, 3, 2, 4], // rowval | ||
vec![-1., -1., 1., -1., 1.], // nzval | ||
); | ||
|
||
let b = vec![0., 0., 0., 1., (5f64).exp()]; | ||
|
||
let cones = [ExponentialConeT(), ZeroConeT(2)]; | ||
|
||
let settings = DefaultSettings { | ||
verbose: true, | ||
..DefaultSettings::default() | ||
}; | ||
let mut solver = DefaultSolver::new(&P, &q, &A, &b, &cones, settings); | ||
solver.solve(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#![allow(non_snake_case)] | ||
use clarabel::algebra::*; | ||
use clarabel::solver::*; | ||
|
||
// Power Cone Example | ||
// | ||
// solve the following power cone problem | ||
// max x1^0.6 y^0.4 + x2^0.1 | ||
// s.t. x1, y, x2 >= 0 | ||
// x1 + 2y + 3x2 == 3 | ||
// which is equivalent to | ||
// max z1 + z2 | ||
// s.t. (x1, y, z1) in K_pow(0.6) | ||
// (x2, 1, z2) in K_pow(0.1) | ||
// x1 + 2y + 3x2 == 3 | ||
|
||
fn main() { | ||
let P = CscMatrix::spalloc(6, 6, 0); // For P = 0 | ||
let q = vec![0.0, 0.0, -1.0, 0.0, 0.0, -1.0]; | ||
|
||
let A = CscMatrix::new( | ||
8, // m | ||
6, // n | ||
vec![0, 2, 4, 5, 7, 9, 10], // colptr | ||
vec![0, 6, 1, 6, 2, 3, 6, 4, 7, 5], // rowval | ||
vec![-1., -1., -1., -2., -1., -1., -3., -1., -1., -1.], // nzval | ||
); | ||
|
||
let b = vec![0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -3.0, -1.0]; | ||
|
||
let cones = [PowerConeT(0.6), PowerConeT(0.1), ZeroConeT(1), ZeroConeT(1)]; | ||
|
||
let settings = DefaultSettings { | ||
verbose: true, | ||
max_iter: 100, | ||
..DefaultSettings::default() | ||
}; | ||
let mut solver = DefaultSolver::new(&P, &q, &A, &b, &cones, settings); | ||
solver.solve(); | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.