Skip to main content

Tensorflow implementation of OSQP solver (unofficial)

Project description

TF-OSQP

TF PEP8 License

Tensorflow 2.x implementation of OSQP.

This is not an official OSQP implementation. You can find official versions here.

From their page:

The OSQP (Operator Splitting Quadratic Program) solver is a numerical optimization package for solving problems in the form

minimize        0.5 x' P x + q' x

subject to      l <= A x <= u

where x in R^n is the optimization variable. The objective function is defined by a positive semidefinite matrix P in S^n_+ and vector q in R^n. The linear constraints are defined by matrix A in R^{m x n} and vectors l in R^m U {-inf}^m, u in R^m U {+inf}^m.

Motivation

This project was created as a complement to a new TF2 implementation for the Revised Greedy Expansion algorithm used to find the convex hull of high dimensional vectors. Locating the distance of a point from a convex hull requires the solution of linearly constrained quadratic equations.

Code for that project will be made available soon.

Features

Live in latest release

Full TF 2.x compatibility: All computations use native TF ops

Python side effects absent: Every constant and variable coded as named instances of tf.constant and tf.Variable

Well documented: Docstrings available for all function with constraints and meanings explained for parameters

Future releases

Graph mode execution: Leverage tf.function() to execute code in Graph mode on TF2

Training parameter assignment: Ability to modify training parameters extended to every single parameter

Full OSQP feature set: Remaining features like solution polishing added

Dependencies

Dependency Description Version License
TensorFlow Open source symbolic math library for ML >= 2.4rc3 Apache 2.0
python Base python software >= 3.6 PSF
numpy Used to define nan and inf constants >= 1.18 NumPy License

Installation

Latest PyPI release

pip install tf_osqp

Usage

Having defined tf.float32 matrices P, q, A, l, u, use the code as follows:

from tf_osqp.tf_osqp import solver

quad_solver = solver()
quad_solver.set_problem(P, q, A, l, u)

x, y = quad_solver.solve()

Here, x will be the solution at optima, y will be the corresponding Lagrangian

Contribute

Product backlog

Current implementation is the skeletal engine written to get the work done. It is some way away from full potential.

  • Refactor code to tf.function() to capitalize on speedups from Graph execution
    • Current version uses Eager execution. This constrains performance and speeds are similar to numpy implementation
  • Add remaining OSQP functionality, e.g., solution polishing
  • Make API freer to use, including option for warm starts and changing training parameters between iterations

Code style

Code is written with PEP-8 guidelines - recommended for PRs.

Citations

  1. G. Banjac, P. Goulart, B. Stellato, and S. Boyd, Infeasibility detection in the alternating direction method of multipliers for convex optimization, Journal of Optimization Theory and Applications 183(2019), no. 2, 490–519.
  2. G. Banjac, B. Stellato, N. Moehle, P. Goulart, A. Bemporad, and S. Boyd, Embedded codegeneration using the OSQP solver, IEEE Conference on Decision and Control (CDC), 2017.
  3. M. Schubiger, G. Banjac, and J. Lygeros, GPU acceleration of ADMM for large-scale quadratic programming, Journal of Parallel and Distributed Computing 144(2020), 55–67.
  4. B. Stellato, G. Banjac, P. Goulart, A. Bemporad, and S. Boyd, OSQP: an operator splitting solver for quadratic programs, Mathematical Programming Computation 12(2020), no. 4,637–672.
  5. B. Stellato, V. V. Naik, A. Bemporad, P. Goulart, and S. Boyd, Embedded mixed-integer quadratic optimization using the OSQP solver, European Control Conference (ECC), 2018

The original pure python source code for OSQP can be found on their repo here.

Current implementation in this repo can execute on GPUs but the code hasn't been optimized to offer large speed ups yet. To see better performance on GPUs, the recommendation is to OSQP's recommended CUDA implementation: cuosqp

License

Apache 2.0

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

tf_osqp-0.1.0.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

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

tf_osqp-0.1.0-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tf_osqp-0.1.0.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.0 setuptools/51.0.0.post20201207 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.5

File hashes

Hashes for tf_osqp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c3c77ab33a2f6bf6590f1f2b846da819fb261c5c4acaadb02224f928f7261919
MD5 9da625db5581cd7a5235963f879ce4d2
BLAKE2b-256 1db4279d6eb99d511e2177d603ae555cd5478ab54e5237fc7d64df2a032b9f85

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tf_osqp-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.0 setuptools/51.0.0.post20201207 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.5

File hashes

Hashes for tf_osqp-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8f8380aed11b7a6f7723d2ddb9935a17b29eb03d7f366fd6e1c848bb18fd363c
MD5 5ac02148352f0c51a538c2109a2ac895
BLAKE2b-256 faa64d1d046a24416533115fb0212b66d3fe87dbd6159e8ca4ce8347a493cb31

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