https://github.com/cvxgrp/diffqcp
Science Score: 36.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
✓Academic publication links
Links to: arxiv.org -
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (10.7%) to scientific vocabulary
Repository
Basic Info
- Host: GitHub
- Owner: cvxgrp
- License: apache-2.0
- Language: Python
- Default Branch: main
- Size: 1.07 MB
Statistics
- Stars: 16
- Watchers: 3
- Forks: 0
- Open Issues: 0
- Releases: 2
Metadata Files
README.md
diffqcp: Differentiating through quadratic cone programs
diffqcp is a JAX library to form 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 to compute Jacobian-vector products (JVPs) and vector-Jacobian products (VJPs) with this operator.
The implementation is based on the derivations in our paper (see below) and computes
these products implicitly via projections onto cones and sparse linear system solves.
Our approach therefore differs from libraries that compute JVPs and VJPs by unrolling algorithm iterates.
We directly exploit the underlying structure of QCPs.
Features include: - Hardware acclerated: JVPs and VJPs can be computed on CPUs, GPUs, and (theoretically) TPUs. - Support for many canonical classes of convex optimization problems including - linear programs (LPs), - quadratic programs (QPs), - second-order cone programs (SOCPs), - and semidefinite programs (SDPs).
Quadratic cone programs
A quadratic cone program is given by the primal and dual problems
math
\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.
For more information about these cones, see the appendix of our paper.
Usage
diffqcp is meant to be used as a CVXPYlayers backend --- it is not designed to be a stand-alone
library.
Nonetheless, here is how it use it.
(Note that while we'll specify different CPU and a GPU configurations,
all modules are CPU and GPU compatible--we just recommend the following
as JAX's BCSR arrays do have CUDA backends for their mv operations while the BCOO arrays do not.)
For both of the following problems, we'll use the following objects:
```python import cvxpy as cvx
problem = cvx.Problem(...) probdata, _, _ = problem.getproblemdata(cvx.CLARABEL, solveropts={'usequadobj': True}) scscones = cvx.reductions.solvers.conicsolvers.scsconif.dimstosolverdict(prob_data["dims"])
x, y, s = ... # canonicalized solutions to problem
```
Optimal CPU approach
If computing JVPs and VJPs on a CPU, we recommend using the equinox.Modules HostQCP and QCPStructureCPU as demonstrated in the following pseudo-example.
```python from diffqcp import HostQCP, QCPStructureCPU from jax.experimental.sparse import BCOO from jaxtyping import Array
P: BCOO = ... # Only the upper triangular part of the QCP matrix P A: BCOO = ... q: Array = ... b: Array = ...
problemstructure = QCPStructureCPU(P, A, scscones) qcp = HostQCP(P, A, q, b, x, y, s, problem_structure)
Compute JVPs
dP: BCOO ... # Same sparsity pattern as P
dA: BCOO = ... # Same sparsity pattern as A
db: Array = ...
dq: Array = ...
dx, dy, ds = qcp.jvp(dP, dA, dq, db)
Compute VJPs
dP, dA will be BCOO arrays, dq, db just Arrays
dP, dA, dq, db = qcp.vjp(f1(x), f2(y), f3(s)) ```
Optimal GPU approach
If computing JVPs and VJPs on a GPU, we recommend using the equinox.Modules QCPStructureGPU and DeviceQCP.
```python from diffqcp import DeviceQCP, QCPStructureGPU from jax.experimental.sparse import BCSR from jaxtyping import Array
P: BCSR = ... # The entirety of the QCP matrix P A: BCSR = ... q: Array = ... b: Array = ...
problemstructure = QCPStructureGPU(P, A, scscones) qcp = DeviceQCP(P, A, q, b, x, y, s, problem_structure)
Compute JVPs
dP: BCSR ... # Same sparsity pattern as P
dA: BCSR = ... # Same sparsity pattern as A
db: Array = ...
dq: Array = ...
dx, dy, ds = qcp.jvp(dP, dA, dq, db)
Compute VJPs
dP, dA will be BCSR arrays, dq, db just Arrays
dP, dA, dq, db = qcp.vjp(f1(x), f2(y), f3(s)) ```
Citation
arXiv:2508.17522 [math.OC]
@misc{healey2025differentiatingquadraticconeprogram,
title={Differentiating Through a Quadratic Cone Program},
author={Quill Healey and Parth Nobel and Stephen Boyd},
year={2025},
eprint={2508.17522},
archivePrefix={arXiv},
primaryClass={math.OC},
url={https://arxiv.org/abs/2508.17522},
}
Next steps
diffqcp is still in development! WIP features and improvements include:
- Support for the exponential cone, the power cone, and their dual cones.
- Batched problem computations.
- Migration of tests from our torch branch.
- Heuristic JVP and VJP computations when the solution map of a QCP is non-differentiable.
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.
Owner
- Name: Stanford University Convex Optimization Group
- Login: cvxgrp
- Kind: organization
- Location: Stanford, CA
- Website: www.stanford.edu/~boyd
- Repositories: 102
- Profile: https://github.com/cvxgrp
GitHub Events
Total
- Watch event: 8
- Push event: 1
- Public event: 1
Last Year
- Watch event: 8
- Push event: 1
- Public event: 1
Packages
- Total packages: 1
-
Total downloads:
- pypi 105 last-month
- Total dependent packages: 0
- Total dependent repositories: 0
- Total versions: 1
- Total maintainers: 1
pypi.org: diffqcp
Engine to compute Jacobian-vector and vector-Jacobian products for (convex) quadratic cone programs.
- Documentation: https://diffqcp.readthedocs.io/
- License: apache-2.0
-
Latest release: 0.1.0
published 10 months ago
Rankings
Maintainers (1)
Dependencies
- actions/checkout v4 composite
- actions/download-artifact v4 composite
- actions/setup-python v5 composite
- actions/upload-artifact v4 composite
- pypa/gh-action-pypi-publish release/v1 composite
- actions/checkout v4 composite
- astral-sh/setup-uv v6 composite
- equinox >=0.12.2
- jax [cuda12]>=0.6.2
- jaxtyping >=0.3.2
- lineax >=0.0.8
- numpy >=2.3.1
- scipy >=1.15.3