Skip to main content

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

DOI PyPI Build Status 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=0.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=0.5)
print(o1)

# test against scipy.optimize.minimize()
o2 = minimize(fun=f, x0=x0, args=0.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=0.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

Contributions

Contributions via pull requests are welcome.

Metadata

Release files for optimparallel 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for optimparallel 0.1.3
File Size Uploaded Provenance Actions
optimparallel-0.1.3.tar.gz 39.1 kB Without provenance Details for optimparallel-0.1.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for optimparallel 0.1.3
File Interpreter ABI Platform Actions
optimparallel-0.1.3-py3-none-any.whl Python 3 none any Details for optimparallel-0.1.3-py3-none-any.whl

Total release size: 59.1 kB

Release files / optimparallel-0.1.3.tar.gz

Download URL optimparallel-0.1.3.tar.gz
Size 39.1 kB
Tags Source
SHA-256 checksum
How to use checksums
f7247e841103f15d39d089ef267e31c4015d64a1115364c8d2bbc6a2b1500c4e
BLAKE2b-256 checksum
How to use checksums
82f548d9744d1474c52abd63eda35dc2ac46cff849046b90428c0a1170668cd2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.18

Release files / optimparallel-0.1.3-py3-none-any.whl

Download URL optimparallel-0.1.3-py3-none-any.whl
Size 20.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
149ae449158c31516c82f4d50a128c7aac9c9e40d60d074fbc5fc29da03a5e88
BLAKE2b-256 checksum
How to use checksums
38deb37b5d92ea66c824ddf2b27abfd3fc10251ccc3dc653a6ec52ba78e70b3f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.18

Security for optimparallel 0.1.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page