Skip to main content

A parallel version of the L-BFGS-B optimizer of scipy.optimize.minimize().

Project description

optimparallel - A parallel version of scipy.optimize.minimize(method='L-BFGS-B')

DOI PyPI Build Status Codacy Badge License: GPL v3

Using optimparallel.minimize_parallel() can significantly reduce the optimization time. For an objective function with an execution time of more than 0.1 seconds and p parameters the optimization speed increases by up to factor 1+p when no analytic gradient is specified and 1+p processor cores with sufficient memory are available.

A similar extension of the L-BFGS-B optimizer exists in the R package optimParallel:

Installation

To install the package run:

$ pip install optimparallel

Usage

Replace scipy.optimize.minimize(method='L-BFGS-B') by optimparallel.minimize_parallel() to execute the minimization in parallel:

from optimparallel import minimize_parallel
from scipy.optimize import minimize
import numpy as np
import time

## objective function
def f(x, sleep_secs=.5):
    print('fn')
    time.sleep(sleep_secs)
    return sum((x-14)**2)

## start value
x0 = np.array([10,20])

## minimize with parallel evaluation of 'fun' and
## its approximate gradient.
o1 = minimize_parallel(fun=f, x0=x0, args=.5)
print(o1)

## test against scipy.optimize.minimize()
o2 = minimize(fun=f, x0=x0, args=.5, method='L-BFGS-B')
print(all(np.isclose(o1.x, o2.x, atol=1e-10)),
      np.isclose(o1.fun, o2.fun, atol=1e-10),
      all(np.isclose(o1.jac, o2.jac, atol=1e-10)))

The evaluated x values, fun(x), and jac(x) can be returned:

o1 = minimize_parallel(fun=f, x0=x0, args=.5, parallel={'loginfo': True})
print(o1.loginfo)

More examples are given in example.py and the Jupyter Notebook example_extended.ipynb.

Note for Windows users: It may be necessary to run minimize_parallel() in the main scope. See example_windows_os.py.

Citation

When using this package please cite:

Author

Contributor

  • Lewis Blake

Contributions

Contributions via pull requests are welcome.

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

optimparallel-0.1.2.tar.gz (39.5 kB view details)

Uploaded Source

Built Distributions

optimparallel-0.1.2-py3.8.egg (13.2 kB view details)

Uploaded Source

optimparallel-0.1.2-py3-none-any.whl (19.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: optimparallel-0.1.2.tar.gz
  • Upload date:
  • Size: 39.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.5

File hashes

Hashes for optimparallel-0.1.2.tar.gz
Algorithm Hash digest
SHA256 afb17175d465426ff6747fef271aa5cdcc14c76882cad3f49d25efde4c39e1e8
MD5 c00cf1d1c33da8c3327dd0f78cab6d95
BLAKE2b-256 8db17e40ce7fe103c97101ea1f8818fff3e87288ed8bdb23185daed36d04081e

See more details on using hashes here.

File details

Details for the file optimparallel-0.1.2-py3.8.egg.

File metadata

  • Download URL: optimparallel-0.1.2-py3.8.egg
  • Upload date:
  • Size: 13.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.5

File hashes

Hashes for optimparallel-0.1.2-py3.8.egg
Algorithm Hash digest
SHA256 d138e22004e2a27c1e39bf12bd3e03a6cdfaec8f301b199b409acd701c72a787
MD5 dae2362dc8334cd66cf8756558bef440
BLAKE2b-256 7d5f069ce2ae044ab05ff0ce2883dbf3b54152ccc81e1b5f1ae74fd6c02996c5

See more details on using hashes here.

File details

Details for the file optimparallel-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: optimparallel-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 19.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.5

File hashes

Hashes for optimparallel-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d4bb631392ba9e949dc1bbcdaf4f9160a10f2d8994544679fe9ea3ea3212325d
MD5 f9e4afd66a19e3be031f441ad41bad8a
BLAKE2b-256 e6eabe427b3ede783dc45d26b29ded588be080eabbf73c10c813167514d4dc93

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page