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.
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