Skip to main content

Engine to compute Jacobian-vector and vector-Jacobian products for (convex) quadratic cone programs.

Project description

diffqcp: Differentiating through quadratic cone programs

diffqcp is a JAX library that enables forming the derivative of the solution map to a quadratic cone program (QCP) with respect to the QCP problem data as an abstract linear operator and computing Jacobian-vector products (JVPs) and vector-Jacobian products (VJPs) with this operator.

TODO(quill): (briefly) Discuss

  • implicit differentiation approach to argmin differentiation (exploiting mathematical structure)
  • DPP (relevant for batched problems)
  • Automatic differentiation.

Features include:

  • Hardware acclerated: JVPs and VJPs can be computed on CPUs, GPUs, and (theoretically) TPUs.
  • Support for all canonical classes of convex optimization problems including
    • linear programs (LPs),
    • quadratic programs (QPs),
    • second-order cone programs (SOCPs),
    • and semidefinite programs (SDPs). TODO(quill): implement before release...should be easy

Quadratic cone programs

A quadratic cone program is given by the primal and dual problems

\begin{equation*}
    \begin{array}{lll}
        \text{(P)} \quad &\text{minimize} \; & (1/2)x^T P x + q^T x  \\
        &\text{subject to} & Ax + s = b  \\
        & & s \in \mathcal{K},
    \end{array}
    \qquad
    \begin{array}{lll}
         \text{(D)} \quad  &\text{maximize} \; & -(1/2)x^T P x -b^T y  \\
        &\text{subject to} & Px + A^T y = -q \\
        & & y \in \mathcal{K}^*,
    \end{array}
\end{equation*}

where $x \in \mathbf{R}^n$ is the primal variable, $y \in \mathbf{R}^m$ is the dual variable, and $s \in \mathbf{R}^m$ is the primal slack variable. The problem data are $P\in \mathbf{S}_+^{n}$, $A \in \mathbf{R}^{m \times n}$, $q \in \mathbf{R}^n$, and $b \in \mathbf{R}^m$. We assume that $\mathcal K \subseteq \mathbf{R}^m$ is a nonempty, closed, convex cone with dual cone $\mathcal{K}^*$.

diffqcp currently supports QCPs whose cone is the Cartesian product of the zero cone, the positive orthant, second-order cones, and positive semidefinite cones. Support for exponential and power cones (and their dual cones) is in development (see the TODOs below). For more information about these cones, see the appendix of our paper.

Citation

See also

Core dependencies (diffqcp makes essential use of the following libraries)

  • Equinox: Neural networks and everything not already in core JAX (via callable PyTrees).
  • Lineax: Linear solvers.

Related

  • CVXPYlayers: Construct differentiable convex optimization layers using CVXPY. (WIP: diffqcp is being added as a backend for CVXPYlayers.)
  • CuClarabel: The GPU implemenation of the second-order QCP solver, Clarabel.
  • SCS: A first-order QCP solver that has an optional GPU-accelerated backend.
  • diffcp: A (Python with C-bindings) library for differentiating through (linear) cone programs.

TODOs:

After failing to achieve desired performance with a torch-backed implementation (branch here), this JAX implementation of diffqcp was rapidly developed. Consequently, there is some tech debt:

Functionality

  • TODO(quill)--important: Heuristic JVP and VJP computations when the solution map of a QCP is non-differentiable (lineax just fails if LSMR doesn't converge, whereas our torch version and diffcp just return the last iterate).
  • Support for the exponential (and dual exponential) cone. (Just requires re-implementing the PyTorch version in JAX following best practices as found in lineax or optimistix.)
  • Support for the power (and dual power) cone. (Same approach as for exponential cone.)
  • Batched JVP and VJP computations (via vmap--should just work since we can already jit)
  • Batched problem computions--i.e., constructing derivatives of solution maps to a batch of DPP-compliant problems. (so yes, diffqcp is aiming to support multi-level batching: you can batch compute JVPs and VJPs over a batch of problems.)
    • The cone proj_dproj methods already support this functionality
  • Can HostQCP and DeviceQCP be combined?
    • Only difference is the use of BCOO arrays for the CPU "optimized" verion vs. BCSR arrays for the GPU "optimized" version
    • Other architecture improvements? (Be sure to add performance regression tests before making large changes.)
  • Allow factor-solve based JVPs and VJPs
    • requires as_matrix to be implemented for all custom lineax.AbstractLinearOperators.
    • Would need to have non-sparse returning atom functions.
  • Similarly, allow for changing the tolerance of the LSMR solve.
  • more explicit host and device array placement (right now have to use flag to specify whether to use single or double precision.)
  • Differentiable? (i.e., what happns if we use jax's auto-diff functionality--would this computation correspond to anything meaningful?)
  • Clean up the cone library so it can stand alone (i.e., it can be a JAX library for projecting onto convex cones and computing derivatives of these projections)
    • so will require separate proj and dproj methods,
    • plus just cleaner abstractions,
    • and removal of tech debt
  • See if diffqcp just works for distributed computations out of the box

Testing

  • Most of the testing exists in the torch branch, so need to port over key tests--i.e., not tests that were just initial (research) validation tests, but tests that ensure future change don't break anything.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

diffqcp-0.1.0.tar.gz (12.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

diffqcp-0.1.0-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file diffqcp-0.1.0.tar.gz.

File metadata

  • Download URL: diffqcp-0.1.0.tar.gz
  • Upload date:
  • Size: 12.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for diffqcp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9d13dc6a697210be790e57ce32a5cfa4c3b4109e603ace1aae271d519ca05d75
MD5 8788b27d9946cac3e3b96490340d2d66
BLAKE2b-256 f97a3e4694d0f32b9f438bdbad15d990bd4fdb8f38c8f84dd036b9bda8b21957

See more details on using hashes here.

Provenance

The following attestation bundles were made for diffqcp-0.1.0.tar.gz:

Publisher: python-publish.yml on cvxgrp/diffqcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file diffqcp-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: diffqcp-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for diffqcp-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ae26508d24b325ebfc371ad44032263d4c3d5f6d723ea2fb25efb33e876857dd
MD5 04dd47f3c0dc20d3158c6e481d0c9294
BLAKE2b-256 aa10a0b3b43c5e80161dd18916115f5f7be0569c9f55cfab93b16c2d4ea2a423

See more details on using hashes here.

Provenance

The following attestation bundles were made for diffqcp-0.1.0-py3-none-any.whl:

Publisher: python-publish.yml on cvxgrp/diffqcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page