Skip to content

cvxgrp/DNLP

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3,919 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DNLP — Disciplined Nonlinear Programming

The DNLP package is an extension of CVXPY to general nonlinear programming (NLP). DNLP allows smooth functions to be freely mixed with nonsmooth convex and concave functions, with some rules governing how the nonsmooth functions can be used. For details, see our paper Disciplined Nonlinear Programming.


Installation

The installation consists of two steps.

Step 1: Install IPOPT

DNLP requires an NLP solver. The recommended solver is Ipopt. First install the IPOPT system library, then install the Python interface cyipopt:

# Ubuntu/Debian
sudo apt-get install coinor-libipopt-dev

# macOS
brew install ipopt

# Windows
conda install -c conda-forge ipopt

Then install the Python interface:

pip install cyipopt

Step 2: Install DNLP

DNLP is installed by cloning this repository and installing it locally:

git clone https://github.com/cvxgrp/DNLP.git
cd DNLP
pip install .

Example

Below we give a toy example where we maximize a convex quadratic function subject to a nonlinear equality constraint. Many more examples, including the ones in the paper, can be found at DNLP-examples.

import cvxpy as cp
import numpy as np

# problem data
np.random.seed(0)
n = 3
A = np.random.randn(n, n)
A = A.T @ A

# formulate optimization problem
x = cp.Variable(n)
obj = cp.Maximize(cp.quad_form(x, A))
constraints = [cp.sum_squares(x) == 1]

# initialize and solve
x.value = np.ones(n)
prob = cp.Problem(obj, constraints)
prob.solve(nlp=True, verbose=True)
print("Optimal value from DNLP: ", prob.value)

# the optimal value for this toy problem can also be found by computing the maximum eigenvalue of A
eigenvalues  = np.linalg.eigvalsh(A)
print("Maximum eigenvalue:      " , np.max(eigenvalues))

Supported Solvers

Solver License Installation
IPOPT EPL-2.0 Install system IPOPT (see above), then pip install cyipopt
Knitro Commercial pip install knitro (requires license)
UNO MIT See Uno
COPT Commercial Requires license

Differentiation Engine

DNLP uses SparseDiffPy as its differentiation engine. SparseDiffPy is a Python wrapper around the SparseDiffEngine C library, and is installed automatically as a dependency of DNLP.

SparseDiffPy builds an expression tree from the CVXPY problem and computes exact sparse gradients, Jacobians, and Hessians required by the NLP solvers.

About

Disciplined nonlinear programming extension of CVXPY.

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • C++ 63.3%
  • Python 35.1%
  • C 1.4%
  • Linear Programming 0.1%
  • Makefile 0.1%
  • Shell 0.0%