PyBADS: Fast and robust black-box optimization in Python

Gurjeet Sangra Singh, Luigi Acerbi

Optimization is the heartbeat of modern science and engineering, but the "real world" is rarely kind to standard algorithms. Often, we are faced with "black-box" functions that are non-convex, non-smooth, noisy, and lack gradient information. To make matters worse, these functions are often "mildly expensive"—taking a few seconds to evaluate—making them too slow for simple grid searches but not slow enough to justify the massive overhead of heavy-duty Bayesian Optimization.

Enter PyBADS, a Python implementation of the Bayesian Adaptive Direct Search (BADS) algorithm. Recently detailed in a paper by Gurjeet Sangra Singh and Luigi Acerbi, PyBADS offers a fast, robust, and sample-efficient solution for these tricky middle-ground optimization problems.

TL;DR

PyBADS is a Python library for "black-box" optimization that combines the reliability of mesh-based direct searches with the speed of Bayesian Optimization. It is specifically designed for functions that are noisy, lack gradients, and have moderate evaluation costs, making it an ideal tool for fitting complex computational models in fields like neuroscience and engineering.

What Problem Does This Paper Address?

The authors target a specific "pain point" in optimization. On one side, you have Direct Search methods (like MADS), which are incredibly robust and have strong theoretical guarantees but require a huge number of function evaluations. On the other side, you have Bayesian Optimization (BayesOpt), which is very sample-efficient but can be fragile; if the underlying surrogate model is slightly off (model misspecification), the whole process can fail.

Furthermore, many existing BayesOpt tools are designed for "highly expensive" functions (taking hours per evaluation). If your function only takes a few seconds, the computational overhead of the optimizer itself becomes the bottleneck. PyBADS addresses this by providing a hybrid approach that is both fast in "wall-clock time" and efficient in the number of samples required.

Methods

PyBADS utilizes a hybrid schema that alternates between two distinct stages:

  1. The Poll Stage (Model-Free): Based on Mesh Adaptive Direct Search (MADS), this stage performs a systematic exploration of the parameter space on a grid (mesh). It takes steps in various directions until it finds an improvement. This acts as the "fail-safe"—it doesn't rely on any assumptions about the function's shape.
  2. The Search Stage (Model-Based): This is where the Bayesian magic happens. PyBADS fits a Gaussian Process (GP) surrogate model to the points evaluated so far. It then uses a Lower Confidence Bound (LCB) strategy to propose new points that balance exploration (checking uncertain areas) and exploitation (honing in on known minima).

The "Aha!" moment of this method is its fail-safe mechanism: if the GP surrogate fails to accurately model the target function and the search stage fails to find an improvement, the algorithm gracefully falls back to the reliable Poll stage.

Datasets

The paper evaluates PyBADS using:

  • Artificial Test Problems: Standard benchmarks like the two-dimensional Rosenbrock function to visualize and verify the algorithm's logic.
  • Real-World Model Fitting: Large-scale problems drawn from cognitive, behavioral, and computational neuroscience.
  • Control Engineering Benchmarks: Comparisons against state-of-the-art optimizers in specialized engineering contexts.

Key Insights and Ideas

  • Hybrid Robustness: By combining MADS and BayesOpt, PyBADS gains the sample efficiency of a model-based approach without the risk of getting stuck due to a poor model.
  • Handling Noise: PyBADS natively accommodates heteroskedastic noise (noise that changes depending on the input), which is a common feature in biological and stochastic simulations.
  • No Tuning Required: Unlike many BayesOpt libraries that require expert knowledge to set up kernels and hyperparameters, PyBADS is designed to work "off-the-shelf" with sensible defaults.
  • Dimensionality: The algorithm scales efficiently to functions with up to $D \approx 20$ continuous parameters, a sweet spot for many scientific modeling tasks.

Key Results

  • Performance: Extensive benchmarks show that PyBADS performs on par with or better than current state-of-the-art optimizers.
  • Sample Efficiency: It typically finds solutions within a few hundred function evaluations.
  • Integration: The library is designed to work seamlessly with PyVBMC, a tool for Bayesian inference, allowing users to find a Maximum-a-Posteriori (MAP) solution quickly before performing full uncertainty quantification.
  • Accessibility: The package is available via PyPI and conda-forge, featuring a "Pythonic" API that requires only a target function and parameter bounds to run.

Limitations and Future Work

While PyBADS is highly effective for its target niche, the authors and the nature of the algorithm suggest a few boundaries:

  • Dimensionality Ceiling: While $D \approx 20$ is impressive for this class of optimizer, problems with hundreds or thousands of parameters would still require different, likely gradient-based, approaches.
  • Evaluation Cost: If a function evaluation takes only microseconds, the overhead of fitting a Gaussian Process might still be too high compared to simpler methods like Nelder-Mead.
  • Discrete Parameters: The current focus is on continuous input parameters; extending this robust hybrid approach to purely categorical or mixed-integer spaces remains an area for potential growth.

For researchers and engineers tired of babysitting temperamental optimizers, PyBADS offers a compelling, "set-it-and-forget-it" alternative that respects both your time and your computational budget.

Summary updated

BibTeX
@article{singh2024pybads,
  author = {Gurjeet Sangra Singh and Luigi Acerbi},
  title = {{PyBADS: Fast and robust black-box optimization in Python}},
  journal = {J. Open Source Softw.},
  year = {2024},
  url = {https://openreview.net/forum?id=WKAAnlKU8t},
}
Figure