Skip to main content

Numerical optimization/minimization

Project description


CircleCI codecov Codacy grade PyPi Version GitHub stars

optipy contains a generic optimization/minimization method. Its creation was motivated by the absence of an implementation of Newton's method with a custom Hessian solver in SciPy (see this bug).

The mandatory Rosenbrock example:

a = 1.0
b = 100.0

def fun(x):
    return (a-x[0])**2 + b*(x[1] - x[0]**2)**2

def jac(x):
    return numpy.array([
        -2*(a-x[0]) - 4*b*(x[1] - x[0]**2) * x[0],
        2*b*(x[1] - x[0]**2)

def hess_inv(x, grad):
    hess = numpy.array([
        [2 + 8*b*x[0]**2 - 4*b*(x[1] - x[0]**2), -4*b*x[0]],
        [-4*b*x[0], 2*b]
    return -numpy.linalg.solve(hess, grad)

sol = optipy.minimize(
    x0=[-1.0, 3.5],

This is basically the exact Newton method. When setting get_search_direction to lambda x, grad: -grad, one gets the steepest descent method. For larger computations, one will typically replace this with a tailored solver, e.g., a preconditioned Krylov solver.

The return type is largely compatible with SciPy's generic return type, OptmizeResult.


optipy is available from the Python Package Index, so simply do

pip install -U optipy

to install or upgrade. Use sudo -H to install as root or the --user option of pip to install in $HOME.


To run the optipy unit tests, check out this repository and type



To create a new release

  1. bump the __version__ number,

  2. publish to PyPi and tag on GitHub:

    $ make publish


optipy is published under the MIT license.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for optipy, version 0.1.0
Filename, size File type Python version Upload date Hashes
Filename, size optipy-0.1.0-py2.py3-none-any.whl (3.9 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size optipy-0.1.0.tar.gz (3.9 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page