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

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.0.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.0.0
File Size Uploaded
bam_solver-5.0.0.tar.gz 82.3 kB Details

Built distributions (wheels)

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

Total release size: 81.2 MB

Release files / bam_solver-5.0.0.tar.gz

Download URL bam_solver-5.0.0.tar.gz
Size 82.3 kB
Tags Source
SHA-256 checksum
How to use checksums
409bcedfc11960068b348c21322ff500b9efbbb8313cbcb061a6b5386eb89e29
BLAKE2b-256 checksum
How to use checksums
96d3ef48e641b37259471a371410ab1e7d26253730fbba62c1056c717a457ab1
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.0.0-cp310-abi3-win_amd64.whl

Download URL bam_solver-5.0.0-cp310-abi3-win_amd64.whl
Size 16.5 MB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
6124fb5c26b55a7cac00fd48d1912c6fa33cbb8472979523d05f96ee438a7174
BLAKE2b-256 checksum
How to use checksums
77e7a016b53ec5034e556d482ff73038eb7fbeb15ffa25f4641521d634e938f2
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.0.0-cp310-abi3-manylinux_2_27_aarch64.whl

Download URL bam_solver-5.0.0-cp310-abi3-manylinux_2_27_aarch64.whl
Size 12.5 MB
Tags CPython 3.10 Linux glibc 2.27+ ARM64 abi3
SHA-256 checksum
How to use checksums
4c54bce7bdd148a2b9dc5ba00442e7e463dbf732a2aa92f31140994bd53ab00a
BLAKE2b-256 checksum
How to use checksums
2bf93c0a18303fac38fc4fa3b0d99ba918055ad344ef8632badba84ea6b092d9
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.0.0-cp310-abi3-manylinux_2_24_x86_64.whl

Download URL bam_solver-5.0.0-cp310-abi3-manylinux_2_24_x86_64.whl
Size 16.1 MB
Tags CPython 3.10 Linux glibc 2.24+ x86-64 abi3
SHA-256 checksum
How to use checksums
80c475cff9f92eda4f5492f91d43bcec6456bf9e52f2893e1f9bc4c6395e2460
BLAKE2b-256 checksum
How to use checksums
23e46a6ff626a8b3fc1664bd5d67e63c2778a764fe0a1cdfbe1e6ea5e7089095
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.0.0-cp310-abi3-macosx_13_0_arm64.whl

Download URL bam_solver-5.0.0-cp310-abi3-macosx_13_0_arm64.whl
Size 15.0 MB
Tags CPython 3.10 abi3 macOS 13.0+ ARM64
SHA-256 checksum
How to use checksums
413c7df30a5888a6550333b92765c7b3ccef7887252a2c0c9337953f29f2d39f
BLAKE2b-256 checksum
How to use checksums
59e3133f0ebd6d433b36228043c802a1a4fd90277d6e913644175caf51deea93
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.0.0-cp310-abi3-macosx_10_12_x86_64.whl

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

Release history Release notifications | RSS feed

This release

5.0.0 This release

6 release files

4.1.1

6 release files

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