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.

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]

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 in a local optimum. 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 for x: {x.value}')

Limitations

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

  • Slow evaluation of objective functions. Currently the objective function is always evaluated by parsing an expression tree. However, in an ideal world this expression tree would be "compiled" before solving.
  • Only supports SciPy-based solvers. Ideally most other NLP solvers should be easy to add, such as IPOPT, which uses 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 unknowns...

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 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.1.tar.gz (12.1 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.1-py3-none-any.whl (16.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: nvxpy-0.1.1.tar.gz
  • Upload date:
  • Size: 12.1 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.1.tar.gz
Algorithm Hash digest
SHA256 1a27e0c0916c408a23964a76aab11e104b57b5cb36f3c463a1888e0b5cb71244
MD5 e53c1c8a7de684a53b6aaa062cd2cff2
BLAKE2b-256 1c0ea6c4499751acbde36be8dd2ee9847e537820bcc135f5d89b604f82eb7761

See more details on using hashes here.

Provenance

The following attestation bundles were made for nvxpy-0.1.1.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.1-py3-none-any.whl.

File metadata

  • Download URL: nvxpy-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 16.0 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 944ae522ec7e8353f3f910425fab2cecbc2c27d0687ded68bc2487ef50a8d5fa
MD5 a757130ab770ffe48cebbe8cf00e054a
BLAKE2b-256 9333a24372530fb3735a01a060daeb0a437d38d4adb1006f740295f90861da6f

See more details on using hashes here.

Provenance

The following attestation bundles were made for nvxpy-0.1.1-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