Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Treat 3/4D SOC cone as dense #51

Merged
merged 30 commits into from
Sep 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
ba28379
add generalized power cones, but haven't debugged it yet
yuwenchen95 Aug 7, 2023
0716833
genpow draft
yuwenchen95 Aug 11, 2023
f6de6a9
fix build failures.
goulart-paul Sep 1, 2023
fb55eb4
add generalized power cones, but haven't debugged it yet
yuwenchen95 Aug 7, 2023
315c4e0
genpow draft
yuwenchen95 Aug 11, 2023
df75069
fix build failures.
goulart-paul Sep 1, 2023
70c5f89
Merge branch 'yc/genpow' of https://github.com/oxfordcontrol/Clarabel…
goulart-paul Sep 3, 2023
d77704c
feature-genpowcone
goulart-paul Sep 4, 2023
5983b70
reorganize nonsym cone traits
goulart-paul Sep 4, 2023
5f7a080
add itertools
goulart-paul Sep 4, 2023
4bb1fa0
Julia porting fixes
goulart-paul Sep 5, 2023
ab31f32
add genpow test
goulart-paul Sep 5, 2023
4545290
update NR method
goulart-paul Sep 5, 2023
d0f2948
bug fix
goulart-paul Sep 5, 2023
76892d8
adds cone method. adds extra work field to GPC
goulart-paul Sep 5, 2023
738c526
spacing
goulart-paul Sep 5, 2023
6336a65
simplify implementation of Hs_is_diagonal
goulart-paul Sep 5, 2023
6355cb1
sync Julia nonsym cones
goulart-paul Sep 5, 2023
e13436d
reduce wright omega iterations
goulart-paul Sep 5, 2023
5a167d5
clippy appeasement
goulart-paul Sep 5, 2023
5877804
rewrite of KKT assembly and cone data mappings
goulart-paul Sep 7, 2023
181b1ce
rustification
goulart-paul Sep 8, 2023
a2802ab
rustification
goulart-paul Sep 8, 2023
da1e8a3
julia impl sync
goulart-paul Sep 13, 2023
1991322
julia sync
goulart-paul Sep 13, 2023
72efa20
Merge branch 'develop' into feature-genpowcone
goulart-paul Sep 13, 2023
7751c9b
port dense SOC cones
goulart-paul Sep 14, 2023
4387dde
composite expansion is unreachable
goulart-paul Sep 14, 2023
1df1619
WIP: for arc test
goulart-paul Sep 15, 2023
7068d53
stability improvements for dense SOC
goulart-paul Sep 17, 2023
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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ enum_dispatch = "0.3.8"
amd = "0.2.2"
thiserror = "1.0"
cfg-if = "1.0"
itertools = "0.11"

