Skip to main content

bam-solver

Python wrapper for the BAM (Branch-And-Model) derivative-free global optimization solver.

Three layers of API ergonomics:

  1. bam.minimize: SciPy-style functional facade.
  2. Bam: full-control mirror of the BAM C API.
  3. bam.AskTell: ask/tell interface for off-process or asynchronous evaluators.

Requirements

  • Python >= 3.10
  • Linux (x86_64, aarch64), macOS (Intel, Apple Silicon), or Windows (x86_64)

No compiler and no separate BAM installation are needed: each wheel bundles libbam and its runtime libraries inside the package. The only runtime dependencies are NumPy and CFFI, installed automatically.

Installation

pip install bam-solver

This needs Python 3.10 or newer (64-bit) on one of the platforms listed under Requirements. On an older Python, or on an unsupported platform, pip finds no compatible wheel and reports only

ERROR: Could not find a version that satisfies the requirement bam-solver (from versions: none)
ERROR: No matching distribution found for bam-solver

Check the interpreter with python --version and, if needed, install into an environment with a newer Python, for example conda create -n bam python=3.12 or python3.12 -m venv bam-env.

That is all; there is nothing else to install or configure to start solving. BAM runs in free mode for small problems; larger problems need a license (see Licensing below).

Building from source (maintainers/contributors only) requires a local BAM build providing bam.h and libbam.*:

BAM_INCLUDE_DIR=/path/to/bam/include BAM_LIB_DIR=/path/to/bam/lib \
    uv build --wheel

See release/README.md for the full in-house build/test/publish process.

Quick examples

Functional (SciPy-style): bam.minimize

import bam

def shc(x):
    x1, x2 = x
    return ((4 - 2.1*x1**2 + x1**4/3) * x1**2
            + x1*x2 + (-4 + 4*x2**2) * x2**2)

res = bam.minimize(shc, x0=[0, 0],
                   bounds=[(-3, 3), (-1.5, 1.5)],
                   options={"max_evals": 80})
print(res.x, res.fun, res.nfev, res.message)

bam.minimize is also usable as the method= argument to scipy.optimize.minimize:

from scipy.optimize import minimize
res = minimize(shc, [0, 0], method=bam.minimize,
               bounds=[(-3, 3), (-1.5, 1.5)],
               options={"max_evals": 80})

Bounds are optional: omit them and BAM uses its default box, exactly as the full-control Bam class and the C API do. Common BAM options keys: max_evals, max_time, max_iter, max_no_gain, print_to_screen, outfname, tracefname, evalsfname, prevals; setting outfname/tracefname enables the listing/trace file, and evalsfname is required whenever prevals is nonzero. Any other BAM option is forwarded verbatim with a single warning naming it, or pass it through raw_options={"name": value} to forward without the warning. The wrapper also accepts x_evaluated/f_evaluated (pre-evaluated points) and history=True (attaches the full x_hist/f_hist evaluation trajectory to the result). Use integrality=[0, 1, ...] for mixed-integer problems (SciPy convention).

Ask/tell: bam.AskTell

For evaluators that BAM cannot call directly (a remote simulator, a long-running batch job, an HPC scheduler):

import bam

opt = bam.AskTell(nvars=2, bounds=[(-3, 3), (-1.5, 1.5)], max_evals=80)
while not opt.is_done():
    try:
        x = opt.ask()
    except StopIteration:
        break
    f = my_simulator(x)             # may take seconds, minutes, hours
    opt.tell(x, f)
res = opt.recommendation()
print(res.x, res.fun)

BAM runs in a background thread; ask() blocks until BAM requests a point, tell(x, f) feeds the result back. Bounds are optional here too (nvars gives the dimension). Use the context-manager form (with bam.AskTell(...) as opt: ...) so the worker thread is always cleaned up. One ask outstanding at a time; pickling / cross-process resume is not supported.

Full-control: Bam

import numpy as np
from bam import Bam

with Bam(nvars=2) as solver:
    solver.set_real_vector("xmin", [-3, -1.5])
    solver.set_real_vector("xmax", [ 3,  1.5])
    solver.set_int("maxevals", 80)
    solver.set_objective(shc)
    result = solver.solve(x0=[0.0, 0.0])

print(result.x, result.fun, result.nfev, result.message)

Licensing

BAM is free for problems with up to two variables. Larger problems require a license file, free for academic users at https://minlp.com/bam-licenses.

The wrapper defers to BAM for license-file discovery; BAM searches CWD, the executable's directory, and every entry of $PATH for a file whose name is configured via the licfname string option (default bamlice.txt). To override:

import bam
bam.set_license_file("/path/to/bam.lic")
# or set BAM_LICENSE_FILE in the environment before importing bam

Diagnostics: bam.license_status() returns a dict with state, path, and free_limit_nvars. If BAM is in free mode at solve time the wrapper emits a one-time BamLicenseWarning.

