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 of 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 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 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.2.tar.gz (12.3 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.2-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: nvxpy-0.1.2.tar.gz
  • Upload date:
  • Size: 12.3 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.2.tar.gz
Algorithm Hash digest
SHA256 52b715d2146ef63668b6cc3b08e0345248be680eed760f9ecf6bceec6b86af33
MD5 b3e3470bb4a2c78de8742d9e17d45771
BLAKE2b-256 427346ab7398913dd2b9ffb24901aec5621bc03ed4455ea05ee79b79da535408

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: nvxpy-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 16.2 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d89d44d933a91254bc01f60caac6a65b828d9ffe24f26a083e04056b90d670d5
MD5 7c96665ae819a647114a330b9a4be865
BLAKE2b-256 1c67bd6cab392c4d2880da1e67c1e753286cfeb336bd4b8f354e5773e0108e3f

See more details on using hashes here.

Provenance

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