# -------------------------------
# features
Expand Down
10 changes: 4 additions & 6 deletions src/algebra/csc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,18 @@ where
J: IntoIterator<Item = &'a T>,
T: FloatT,
{
#[allow(clippy::needless_range_loop)]
fn from(rows: I) -> CscMatrix<T> {
let rows: Vec<Vec<T>> = rows
.into_iter()
.map(|r| r.into_iter().map(|&v| v).collect())
.map(|r| r.into_iter().copied().collect())
.collect();

let m = rows.len();
let n = rows.iter().map(|r| r.len()).next().unwrap_or(0);

assert!(rows.iter().all(|r| r.len() == n));
let nnz = rows
.iter()
.flat_map(|r| r)
.filter(|&&v| v != T::zero())
.count();
let nnz = rows.iter().flatten().filter(|&&v| v != T::zero()).count();

let mut colptr = Vec::with_capacity(n + 1);
let mut rowval = Vec::with_capacity(nnz);
Expand Down
3 changes: 2 additions & 1 deletion src/algebra/dense/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ pub struct Matrix<T = f64> {
/// [0.0, 4.0]]);
// ```
//
#[allow(clippy::needless_range_loop)]
impl<'a, I, J, T> From<I> for Matrix<T>
where
I: IntoIterator<Item = J>,
Expand All @@ -51,7 +52,7 @@ where
fn from(rows: I) -> Matrix<T> {
let rows: Vec<Vec<T>> = rows
.into_iter()
.map(|r| r.into_iter().map(|&v| v).collect())
.map(|r| r.into_iter().copied().collect())
.collect();

let m = rows.len();
Expand Down
3 changes: 1 addition & 2 deletions src/algebra/floats.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(non_snake_case)]
use num_traits::{Float, FloatConst, FromPrimitive, NumAssign};
use std::fmt::{Debug, Display, LowerExp};

Expand Down Expand Up @@ -79,8 +80,6 @@ cfg_if::cfg_if! {
// NB: `AsFloatT` is a convenience trait for f32/64 and u32/64
// so that we can do things like (2.0).as_T() everywhere on
// constants, rather than the awful T::from_f32(2.0).unwrap()

#[allow(non_snake_case)]
pub trait AsFloatT<T>: 'static {
fn as_T(&self) -> T;
}
Expand Down
5 changes: 4 additions & 1 deletion src/algebra/math_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ pub trait VectorMath {
/// Standard Euclidian or 2-norm distance from `self` to `y`
fn dist(&self, y: &Self) -> Self::T;

/// Sum of elements squared.
/// Sum of elements.
fn sum(&self) -> Self::T;

/// Sum of squares of the elements.
fn sumsq(&self) -> Self::T;

/// 2-norm
Expand Down
7 changes: 6 additions & 1 deletion src/algebra/vecmath.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::{FloatT, ScalarMath, VectorMath};
use itertools::izip;
use std::iter::zip;

impl<T: FloatT> VectorMath for [T] {
Expand Down Expand Up @@ -88,7 +89,7 @@ impl<T: FloatT> VectorMath for [T] {
assert_eq!(s.len(), ds.len());

let mut out = T::zero();
for ((&s, &ds), (&z, &dz)) in zip(zip(s, ds), zip(z, dz)) {
for (&s, &ds, &z, &dz) in izip!(s, ds, z, dz) {
let si = s + α * ds;
let zi = z + α * dz;
out += si * zi;
Expand All @@ -101,6 +102,10 @@ impl<T: FloatT> VectorMath for [T] {
T::sqrt(dist2)
}

fn sum(&self) -> T {
self.iter().fold(T::zero(), |acc, &x| acc + x)
}

fn sumsq(&self) -> T {
self.dot(self)
}
Expand Down
29 changes: 17 additions & 12 deletions src/solver/core/cones/compositecone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ where
// create cones with the given dims
for t in types.iter() {
//make a new cone
let cone = make_cone(*t);
let cone = make_cone(t);

//update global problem symmetry
_is_symmetric = _is_symmetric && cone.is_symmetric();
Expand Down Expand Up @@ -157,7 +157,7 @@ where
pub fn iter_mut(&mut self) -> std::slice::IterMut<'_, SupportedCone<T>> {
self.cones.iter_mut()
}
pub(crate) fn type_count(&self, tag: SupportedConeTag) -> usize {
pub(crate) fn get_type_count(&self, tag: SupportedConeTag) -> usize {
if self.type_counts.contains_key(&tag) {
self.type_counts[&tag]
} else {
Expand All @@ -182,6 +182,18 @@ where
self._is_symmetric
}

fn is_sparse_expandable(&self) -> bool {
//This should probably never be called
//self.cones.iter().any(|cone| cone.is_sparse_expandable())
unreachable!();
}

fn allows_primal_dual_scaling(&self) -> bool {
self.cones
.iter()
.all(|cone| cone.allows_primal_dual_scaling())
}

fn rectify_equilibration(&self, δ: &mut [T], e: &[T]) -> bool {
let mut any_changed = false;

Expand Down Expand Up @@ -248,14 +260,7 @@ where
//This function should probably never be called since
//we only us it to interrogate the blocks, but we can
//implement something reasonable anyway
let mut is_diag = true;
for cone in self.iter() {
is_diag &= cone.Hs_is_diagonal();
if !is_diag {
break;
}
}
is_diag
self.cones.iter().all(|cone| cone.Hs_is_diagonal())
}

#[allow(non_snake_case)]
Expand Down Expand Up @@ -348,9 +353,9 @@ where
(α, α)
}

fn compute_barrier(&self, z: &[T], s: &[T], dz: &[T], ds: &[T], α: T) -> T {
fn compute_barrier(&mut self, z: &[T], s: &[T], dz: &[T], ds: &[T], α: T) -> T {
let mut barrier = T::zero();
for (cone, rng) in zip(&self.cones, &self.rng_cones) {
for (cone, rng) in zip(&mut self.cones, &self.rng_cones) {
let zi = &z[rng.clone()];
let si = &s[rng.clone()];
let dzi = &dz[rng.clone()];
Expand Down
Loading