Tests

pytest                                   # runs the in-package suite
BAM_TEST_LICENSE=/usr/local/bin/bamlice.txt pytest    # also exercises licensed-mode paths

Metadata

Release files for bam-solver 5.1.0

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

Source distribution (sdist)

Source distribution for bam-solver 5.1.0
File Size Uploaded Provenance Actions
bam_solver-5.1.0.tar.gz 83.1 kB Without provenance Details for bam_solver-5.1.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for bam-solver 5.1.0
File Actions
bam_solver-5.1.0-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details for bam_solver-5.1.0-cp310-abi3-win_amd64.whl
bam_solver-5.1.0-cp310-abi3-manylinux_2_27_aarch64.whl CPython 3.10 abi3 Linux glibc 2.27+ ARM64 Details for bam_solver-5.1.0-cp310-abi3-manylinux_2_27_aarch64.whl
bam_solver-5.1.0-cp310-abi3-manylinux_2_24_x86_64.whl CPython 3.10 abi3 Linux glibc 2.24+ x86-64 Details for bam_solver-5.1.0-cp310-abi3-manylinux_2_24_x86_64.whl
bam_solver-5.1.0-cp310-abi3-macosx_13_0_arm64.whl CPython 3.10 abi3 macOS 13.0+ ARM64 Details for bam_solver-5.1.0-cp310-abi3-macosx_13_0_arm64.whl
bam_solver-5.1.0-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details for bam_solver-5.1.0-cp310-abi3-macosx_10_12_x86_64.whl

Total release size: 82.9 MB

Release files / bam_solver-5.1.0.tar.gz

Download URL bam_solver-5.1.0.tar.gz
Size 83.1 kB
Tags Source
SHA-256 checksum
How to use checksums
3342e37d2b8504fb3edd4ecf5ff5c338ed734f130251444a08f3f7108bd215fe
BLAKE2b-256 checksum
How to use checksums
6fc2fd6de47f18ad865ae40fb2169756aeb3782359d6e1f4d36aff6f638a077e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release files / bam_solver-5.1.0-cp310-abi3-win_amd64.whl

Download URL bam_solver-5.1.0-cp310-abi3-win_amd64.whl
Size 16.8 MB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
96f37b7182dfbb6b7693741043a15228b8eb63651e8b1b2f28ffed8d6d13b1f3
BLAKE2b-256 checksum
How to use checksums
d09d00f654693bb5c7f3a6219de7c8830c46b134d31d2d781b97ce2a8be3a774
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release files / bam_solver-5.1.0-cp310-abi3-manylinux_2_27_aarch64.whl

Download URL bam_solver-5.1.0-cp310-abi3-manylinux_2_27_aarch64.whl
Size 12.7 MB
Tags CPython 3.10 Linux glibc 2.27+ ARM64 abi3
SHA-256 checksum
How to use checksums
ad85b2f6eeb968e0b4b44660209f115bde155a759c9deb3e6ef3cf97cba3ae28
BLAKE2b-256 checksum
How to use checksums
0a8971d172fb72249e05894a3c2a4a87d7d84354984f6c9b71d41bed00468fe0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release files / bam_solver-5.1.0-cp310-abi3-manylinux_2_24_x86_64.whl

Download URL bam_solver-5.1.0-cp310-abi3-manylinux_2_24_x86_64.whl
Size 16.4 MB
Tags CPython 3.10 Linux glibc 2.24+ x86-64 abi3
SHA-256 checksum
How to use checksums
e2380b4731b0ab0b4535163c569cc5f83f54122791715606ba7a68b209327306
BLAKE2b-256 checksum
How to use checksums
38c91afa42236e5b9ea8674993e1ffb6b5eb2c8cb6fcb523c56fd3f61e20b23c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release files / bam_solver-5.1.0-cp310-abi3-macosx_13_0_arm64.whl

Download URL bam_solver-5.1.0-cp310-abi3-macosx_13_0_arm64.whl
Size 15.2 MB
Tags CPython 3.10 abi3 macOS 13.0+ ARM64
SHA-256 checksum
How to use checksums
99282cb73045797f8125d500307fac15988045accc207554e1f02556e2353630
BLAKE2b-256 checksum
How to use checksums
b2613b275d1962826bc6037d18300b032cda3d554e4cc4a1311326d9ce7ebd66
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release files / bam_solver-5.1.0-cp310-abi3-macosx_10_12_x86_64.whl

Download URL bam_solver-5.1.0-cp310-abi3-macosx_10_12_x86_64.whl
Size 21.6 MB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
15846f6505542ea859e05a67b8104d9c5568e908fb898aacd44c6e7660783828
BLAKE2b-256 checksum
How to use checksums
a9b83dfb865ce6854127a6eadd83f820b5024c4b02fa684a997e39fbb4701be1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Security for bam-solver 5.1.0

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