Skip to content

Commit

Permalink
Merge pull request #8 from oxfordcontrol/pg/v0.3.0-julia-port
Browse files Browse the repository at this point in the history
Pg/v0.3.0 julia port
  • Loading branch information
goulart-paul authored Sep 13, 2022
2 parents ad07235 + 8287bf4 commit 0d2761d
Show file tree
Hide file tree
Showing 66 changed files with 4,611 additions and 982 deletions.
2 changes: 1 addition & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
# ------------------------------

[build]
rustdocflags = [ "--html-in-header", "./html/docs-header.html" ]
rustdocflags = [ "--html-in-header", "./html/rustdocs-header.html" ]
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ Cargo.lock
.vscode
.env*
notes*.txt
julia
/dist
58 changes: 50 additions & 8 deletions Cargo.toml
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"
Expand All @@ -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"
Expand All @@ -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
Expand All @@ -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" ]
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Interior Point Conic Optimization for Rust and Python
<a href="https://codecov.io/gh/oxfordcontrol/Clarabel.rs"><img src="https://codecov.io/gh/oxfordcontrol/Clarabel.rs/branch/main/graph/badge.svg"></a>
<a href="https://oxfordcontrol.github.io/ClarabelDocs/stable"><img src="https://img.shields.io/badge/Documentation-stable-purple.svg"></a>
<a href="https://opensource.org/licenses/Apache-2.0"><img src="https://img.shields.io/badge/License-Apache%202.0-blue.svg"></a>
<a href="https://github.com/oxfordcontrol/Clarabel.rs/releases"><img src="https://img.shields.io/badge/Release-v0.2.0-blue.svg"></a>
<a href="https://github.com/oxfordcontrol/Clarabel.rs/releases"><img src="https://img.shields.io/badge/Release-v0.3.0-blue.svg"></a>
</p>

<p align="center">
Expand Down Expand Up @@ -47,7 +47,7 @@ Clarabel is also available in a Julia implementation. See [here](https://github

## Features

* __Versatile__: Clarabel.rs solves linear programs (LPs), quadratic programs (QPs) and second-order cone programs (SOCPs). Future versions will provide support for problems involving positive semidefinite, exponential and power cones.
* __Versatile__: Clarabel.rs solves linear programs (LPs), quadratic programs (QPs) and second-order cone programs (SOCPs). It also solves problems with exponential and power cone constraints. Future versions will provide support for problems involving positive semidefinite cone constraints.
* __Quadratic objectives__: Unlike interior point solvers based on the standard homogeneous self-dual embedding (HSDE), Clarabel.rs handles quadratic objectives without requiring any epigraphical reformulation of the objective. It can therefore be significantly faster than other HSDE-based solvers for problems with quadratic objective functions.
* __Infeasibility detection__: Infeasible problems are detected using a homogeneous embedding technique.
* __Open Source__: Our code is available on [GitHub](https://github.com/oxfordcontrol/Clarabel.rs) and distributed under the Apache 2.0 License
Expand Down
29 changes: 29 additions & 0 deletions examples/python/example_expcone.py
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()
33 changes: 33 additions & 0 deletions examples/rust/example_expcone.rs
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();
}
40 changes: 40 additions & 0 deletions examples/rust/example_powcone.rs
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.
6 changes: 4 additions & 2 deletions src/algebra/floats.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use num_traits::{Float, FromPrimitive, NumAssign};
use num_traits::{Float, FloatConst, FromPrimitive, NumAssign};

/// Trait for floating point types used in the Clarabel solver
///
Expand All @@ -14,6 +14,7 @@ pub trait FloatT:
'static
+ Send
+ Float
+ FloatConst
+ NumAssign
+ Default
+ FromPrimitive
Expand Down Expand Up @@ -46,7 +47,7 @@ macro_rules! impl_as_T {
($ty:ty, $ident:ident) => {
impl<T> AsFloatT<T> for $ty
where
T: FromPrimitive + 'static,
T: std::ops::Mul<T, Output = T> + FromPrimitive + 'static,
{
#[inline]
fn as_T(&self) -> T {
Expand All @@ -57,5 +58,6 @@ macro_rules! impl_as_T {
}
impl_as_T!(u32, from_u32);
impl_as_T!(u64, from_u64);
impl_as_T!(usize, from_usize);
impl_as_T!(f32, from_f32);
impl_as_T!(f64, from_f64);
Loading

0 comments on commit 0d2761d

Please sign in to comment.