spinopt


Namespinopt JSON
Version 24.7.2 PyPI version JSON
download
home_pageNone
SummaryScipy interface to NLOPT
upload_time2025-07-24 21:37:15
maintainerNone
docs_urlNone
authorMartin van der Schans
requires_pythonNone
licenseNone
keywords optimization
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # SpiNopt: a Scipy optimization interface to NLOPT

For optimization, everyone starts out with the [Scipy optimization library](https://docs.scipy.org/doc/scipy/tutorial/optimize.html), but, at some point, you might want to try something else.
[NLOPT](https://nlopt.readthedocs.io/en/latest/) is a great library, but can be quite a hassle rewrite your code to use it.

This package provides a Scipy interface to the NLOPT optimization library. It's aim is not to provide a complete ecosystem which different solvers are available, but merely a way to quickly connect the NLOPT solvers, once you already have something set up with Scipy, or are familiar with how to set something up with Scipy.

## Basic example

```python
import numpy as np
from spinopt import NLOptimizer

dim = 3

# Define objective in this way
def my_easy_func(x, grad):
    if grad.size > 0:
        grad[:] = 2 * (x - np.arange(len(x)))
    x = x - np.arange(len(x))
    return x.dot(x)

# Define constraints Scipy style
A = np.ones((1, dim))
b = np.ones((1, 1))
constraints = [{"type": "eq", "jac": lambda w: A, "fun": lambda w: A.dot(w) - b.squeeze()}]

# Initialize optimizer
x0=np.zeros(dim)
opt = NLOptimizer(my_easy_func, x0, constraints=constraints)

# Optimize
res = opt.minimize()
assert res.success
assert np.allclose(res.x, np.arange(dim), atol=1e-5)
```

## Installation

To install from PyPI:

```bash
pip install spinopt
```

To install the latest development version from github:

```bash
pip install git+https://github.com/mvds314/spinopt.git
```

## Development

For development purposes, clone the repo:

```bash
git clone https://github.com/mvds314/spinopt.git
```

Then navigate to the folder containing `setup.py` and run

```bash
pip install -e .
```

to install the package in edit mode.

Run unittests with `pytest`.

## Related software

- [Scipy optimize](https://docs.scipy.org/doc/scipy/tutorial/optimize.html)
- [NLOPT](https://nlopt.readthedocs.io/en/latest/)


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "spinopt",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "Optimization",
    "author": "Martin van der Schans",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/39/ef/51460adc847582a748b2b9577753df1bc8deb5dd149c8e5472a4089e9ff1/spinopt-24.7.2.tar.gz",
    "platform": null,
    "description": "# SpiNopt: a Scipy optimization interface to NLOPT\n\nFor optimization, everyone starts out with the [Scipy optimization library](https://docs.scipy.org/doc/scipy/tutorial/optimize.html), but, at some point, you might want to try something else.\n[NLOPT](https://nlopt.readthedocs.io/en/latest/) is a great library, but can be quite a hassle rewrite your code to use it.\n\nThis package provides a Scipy interface to the NLOPT optimization library. It's aim is not to provide a complete ecosystem which different solvers are available, but merely a way to quickly connect the NLOPT solvers, once you already have something set up with Scipy, or are familiar with how to set something up with Scipy.\n\n## Basic example\n\n```python\nimport numpy as np\nfrom spinopt import NLOptimizer\n\ndim = 3\n\n# Define objective in this way\ndef my_easy_func(x, grad):\n    if grad.size > 0:\n        grad[:] = 2 * (x - np.arange(len(x)))\n    x = x - np.arange(len(x))\n    return x.dot(x)\n\n# Define constraints Scipy style\nA = np.ones((1, dim))\nb = np.ones((1, 1))\nconstraints = [{\"type\": \"eq\", \"jac\": lambda w: A, \"fun\": lambda w: A.dot(w) - b.squeeze()}]\n\n# Initialize optimizer\nx0=np.zeros(dim)\nopt = NLOptimizer(my_easy_func, x0, constraints=constraints)\n\n# Optimize\nres = opt.minimize()\nassert res.success\nassert np.allclose(res.x, np.arange(dim), atol=1e-5)\n```\n\n## Installation\n\nTo install from PyPI:\n\n```bash\npip install spinopt\n```\n\nTo install the latest development version from github:\n\n```bash\npip install git+https://github.com/mvds314/spinopt.git\n```\n\n## Development\n\nFor development purposes, clone the repo:\n\n```bash\ngit clone https://github.com/mvds314/spinopt.git\n```\n\nThen navigate to the folder containing `setup.py` and run\n\n```bash\npip install -e .\n```\n\nto install the package in edit mode.\n\nRun unittests with `pytest`.\n\n## Related software\n\n- [Scipy optimize](https://docs.scipy.org/doc/scipy/tutorial/optimize.html)\n- [NLOPT](https://nlopt.readthedocs.io/en/latest/)\n\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Scipy interface to NLOPT",
    "version": "24.7.2",
    "project_urls": {
        "repository": "https://github.com/mvds314/spinopt"
    },
    "split_keywords": [
        "optimization"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "90e72c7f134cf63f81e76aa6a7c4477a0cb8845a501482ec37a7805107752500",
                "md5": "c9cc8c99fac6d907c808cb5352625c05",
                "sha256": "d9e37ebcaf16735f44eba68afcfa1ab96f8855833e70c1b5c2d4d9661ac6d82f"
            },
            "downloads": -1,
            "filename": "spinopt-24.7.2-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c9cc8c99fac6d907c808cb5352625c05",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 6647,
            "upload_time": "2025-07-24T21:37:14",
            "upload_time_iso_8601": "2025-07-24T21:37:14.929780Z",
            "url": "https://files.pythonhosted.org/packages/90/e7/2c7f134cf63f81e76aa6a7c4477a0cb8845a501482ec37a7805107752500/spinopt-24.7.2-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "39ef51460adc847582a748b2b9577753df1bc8deb5dd149c8e5472a4089e9ff1",
                "md5": "4c07b197a5d77640df42173c3089bbc2",
                "sha256": "26355e41729e9a20aa0e7ad2fbc9e027d682f56af597a99ea5e7bfd7352fc04e"
            },
            "downloads": -1,
            "filename": "spinopt-24.7.2.tar.gz",
            "has_sig": false,
            "md5_digest": "4c07b197a5d77640df42173c3089bbc2",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 6097,
            "upload_time": "2025-07-24T21:37:15",
            "upload_time_iso_8601": "2025-07-24T21:37:15.938248Z",
            "url": "https://files.pythonhosted.org/packages/39/ef/51460adc847582a748b2b9577753df1bc8deb5dd149c8e5472a4089e9ff1/spinopt-24.7.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-24 21:37:15",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "mvds314",
    "github_project": "spinopt",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "spinopt"
}
        
Elapsed time: 0.76075s