Skip to main content

A Python DSL for simply and easily formulating and solving non-convex optimization problems.

Project description

NVXPY

Build Status codecov

Overview

NVXPY is a Python-based Domain Specific Language (DSL) designed for formulating and solving non-convex programs using a natural, math-inspired API. It is designed to have as similar an interface to CVXPY as possible.

NVXPY is not a solver, it uses the solvers exposed by the minimize method in SciPy.

Features

  • Simple, concise, and generic interface
  • Mediocre efficiency for expression tree evaluations (estimated at 60% - 99% native NumPy)
  • Handles gradients seemlessly, even for custom and non-Autograd functions

Installation

NVXPY can be installed from PyPi using:

pip install nvxpy

and has the following dependencies:

  • Python >= 3.11
  • NumPy >= 2.3
  • SciPy >= 1.15
  • Autograd >= 1.8

Usage

The following is a simple example to get started with NVXPY:

import numpy as np
import nvxpy as nvx

x = nvx.Variable((3,))
x.value = np.array([-5.0, 0.0, 0.0]) # NLPs require a seed.

x_d = np.array([5.0, 0.0, 0.0])

obj = nvx.norm(x - x_d)
constraints = [nvx.norm(x) >= 1.0] # Non-convex!

prob = nvx.Problem(nvx.Minimize(obj), constraints)
prob.solve(solver=nvx.SLSQP)

print(f'optimized value of x: {x.value}')

The above code will likely get stuck at a locally optimal solution. To reach the globally optimal solution, we can adjust the seed and re-solve as follows:

x.value = np.array([-5.0, 1.0, 1.0])
prob.solve(solver=nvx.SLSQP)

print(f'globally optimal value of x: {x.value}')

Limitations

NVXPY is in early development. The most pressing issues are as follows:

  • Only supports SciPy-based solvers. Ideally most other NLP solvers should be easy to add, such as IPOPT, which provides a similar API to the minimize function from SciPy.
  • No plans to support integer programming any time soon. One potential solution is to make a SLP-inspired solver based on the MILP solver from SciPy to enforce integrality constraints. However, any custom solver would probably be out of the scope of this project.
  • Small amount of atomic operations and sets.
  • Unknown and untested edge cases.

Development

To contribute to NVXPY, clone the repository and install the development dependencies:

git clone https://github.com/landonclark97/nvxpy.git
cd nvxpy
poetry install --with dev

Running Tests

Tests are written using pytest. To run the tests, execute:

poetry run pytest

License

Apache 2.0

Contact

For any inquiries or issues, please contact Landon Clark at landonclark97@gmail.com.

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

nvxpy-0.1.3.tar.gz (15.6 kB view details)

Uploaded Source

Built Distribution

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

nvxpy-0.1.3-py3-none-any.whl (21.8 kB view details)

Uploaded Python 3

File details

Details for the file nvxpy-0.1.3.tar.gz.

File metadata

  • Download URL: nvxpy-0.1.3.tar.gz
  • Upload date:
  • Size: 15.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for nvxpy-0.1.3.tar.gz
Algorithm Hash digest
SHA256 ceb6fef46d457c11f3b0bc1857dc320557fd7b04d7a91950bbbdd5b26dfbb356
MD5 a40caa444cc48f06a67eac1dfa2205df
BLAKE2b-256 0fbc060cf6e1d779bbbc16316900782ab69c6e578652adb7a4cae2d8dac546fc

See more details on using hashes here.

Provenance

The following attestation bundles were made for nvxpy-0.1.3.tar.gz:

Publisher: publish.yaml on landonclark97/nvxpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nvxpy-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: nvxpy-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 21.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for nvxpy-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c307a4e2a36e5170b3a3f8cda112b14f90497be5c63f33ab5f262fef0cb34dbb
MD5 4e87c72a8d599ea080d47ec24c620ee2
BLAKE2b-256 0da81444573b2fa06838c39b0383eb6f6e0a5221fb18742c2b3eddbd23dd8167

See more details on using hashes here.

Provenance

The following attestation bundles were made for nvxpy-0.1.3-py3-none-any.whl:

Publisher: publish.yaml on landonclark97/nvxpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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