differentiableosqp.jl

Thin wrapper for OSQP.jl, allowing users to ForwardDiff through the quadratic program

https://github.com/dev10110/differentiableosqp.jl

Science Score: 41.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
  • .zenodo.json file
  • DOI references
    Found 4 DOI reference(s) in README
  • Academic publication links
    Links to: arxiv.org
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (9.3%) to scientific vocabulary
Last synced: 10 months ago · JSON representation ·

Repository

Thin wrapper for OSQP.jl, allowing users to ForwardDiff through the quadratic program

Basic Info
  • Host: GitHub
  • Owner: dev10110
  • License: mit
  • Language: Julia
  • Default Branch: main
  • Size: 121 KB
Statistics
  • Stars: 5
  • Watchers: 1
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Created over 3 years ago · Last pushed over 3 years ago
Metadata Files
Readme License Citation

README.md

DifferentiableOSQP

Dev Build Status

This package provides a thin wrapper of OSQP.jl, but also provides the ability to differentiate through the quadratic progam, based on the equations in OptNet.

The package exports 2 commands: solve and solve_and_jac.

Installation

Activate your environment and simply add DifferentialOSQP: ] add https://github.com/dev10110/DifferentiableOSQP.jl

Interface 1: Solve a QP

x = solve(P, q, A, u; kwargs...) Solves the quadratic program: math \begin{aligned} \min_x &\quad \frac{1}{2} x^T P x + q^T x \\ s.t. &\quad A x \leq u \end{aligned} where kwargs are keyword arguments passed into OSQP.setup!

To include equality constraints, for example G x = h, modify A, u matrices as: A = [A ; G ; -G] u = [u ; h; -h] This introduces the constraints G x \leq h and G x \geq h, allowing equalities to be handled. Yes, this is rather inefficient, but the easiest way to solve the problem I think.

Interface 2: Solve a Parameteric QP

x = solve(θ, P_fn, q_fn, A_fn, u_fn; kwargs) Solves the quadratic program: math \begin{aligned} \min_x &\quad \frac{1}{2} x^T P(\theta) x + q(\theta)^T x \\ s.t. &\quad A(\theta) x \leq u(\theta) \end{aligned} i.e., assumes the P_fn, q_fn, A_fn, u_fn are functions of θ. Note, the shape and size of each output must be correct - for example, A_fn(θ) must return a matrix, and q_fn(θ) must return a vector.

Interface 3: Jacobians of a QP

Thinking about interface 2, notice that a QP solver is essentially a function math QP : \mathbb{R}^p \to \mathbb{R}^n\\ x = QP(θ)

Therefore, the Jacobian of the QP math J = \frac{\partial x}{\partial \theta}

If we want the jacobian of QP, we can call it as the following: x, J = solve_and_jac(θ, P_fn, q_fn, A_fn, u_fn; kwargs) which gives the optimal solution x, and the jacobian J

Interaface 4: ForwardDiff

For convenience, we overloaded solve to handle Dual numbers. This means we can directly use ForwardDiff.jacobian, as in the following example:

J = ForwardDiff.jacobian(θ -> solve(θ, P_fn, q_fn, A_fn, u_fn), θ0)

or more explictly ``` function parametericqp(θ) return solve(θ, Pfn, qfn, Afn, u_fn) end

J = ForwardDiff.jacobian(parametric_qp, θ0) ```

Warning

Naturally, not all QPs are differentiable. This library will always return a derivative, but doesnt check/warn if the derivative doesnt exist. I want to add this functionality in the future. See this or this paper for some results on existence of derivatives/Lipschitz continuity of QPs.

Owner

  • Name: Devansh
  • Login: dev10110
  • Kind: user

Citation (CITATION.bib)

@misc{DifferentiableOSQP.jl,
	author  = {Devansh Ramgopal Agrawal <devansh@umich.edu> and contributors},
	title   = {DifferentiableOSQP.jl},
	url     = {https://github.com/dev10110/DifferentiableOSQP.jl},
	version = {v0.1.0},
	year    = {2022},
	month   = {12}
}

GitHub Events

Total
Last Year

Dependencies

.github/workflows/CI.yml actions
  • actions/checkout v2 composite
  • julia-actions/cache v1 composite
  • julia-actions/julia-buildpkg v1 composite
  • julia-actions/julia-docdeploy v1 composite
  • julia-actions/julia-runtest v1 composite
  • julia-actions/setup-julia v1 composite
.github/workflows/TagBot.yml actions
  • JuliaRegistries/TagBot v1 composite