Skip to main content

A fully first-order (FFO) layer for differentiable convex optimization

Project description

This is the implementation of fully first-order bilevel gradient to replace the non-fully first-order methods in differentiable optimization. The main comparison is qpth and cvxpylayer. Our method provides a fully first-order method to differentiate through optimization layers approximately. It has the advantage in computation and memory efficiency, but in the tradeoff of the accuracy of the gradient.

Please install the required packages:


1) Decision-focused learning (QP case)

Key files

  • main.py — entrypoint for all methods
  • ffoqp.py - previous ffo version with l2 penalty
  • ffoqp_eq_cst.py - new ffo version without l2 penalty (faster convergence in theory)
  • ffoqp_eq_cst_schur/pdipm/parallelize.py - try to accelerate ffoqp_eq_cst

To run the code, please use:

python main.py --method=ffoqp_eq_cst --eps=0.1 --lr=0.00001 --ydim=200
python main.py --method=ffoqp --eps=0.1 --lr=0.00001 --ydim=200
python main.py --method=cvxpylayer --eps=0.1 --lr=0.00001 --ydim=200
python main.py --method=qpth --eps=0.1 --lr=0.00001 --ydim=200

(optional)
python main.py --method=ffoqp_eq_cst_pdipm --eps=0.1 --lr=0.00001 --ydim=200
python main.py --method=ffoqp_eq_cst_parallelize --eps=0.1 --lr=0.00001 --ydim=200
python main.py --method=ffoqp_eq_cst_schur --eps=0.1 --lr=0.00001 --ydim=200

I ran a few simple experiments to compare the performance of the three methods. Each epoch includes 2048 samples (split into training and testing) to run decision-focused leanring (end-to-end learning).

For optimization problems of size 200, the computation results are as follows (please run plot_toy_dfl.ipynb to reproduce it) image

The computation improvement can only be seen in larger instances of the optimization problem. This is likely due to the dominance of the overhead in the forward process to solve the optimization problem. Only when the size goes larger, the backward process of the optimization problem becomes more expensive than the forward process. In smaller instances, the overhead in the forward process dominates the computation time, and thus the improvement in the backward process is not significant enough to be observed. qpth also uses a faster algorithm to parallelize and implement the forward pass, which is why qpth is faster than cvxpylayer (in theory they are the same).


2) Second-order Cone program

To run the code, please run:

ffoqsocp_test.ipynb

We found that ffoqp's gradient approximation is more accurate than LPGD in this case.


3) Sudoku (differentiable optimization as a layer)

Key files

  • sudoku/main_sudoku.py — entrypoint for all methods
  • ffocp_eq.py - new ffo version for general convex problem without l2 penalty
  • cvxpylayers_local/cvxpylayer.py - incorporate the latest diffcp into cvxpylayer to support LPGD

To run the code, please use:

python sudoku/main_sudoku.py --method ffocp --n 3 --epoch 1 --batch_size 8
python sudoku/main_sudoku.py --method lpgd --n 3 --epoch 1 --batch_size 8
python sudoku/main_sudoku.py --method ffoqp --n 3 --epoch 1 --batch_size 8
python sudoku/main_sudoku.py --method cvxpylayer --n 3 --epoch 1 --batch_size 8
python sudoku/main_sudoku.py --method qpth --n 3 --epoch 1 --batch_size 8

To plot the results, please use

python sudoku/plot_results.py

Now we observed that LPGD has a very high test error (~0.9), while ffocp and other methods can achieve low test errors (~0.01-0.1).

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

ffolayer-0.1.1.tar.gz (32.6 kB view details)

Uploaded Source

Built Distribution

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

ffolayer-0.1.1-py3-none-any.whl (25.9 kB view details)

Uploaded Python 3

File details

Details for the file ffolayer-0.1.1.tar.gz.

File metadata

  • Download URL: ffolayer-0.1.1.tar.gz
  • Upload date:
  • Size: 32.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.14

File hashes

Hashes for ffolayer-0.1.1.tar.gz
Algorithm Hash digest
SHA256 eb371e58d1681e613de05999648cdb853363addfe0cbc8a31ed435adfd9de406
MD5 99f70f455b0c0a2fd428c7dfb22a7c2e
BLAKE2b-256 336e9109c7e982c7efd9525d046a2d8de456badaa57bb68e1261f3cd29d8f9e5

See more details on using hashes here.

File details

Details for the file ffolayer-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: ffolayer-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 25.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.14

File hashes

Hashes for ffolayer-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 084e8f21eca599f2546546321c9927a754bccf984644ff01c351c3030455e798
MD5 af595e603aa8f27e44c0edfd62ede34f
BLAKE2b-256 daf986e7726a5818db1a463bf0db508d21f53a477a84826b3c08c91391f2ab34

See more details on using hashes here.

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