Examples¶
Explore CVXPYlayers through interactive notebooks and scripts.
Quick Start¶
Most popular for deep learning. Full torch.nn.Module integration with autograd support.
Functional style with jax.grad and jax.vmap. Support for jax.jit coming soon.
Optimized for Apple Silicon. Unified memory for M1/M2/M3 chips.
Tutorials¶
Step-by-step introductions to CVXPYlayers:
Complete walkthrough of defining problems, creating layers, and training.
Learn to use CVXPYlayers with JAX transformations.
Control Systems¶
Learn optimal value function parameters for LQR control.
LQR with control input bounds and state constraints.
Autonomous vehicle trajectory optimization.
MPC with learned cost-to-go function.
Convex approximations for dynamic programming problems.
Finance & Portfolio Optimization¶
Classic mean-variance optimization with dynamic rebalancing.
Volatility-aware portfolio optimization using VIX index.
Machine Learning¶
Learning monotonic input-output relationships.
Signal/image denoising with learned parameters.
Optimization layers with ReLU activations.
Adversarial attacks on machine learning models.
Resource Allocation¶
Water and resource distribution optimization.
Supply chain network flow optimization.
Engineering¶
Optimizing mechanical stiffness parameters.
Geometric program for transistor sizing with gp=True. Sensitivity analysis of delay vs. area/power budgets.
Optimization Techniques¶
Batched solving, parameter broadcasting, and dual variable extraction for portfolio optimization.
Learn the right amount of robustness from data. Worst-case design under uncertainty.
Neural net + CvxpyLayer end-to-end pipeline. Decision-focused learning vs. two-stage training.
Fit a convex piecewise-linear function (max-of-affines) to data via SGD.
Running Locally¶
Clone and run any example:
git clone https://github.com/cvxpy/cvxpylayers.git
cd cvxpylayers
pip install -e ".[torch]"
pip install matplotlib jupyter
# Run a notebook
jupyter notebook examples/torch/lqr.ipynb