pub struct DifferentiableQP {
pub q: Vec<Vec<f64>>,
pub c: Vec<f64>,
pub g: Vec<Vec<f64>>,
pub h: Vec<f64>,
pub a: Vec<Vec<f64>>,
pub b: Vec<f64>,
}Expand description
A differentiable QP layer.
Holds the problem data and supports forward solving and backward (gradient) computation.
Fields§
§q: Vec<Vec<f64>>Quadratic cost matrix Q (n×n, symmetric positive semi-definite).
c: Vec<f64>Linear cost vector c (n).
g: Vec<Vec<f64>>Inequality constraint matrix G (m×n): Gx ≤ h.
h: Vec<f64>Inequality constraint rhs h (m).
a: Vec<Vec<f64>>Equality constraint matrix A (p×n): Ax = b.
b: Vec<f64>Equality constraint rhs b (p).
Implementations§
Source§impl DifferentiableQP
impl DifferentiableQP
Sourcepub fn new(
q: Vec<Vec<f64>>,
c: Vec<f64>,
g: Vec<Vec<f64>>,
h: Vec<f64>,
a: Vec<Vec<f64>>,
b: Vec<f64>,
) -> OptimizeResult<Self>
pub fn new( q: Vec<Vec<f64>>, c: Vec<f64>, g: Vec<Vec<f64>>, h: Vec<f64>, a: Vec<Vec<f64>>, b: Vec<f64>, ) -> OptimizeResult<Self>
Create a new differentiable QP.
§Arguments
q– n×n cost matrix (must be symmetric PSD).c– n-dimensional linear cost.g– m×n inequality constraint matrix.h– m-dimensional inequality rhs.a– p×n equality constraint matrix.b– p-dimensional equality rhs.
Sourcepub fn forward(&self, config: &DiffQPConfig) -> OptimizeResult<DiffQPResult>
pub fn forward(&self, config: &DiffQPConfig) -> OptimizeResult<DiffQPResult>
Solve the QP (forward pass).
Uses a primal-dual interior-point method with Mehrotra predictor- corrector steps.
Sourcepub fn backward(
&self,
result: &DiffQPResult,
dl_dx: &[f64],
config: &DiffQPConfig,
) -> OptimizeResult<ImplicitGradient>
pub fn backward( &self, result: &DiffQPResult, dl_dx: &[f64], config: &DiffQPConfig, ) -> OptimizeResult<ImplicitGradient>
Backward pass: compute gradients of loss w.r.t. QP parameters.
Given the upstream gradient dl/dx*, returns the implicit gradients dl/d{Q, c, G, h, A, b}.
Sourcepub fn batched_forward(
params_list: &[DifferentiableQP],
config: &DiffQPConfig,
) -> OptimizeResult<Vec<DiffQPResult>>
pub fn batched_forward( params_list: &[DifferentiableQP], config: &DiffQPConfig, ) -> OptimizeResult<Vec<DiffQPResult>>
Solve multiple QPs with the same structure but different parameters.
This is a convenience method; each QP is solved independently.
Trait Implementations§
Source§impl Clone for DifferentiableQP
impl Clone for DifferentiableQP
Source§fn clone(&self) -> DifferentiableQP
fn clone(&self) -> DifferentiableQP
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for DifferentiableQP
impl RefUnwindSafe for DifferentiableQP
impl Send for DifferentiableQP
impl Sync for DifferentiableQP
impl Unpin for DifferentiableQP
impl UnsafeUnpin for DifferentiableQP
impl UnwindSafe for DifferentiableQP
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.