A Python DSL for simply and easily formulating and solving non-convex optimization problems.
Project description
NVXPY
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
minimizefunction 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
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ceb6fef46d457c11f3b0bc1857dc320557fd7b04d7a91950bbbdd5b26dfbb356
|
|
| MD5 |
a40caa444cc48f06a67eac1dfa2205df
|
|
| BLAKE2b-256 |
0fbc060cf6e1d779bbbc16316900782ab69c6e578652adb7a4cae2d8dac546fc
|
Provenance
The following attestation bundles were made for nvxpy-0.1.3.tar.gz:
Publisher:
publish.yaml on landonclark97/nvxpy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nvxpy-0.1.3.tar.gz -
Subject digest:
ceb6fef46d457c11f3b0bc1857dc320557fd7b04d7a91950bbbdd5b26dfbb356 - Sigstore transparency entry: 295908547
- Sigstore integration time:
-
Permalink:
landonclark97/nvxpy@e2463166c1e228cb5d2b17df521e88c8f7bece51 -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/landonclark97
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@e2463166c1e228cb5d2b17df521e88c8f7bece51 -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c307a4e2a36e5170b3a3f8cda112b14f90497be5c63f33ab5f262fef0cb34dbb
|
|
| MD5 |
4e87c72a8d599ea080d47ec24c620ee2
|
|
| BLAKE2b-256 |
0da81444573b2fa06838c39b0383eb6f6e0a5221fb18742c2b3eddbd23dd8167
|
Provenance
The following attestation bundles were made for nvxpy-0.1.3-py3-none-any.whl:
Publisher:
publish.yaml on landonclark97/nvxpy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nvxpy-0.1.3-py3-none-any.whl -
Subject digest:
c307a4e2a36e5170b3a3f8cda112b14f90497be5c63f33ab5f262fef0cb34dbb - Sigstore transparency entry: 295908590
- Sigstore integration time:
-
Permalink:
landonclark97/nvxpy@e2463166c1e228cb5d2b17df521e88c8f7bece51 -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/landonclark97
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@e2463166c1e228cb5d2b17df521e88c8f7bece51 -
Trigger Event:
release
-
Statement type: