Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 50 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,64 @@
NLopt Python
============

[![PyPI version](https://badge.fury.io/py/nlopt.svg)](https://badge.fury.io/py/nlopt)
![Build](https://github.com/DanielBok/nlopt-python/workflows/Build/badge.svg?branch=master)
[![PyPI version](https://badge.fury.io/py/nlopt.svg)](https://pypi.org/project/nlopt/)
[![PyPI downloads](https://img.shields.io/pypi/dm/nlopt.svg)](https://pypi.org/project/nlopt/)
[![Python versions](https://img.shields.io/pypi/pyversions/nlopt.svg)](https://pypi.org/project/nlopt/)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
[![Build](https://github.com/DanielBok/nlopt-python/actions/workflows/build.yml/badge.svg)](https://github.com/DanielBok/nlopt-python/actions/workflows/build.yml)
[![Nightly Build](https://github.com/DanielBok/nlopt-python/actions/workflows/nightly-build.yml/badge.svg)](https://github.com/DanielBok/nlopt-python/actions/workflows/nightly-build.yml)
[![Documentation](https://img.shields.io/badge/docs-readthedocs-blue.svg)](https://nlopt.readthedocs.io/en/latest/NLopt_Python_Reference/)

This project builds Python wheels for the NLopt library. NLopt contains various routines for non-linear optimization.
Python wheels for [NLopt](https://github.com/stevengj/nlopt), a library for nonlinear optimization. NLopt provides
a common interface to a large collection of optimization algorithms, both global and local, gradient-based and
derivative-free, for constrained or unconstrained problems.

## Versions supported

The project supports Python versions 3.9+ and above for Windows, MacOS, and Linux.
This project exists to make installing NLopt in Python as simple as `pip install nlopt` — no compiler, SWIG, or
system NLopt installation required. Prebuilt wheels are published for Windows, macOS, and Linux.

## Installation

```bash
pip install nlopt
```

Prebuilt wheels are available for Python 3.10+ on Windows, macOS, and Linux (x86_64 and arm64). If no matching
wheel is found for your platform, pip will fall back to building from source, which requires SWIG and a C++
compiler.

## Usage

```python
import nlopt
import numpy as np

def objective(x, grad):
return x[0] ** 2 + x[1] ** 2

opt = nlopt.opt(nlopt.LN_COBYLA, 2)
opt.set_min_objective(objective)
opt.set_lower_bounds([-10, -10])
opt.set_upper_bounds([10, 10])
opt.set_xtol_rel(1e-6)

x = opt.optimize(np.array([1.0, 1.0]))
print(f"Minimum found at {x}, value = {opt.last_optimum_value()}")
```

## Documentation

For more information on how to use NLopt, refer to the [documentation](https://nlopt.readthedocs.io/en/latest/NLopt_Python_Reference/).
Full API documentation, including the list of supported algorithms, is available at
[nlopt.readthedocs.io](https://nlopt.readthedocs.io/en/latest/NLopt_Python_Reference/).

## Releases

Builds run nightly and publish dev versions to [TestPyPI](https://test.pypi.org/project/nlopt/) so regressions
surface before a real release. Stable releases are cut from tagged GitHub Releases and published to
[PyPI](https://pypi.org/project/nlopt/). The vendored `extern/nlopt` submodule is checked daily against upstream
and bumped automatically via PR when a new NLopt version is released.

## License

This project wraps [NLopt](https://github.com/stevengj/nlopt), whose underlying routines are covered by a mix
of licenses (mainly MIT and LGPL) depending on the algorithm — see [LICENSE](LICENSE) for details. The Python
packaging in this repository is licensed under MIT.
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ classifiers =
Operating System :: Microsoft :: Windows
Operating System :: Unix
Programming Language :: C++
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.11
Programming Language :: Python :: 3.12
Programming Language :: Python :: 3.13
Programming Language :: Python :: 3.14
Topic :: Scientific/Engineering

[options]
python_requires = >= 3.9
python_requires = >= 3.10
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

setup(
version=version,
python_requires=">=3.9",
python_requires=">=3.10",
install_requires=["numpy >=2,<3"],
setup_requires=["numpy >=2,<3"],
ext_modules=[NLOptBuildExtension("nlopt._nlopt", version)],
Expand Down
Loading