Usage Guide#

This guide covers installation, basic usage, and common workflows for Panobbgo.

Installation#

Requirements#

  • Python ≥ 3.14

  • NumPy ≥ 2.0

  • SciPy ≥ 1.16

  • matplotlib ≥ 3.0

  • pandas ≥ 2.0

  • statsmodels ≥ 0.14

  • Dask ≥ 2026.1 (optional — only for evaluation: method: dask; install via the dask extra)

Using pip#

git clone https://github.com/haraldschilly/panobbgo.git
cd panobbgo
pip install -e ".[dev]"

Verifying the installation#

The snippets below are doctests: they run in CI against the installed package, so if they pass for you the installation is complete.

>>> import sys
>>> print(f"Python version: {sys.version}")
Python version: ...

>>> import panobbgo
>>> print(f"Panobbgo version: {panobbgo.__version__}")
Panobbgo version: ...

>>> import numpy as np
>>> import scipy
>>> import pandas as pd
>>> import matplotlib
>>> print("All dependencies imported successfully")
All dependencies imported successfully

>>> print(f"NumPy: {np.__version__}, SciPy: {scipy.__version__}")
NumPy: ..., SciPy: ...

To run the framework’s own test suite (about 2300 tests, roughly a minute with four workers):

uv run pytest -q -n 4

Evaluation Setup#

Threaded Evaluation (Default):

By default, Panobbgo uses local threads for evaluation. This requires no additional setup and is suitable for most local development tasks.

Dask Cluster (Optional):

For large-scale distributed optimization, you can use a Dask cluster:

  1. Install the dask extra (Dask is not a core dependency; the backend lives in panobbgo.dask_evaluation and is imported lazily):

    pip install "panobbgo[dask]"     # or: uv sync --extra dask
    
  2. Start Cluster: .. code-block:: bash

    dask scheduler & dask worker localhost:8786 –nworkers 4 &

  3. Configure Panobbgo: Set evaluation: method: dask in your config.yaml.

See Dask distributed documentation for advanced setup (remote clusters, Kubernetes, SLURM integration, etc.).

Configuration#

Settings come, in decreasing precedence, from keyword arguments of the strategy (max_eval=, seed=, config attribute names), config.yaml in the working directory, ~/.panobbgo/config.ini and the built-in defaults. On first run Panobbgo writes a default config.ini:

[heuristic]
capacity = 20             # heuristic output-queue size

[core]
loglevel = 40             # Python logging level (40 = ERROR)
show_interval = 1.0
max_eval = 1000           # evaluation budget
discount = 0.95           # performance decay factor
smooth = 0.5              # additive smoothing for the bandit
# also read from [core]: seed, stop_on_convergence, deadlock_seconds
# (see below), rewarding_credit, rewarding_explore

# [storage]
# backend = sqlite        # checkpoint/resume; uri defaults to panobbgo.db

Everything above can also go in config.yaml (core: max_eval: 500, heuristic: capacity: 20, …). The evaluation, Dask, constraint and logging settings are YAML only — config.ini has no section for them:

evaluation:
  method: threaded        # 'threaded', 'processes', 'dask' or 'virtual'
  timeout: 60             # optional per-call limit, seconds (see below)
  sync: false             # true: bit-reproducible seeded runs
  async_policy: pull      # sync false: 'pull' (when free) or 'legacy' (see below)
  virtual_workers: 4      # method 'virtual' only: simulated workers q
  virtual_duration: constant   # 'lognormal' (mean 1, see below) or a number
  virtual_duration_sigma: 0.5  # log-space sd of 'lognormal'
  virtual_duration_mean: 1     # nominal mean (the metric's time unit)
  virtual_policy: async        # or 'sync' (regression mode, see below)
dask:
  cluster_type: local     # 'local' (auto-start) or 'remote'
  local:
    n_workers: 2
    threads_per_worker: 1
    memory_limit: 2GB
    dashboard_address: ':8787'
  remote:
    scheduler_address: tcp://localhost:8786

constraints:
  handler: DefaultConstraintHandler
  # rho, exponent, dynamic_penalty_rate, alm_rate: unset = the handler's
  # own default (rho 100 for Default/Penalty/Epsilon, 10 for Dynamic/ALM)

evaluation.timeout (seconds, default unset = no limit) is a per-call limit that applies to every evaluation in every backend and is enforced where the evaluation runs. The clock starts when the call starts — time spent queued never counts. An evaluation past the limit becomes a regular result with fx = NaN and cv = inf (infeasible; the violations are unknown, so cv_vec is None and the frame’s cv_vec columns are NaN), marked Result.timed_out and in the ("timed_out", 0) column of the results frame; it is recorded, charged once against max_eval and published through new_results like any result, so heuristics see a bad point and every ranking puts it last.

  • processes: exactly the worker process running that call is killed (a fresh one replaces it); every other in-flight evaluation keeps running.

  • dask: the task on the dask worker runs the objective in a child process (panobbgo.timeout_call.call_with_timeout()) and kills that child when the call runs too long, so a hung objective never holds its worker. The problem must be serializable and importable in a fresh interpreter on the worker (checked once before the first task). Each call evaluates a fresh copy of the problem, so state it accumulates while evaluating does not carry over between calls — e.g. a NoisyProblem with resample=True draws the same noise on every re-evaluation (a warning says so). Without a timeout the objective runs in the worker itself, as before.

  • threaded: a thread cannot be killed — a timed-out call is abandoned: it keeps running in the background and its result is discarded; abandoned threads are counted and warned about. Use processes or dask for objectives that can hang. With evaluation.sync, a timeout routes each batch through the thread pool, harvested in submission order.

  • virtual: the call is simulated (below); one whose simulated duration exceeds the timeout is not evaluated at all and completes, as the NaN placeholder, exactly timeout virtual time units after its dispatch.

An objective that raises is still a failed evaluation (no result, failed_evaluations event).

evaluation.method = "virtual" is a deterministic simulation of q parallel workers (panobbgo.virtual_clock) for benchmarking asynchronous behaviour without real waiting: the objective runs in-process when a simulated worker picks a candidate up, and only the durations — and hence the order in which results reach the strategy — are simulated. The built-in duration models have mean 1 (virtual time is in units of the mean duration); an x-dependent model is set on the strategy (strategy.config.virtual_duration = CallableDuration(f, mean=...), or a callable f(x) together with virtual_duration_mean: the nominal mean is required). Each result carries Result.t_dispatch and Result.t_complete (in memory only; the sqlite storage backend does not store them). The same seed gives the same run on every machine.

The default virtual_policy: async is the asynchronous expensive-evaluation policy: a decision at every completion instant, candidates only for the free workers (the strategy’s request_cap; jobs_per_client = 1); with one worker the run is strictly one call at a time.

The real asynchronous loop (sync: false; threaded, processes or dask) runs the same pull-when-free policy by default (async_policy: pull): the strategy is asked only while a worker is free, for at most the free workers within the budget, with jobs_per_client = 1, and no candidate is queued behind a busy worker, where it would go stale. A harvest that frees a worker is followed by a new request at once; while every worker is busy the loop blocks until an evaluation completes rather than polling. async_policy: legacy keeps the old behaviour: batches of jobs_per_client per worker sized from wall-clock task timings, requested on every pass, so a fixed-size strategy can queue far past the free workers. With sync: true (and on the virtual clock) the setting has no effect. virtual_policy: sync keeps the synchronous batch policy as a regression mode: with virtual_workers = 1, a constant duration and dask.local.n_workers = 1 (which sizes the synchronous batches) it is exactly the evaluation.sync run.

Edit these files to customize behavior.

Note

There is no wall-clock stall guard. A run used to end after max_stall_seconds without progress, which made a seeded run a function of machine speed — a slow handler could truncate it anywhere between 70 and 240 of 300 evaluations. A run now ends when nothing can produce a point: no evaluation in flight, no event handler queued, and no heuristic with a point to give. Progress is counted in evaluations; a slow arm makes a run take longer, never shorter.

deadlock_seconds (default 600) is the remaining time-based knob and is not a scheduling parameter: it is an error backstop for a genuine bug — a heuristic that claims a point but never gives one, a handler that never returns, queued evaluations with no live worker — and tripping it is logged at ERROR level with the state that caused it. It fires only when no evaluation is outstanding: a running evaluation (thread, worker process, any outstanding dask future) is waited for however long it takes, so hour-long or remote evaluations never trip it. Limit a single evaluation with the opt-in evaluation.timeout instead. An old config file’s max_stall_seconds entry is ignored. See planning/DESIGN_pump_and_stall_2026-09-11.md §2.

Passing it as a keyword argument is an error, though: a strategy’s constructor accepts only max_eval / max_evaluations, seed, its own parameters and the names of existing config attributes, and raises TypeError for anything else — a removed option such as max_stall_seconds= or a typo such as max_evals= is no longer dropped silently.

Basic Usage#

Minimal Example#

from panobbgo.lib.classic import Rosenbrock
from panobbgo.strategies.rewarding import StrategyRewarding
from panobbgo.heuristics import Center, Random, NelderMead

# Define problem
problem = Rosenbrock(dims=5)

# Create strategy
strategy = StrategyRewarding(problem, max_evaluations=500)

# Add heuristics
strategy.add(Center)       # Start at center
strategy.add(Random)       # Exploration
strategy.add(NelderMead)   # Exploitation

# Run optimization
strategy.start()

# Get results
print(f"Best found: {strategy.best}")
print(f"Best x: {strategy.best.x}")
print(f"Best f(x): {strategy.best.fx}")

Complete Example#

from panobbgo.lib.classic import Rosenbrock
from panobbgo.strategies.rewarding import StrategyRewarding
from panobbgo.analyzers import Best, Splitter
from panobbgo.heuristics import (
    Center, Zero, LatinHypercube, Random,
    Nearby, NelderMead
)

# Define 10-dimensional Rosenbrock
problem = Rosenbrock(dims=10)

# Create adaptive strategy
strategy = StrategyRewarding(
    problem,
    max_evaluations=2000      # Budget
)

# Add analyzers (optional - Best is default)
strategy.add_analyzer(Best)      # Track best points
strategy.add_analyzer(Splitter)  # Spatial decomposition

# Add diverse heuristics
strategy.add(Center)                    # Initialize at center
strategy.add(Zero)                      # Initialize at origin
strategy.add(LatinHypercube, div=5)    # Space-filling design (5^10 grid)
strategy.add(Random)                    # Ongoing exploration
strategy.add(Nearby)                    # Local perturbations
strategy.add(NelderMead)               # Simplex optimization

# Run
strategy.start()

# Analyze results
print(f"\nOptimization complete!")
print(f"Evaluations: {len(strategy.results)}")
print(f"Best f(x): {strategy.best.fx:.6f}")
print(f"Best x: {strategy.best.x}")
print(f"Found by: {strategy.best.who}")

# Access result database
df = strategy.results.results
print(f"\nDataFrame shape: {df.shape}")
print(df.head())

Scripts That Start Worker Processes: the __main__ Guard#

Some parts of Panobbgo run in child processes started with multiprocessing’s "spawn" method:

A spawned child starts a fresh interpreter and re-imports your script. If the script builds and starts the strategy at module level, the child runs that code again and tries to start processes of its own, which fails (RuntimeError: An attempt has been made to start a new process before the current process has finished its bootstrapping phase) or, at best, starts a second optimization. Put everything that runs the optimization under an if __name__ == "__main__": guard:

from panobbgo.heuristics import LBFGSB, Random
from panobbgo.lib.classic import Rosenbrock
from panobbgo.strategies import StrategyRewarding


def main():
    strategy = StrategyRewarding(Rosenbrock(dims=5), max_evaluations=500)
    strategy.add(Random)
    strategy.add(LBFGSB)
    strategy.start()
    print(strategy.best)


if __name__ == "__main__":
    main()

Imports, problem classes and helper functions may stay at module level; only the code that runs belongs under the guard. The guard is harmless for the other heuristics, so using it in every script is the simple rule. In a notebook there is no script to re-import, but the processes backend still needs a problem class that a fresh interpreter can import (not one defined in the notebook or in __main__).

Verified Walkthrough#

The following steps are executable doctests (run in CI), so they double as a check that your installation behaves as documented. They set up problems and strategies without starting an optimization run.

Step 1: Define a problem

Create a simple optimization problem by subclassing Problem:

>>> import numpy as np
>>> from panobbgo.lib import Problem

>>> class SphereProblem(Problem):
...     """Simple sphere function: f(x) = sum(x^2)"""
...     def __init__(self, dim=2):
...         # Define search bounds: each variable in [-5, 5]
...         box = [(-5.0, 5.0)] * dim
...         super().__init__(box)
...
...     def eval(self, x):
...         """Evaluate the objective function"""
...         return np.sum(x ** 2)

>>> # Create an instance
>>> problem = SphereProblem(dim=2)
>>> print(f"Problem dimension: {problem.dim}")
Problem dimension: 2

>>> # Test evaluation at the origin (global optimum)
>>> from panobbgo.lib import Point
>>> point = Point([0.0, 0.0], "test")
>>> result = problem(point)
>>> print(f"f([0,0]) = {result.fx}")
f([0,0]) = 0.0

Step 2: Evaluate points manually

Test point evaluation and bounds checking:

>>> # Generate a random point within bounds
>>> random_point = problem.random_point()
>>> print(f"Random point: {random_point}")
Random point: ...

>>> # Evaluate the random point
>>> random_point_obj = Point(random_point, "test")
>>> result = problem(random_point_obj)
>>> print(f"f({random_point}) = {result.fx}")
f(...) = ...

>>> # Check that point is within bounds
>>> in_bounds = all(problem.box[0][0] <= coord <= problem.box[0][1] for coord in random_point)
>>> print(f"Point within bounds: {in_bounds}")
Point within bounds: True

Step 3: Create a strategy and add heuristics

>>> from panobbgo.strategies.rewarding import StrategyRewarding

>>> # Create strategy
>>> strategy = StrategyRewarding(problem)
>>> strategy.config.max_eval = 50  # Set evaluation budget
>>> print(f"Strategy created with max_evaluations: {strategy.config.max_eval}")
Strategy created with max_evaluations: 50

>>> from panobbgo.heuristics import Center, Random, Nearby

>>> # Add initialization heuristic
>>> strategy.add(Center)
>>> strategy.add(Random)
>>> strategy.add(Nearby, radius=0.1)
>>> print(f"Total heuristics: {len(strategy._hs)}")
Total heuristics: 3

Step 4: Verify the strategy setup

>>> # Check strategy configuration
>>> print(f"Problem: {strategy.problem.__class__.__name__}")
Problem: SphereProblem
>>> print(f"Max evaluations: {strategy.config.max_eval}")
Max evaluations: 50
>>> print(f"Number of heuristics: {len(strategy._hs)}")
Number of heuristics: 3

>>> # The strategy is ready to run optimization with strategy.start()
>>> print("Strategy setup complete!")
Strategy setup complete!

The optimization workflow from here is:

  1. Call strategy.start() to begin optimization

  2. The strategy coordinates heuristics to generate points

  3. Points are evaluated in parallel (using local threads by default)

  4. Results are collected and the best solution is tracked

  5. Optimization continues until the evaluation budget is exhausted

Step 5: Use a built-in test function

>>> from panobbgo.lib.classic import Rosenbrock

>>> # Create Rosenbrock function (banana-shaped valley)
>>> rosenbrock = Rosenbrock(dims=2)
>>> print(f"Rosenbrock problem dimension: {rosenbrock.dim}")
Rosenbrock problem dimension: 2

>>> # Evaluate at global optimum
>>> optimum = Point([1.0, 1.0], "test")
>>> result = rosenbrock(optimum)
>>> print(f"Rosenbrock optimum f([1,1]) = {result.fx}")
Rosenbrock optimum f([1,1]) = 0.0

>>> # Evaluate at a different point
>>> test_point = Point([0.0, 0.0], "test")
>>> result = rosenbrock(test_point)
>>> print(f"Rosenbrock f([0,0]) = {result.fx:.3f}")
Rosenbrock f([0,0]) = 1.000

>>> # Create strategy for Rosenbrock
>>> strategy2 = StrategyRewarding(rosenbrock)
>>> strategy2.config.max_eval = 100
>>> strategy2.add(Center)
>>> strategy2.add(Random)
>>> strategy2.add(Nearby, radius=0.1)

>>> # Strategy is ready for optimization
>>> print(f"Rosenbrock strategy configured with {len(strategy2._hs)} heuristics")
Rosenbrock strategy configured with 3 heuristics
>>> print(f"Ready to optimize with budget of {strategy2.config.max_eval} evaluations")
Ready to optimize with budget of 100 evaluations

Step 6: Define a constrained problem

>>> class ConstrainedSphere(Problem):
...     """Sphere with constraint: sum(x) <= 1"""
...     def __init__(self, dim=2):
...         box = [(-2.0, 2.0)] * dim
...         super().__init__(box)
...
...     def eval(self, x):
...         return np.sum(x ** 2)
...
...     def eval_constraints(self, x):
...         # Constraint: sum(x) - 1 <= 0 (feasible when sum(x) <= 1)
...         return np.array([np.sum(x) - 1.0])

>>> constrained_problem = ConstrainedSphere(dim=2)
>>> print("Constrained problem created")
Constrained problem created

>>> # Test feasible point
>>> feasible_point = Point([0.3, 0.3], "test")
>>> result_feasible = constrained_problem(feasible_point)
>>> print(f"Feasible point: x = {feasible_point.x}, f(x) = {result_feasible.fx:.3f}")
Feasible point: x = [0.3 0.3], f(x) = 0.180
>>> print(f"Constraint violation: {result_feasible.cv_vec}")
Constraint violation: [-0.4]

>>> # Test infeasible point
>>> infeasible_point = Point([1.0, 1.0], "test")
>>> result_infeasible = constrained_problem(infeasible_point)
>>> print(f"Infeasible point: x = {infeasible_point.x}, f(x) = {result_infeasible.fx:.3f}")
Infeasible point: x = [1. 1.], f(x) = 2.000
>>> print(f"Constraint violation: {result_infeasible.cv_vec}")
Constraint violation: [1.]

Step 7: Full setup

>>> # Import everything needed
>>> from panobbgo.lib.classic import Rosenbrock
>>> from panobbgo.strategies.rewarding import StrategyRewarding
>>> from panobbgo.heuristics import Center, Random, Nearby, NelderMead

>>> # Define problem
>>> problem = Rosenbrock(dims=3)
>>> print(f"Optimizing {problem.dim}D Rosenbrock function")
Optimizing 3D Rosenbrock function

>>> # Create strategy
>>> strategy = StrategyRewarding(problem)
>>> strategy.config.max_eval = 200

>>> # Add diverse heuristics
>>> strategy.add(Center)
>>> strategy.add(Random)
>>> strategy.add(Nearby, radius=0.1)
>>> strategy.add(NelderMead)

>>> # Verify setup
>>> print(f"Problem: {problem.__class__.__name__} ({problem.dim}D)")
Problem: Rosenbrock (3D)
>>> print(f"Strategy: {strategy.__class__.__name__}")
Strategy: StrategyRewarding
>>> print(f"Budget: {strategy.config.max_eval} evaluations")
Budget: 200 evaluations
>>> print(f"Heuristics: {len(strategy._hs)}")
Heuristics: 4
>>> print("Ready to run with: strategy.start()")
Ready to run with: strategy.start()

Defining Custom Problems#

Basic Problem#

Subclass Problem:

import numpy as np
from panobbgo.lib import Problem

class Sphere(Problem):
    """Simple sphere function: f(x) = sum(x^2)"""

    def __init__(self, dim=5):
        # Define bounding box: each variable in [-10, 10]
        box = [(-10.0, 10.0)] * dim
        super().__init__(box)

    def eval(self, x):
        """Evaluate objective function"""
        return np.sum(x ** 2)

# Use it
problem = Sphere(dim=10)
strategy = StrategyRewarding(problem, max_evaluations=500)
# ... add heuristics and run ...

Problem Wrappers#

Instead of modifying your problem class, use composable wrappers from panobbgo.lib.wrappers:

from panobbgo.lib import NoisyProblem  # = panobbgo.lib.noise.NoisyProblem
from panobbgo.lib.noise import AdditiveGaussianNoise
from panobbgo.lib.wrappers import NormalizedProblem, LogTransformProblem

# Normalize all dimensions to [0, 1]
problem = NormalizedProblem(Rosenbrock(dims=5))

# Add noise for robustness testing: a pure function of (seed, x), so
# runs are reproducible whatever the evaluation order or thread.
# resample=True draws fresh noise on each re-evaluation of the same x.
problem = NoisyProblem(Rosenbrock(dims=5), AdditiveGaussianNoise(sigma=0.1), seed=42)

# Log-transform for objectives spanning orders of magnitude
problem = LogTransformProblem(MyProblem(), offset=0.0)

# Compose multiple wrappers
problem = NormalizedProblem(NoisyProblem(MyProblem(), AdditiveGaussianNoise(sigma=0.05), seed=0))

The noise is applied to the precision f(x) - f_opt (f_opt defaults to the problem’s optimum_y, else 0); see panobbgo.lib.noise for the models. panobbgo.lib.wrappers.NoisyProblem(problem, noise_std=..., seed=...) is a deprecated adapter for the old signature.

Wrappers are transparent — the framework sees a standard Problem with the transformed box and evaluation.

Noisy Problem (Manual)#

You can also add stochasticity directly in eval():

class NoisySphere(Problem):
    def __init__(self, dim=5, noise_std=0.1):
        box = [(-10.0, 10.0)] * dim
        super().__init__(box)
        self.noise_std = noise_std

    def eval(self, x):
        """Noisy evaluation"""
        true_value = np.sum(x ** 2)
        noise = np.random.randn() * self.noise_std
        return true_value + noise

Constrained Problem#

Override eval_constraints() to return violation vector:

class ConstrainedProblem(Problem):
    def __init__(self):
        # 2D problem: x in [-5, 5], y in [-5, 5]
        box = [(-5, 5), (-5, 5)]
        super().__init__(box)

    def eval(self, x):
        """Objective: minimize (x-1)^2 + (y-2)^2"""
        return (x[0] - 1)**2 + (x[1] - 2)**2

    def eval_constraints(self, x):
        """Constraints:
        g1: x + y <= 1  (i.e., x + y - 1 <= 0)
        g2: x >= 0
        """
        g1 = x[0] + x[1] - 1.0
        g2 = -x[0]
        # Return positive violations
        return np.array([max(0, g1), max(0, g2)])

# Panobbgo will minimize objective while trying to satisfy constraints
problem = ConstrainedProblem()
strategy = StrategyRewarding(problem, max_evaluations=300)

# The constraint handling method is set in config.yaml:
#   constraints:
#     handler: AugmentedLagrangianConstraintHandler

strategy.add(Center)
strategy.add(Random)
# Add FeasibleSearch to actively target feasible regions
from panobbgo.heuristics import FeasibleSearch, ConstraintGradient
strategy.add(FeasibleSearch)
strategy.add(ConstraintGradient)
strategy.add(NelderMead)
strategy.start()

print(f"Best feasible: {strategy.best}")
print(f"Constraint violation: {strategy.best.cv}")

Constraint Handling Methods#

Panobbgo supports different constraint handling strategies, selected in config.yaml (constraints: handler: ...) or with the constraint_handler strategy argument:

  1. DefaultConstraintHandler (default): Lexicographic ordering. Prioritizes feasibility (cv=0) over objective function value. Good for general use where feasibility is strict.

  2. PenaltyConstraintHandler: Uses a static penalty: $P(x) = f(x) + rho cdot cv(x)^{exponent}$. Useful if slight violations are acceptable or gradients lead out of feasible region.

  3. DynamicPenaltyConstraintHandler: Penalty coefficient increases over time. Starts low to allow exploration of infeasible regions, then tightens.

  4. AugmentedLagrangianConstraintHandler: Implements the Augmented Lagrangian Method. Adaptively updates multipliers $lambda$ and penalty $mu$ based on progress. Can be more robust for equality constraints or hard inequality constraints.

  5. EpsilonConstraintHandler: Uses the $epsilon$-Constrained Method. Initially treats points with small violations ($cv(x) le epsilon(t)$) as feasible. $epsilon(t)$ decreases from epsilon_start to 0 over epsilon_cutoff evaluations. Effective for finding feasible regions in difficult problems by approaching the boundary gradually.

  6. FilterConstraintHandler: Uses a multi-objective filter approach (Pareto dominance on (objective, violation)). Accepts points that are not dominated by any previously accepted point in the filter. Useful for maintaining a diverse set of trade-off solutions during the search.

FeasibleSearch Heuristic#

When dealing with constraints, it is highly recommended to add the FeasibleSearch heuristic. This heuristic is specifically designed to:

  • Repair infeasible solutions by searching towards known feasible regions (Line Search).

  • Explore the boundary of the feasible region.

  • Adaptively sample around the best point to reduce constraint violations.

from panobbgo.heuristics import FeasibleSearch
strategy.add(FeasibleSearch)

ConstraintGradient Heuristic#

The ConstraintGradient heuristic estimates the gradient of the constraint violation function using finite differences from recent evaluations (or neighbors). It uses this estimated gradient to perform a descent step towards the feasible region. This is particularly useful when constraint violations are smooth.

from panobbgo.heuristics import ConstraintGradient
strategy.add(ConstraintGradient)

LocalPenaltySearch Heuristic#

For problems with constraints handled via penalties (e.g. Penalty or Augmented Lagrangian), the LocalPenaltySearch heuristic can be very effective. It uses Scipy’s local optimizers (like L-BFGS-B or Nelder-Mead) to minimize the scalarized penalty function directly.

from panobbgo.heuristics import LocalPenaltySearch

# Use L-BFGS-B on the penalized objective
strategy.add(LocalPenaltySearch, method="L-BFGS-B")

Note

LocalPenaltySearch runs its optimizer in a spawned subprocess: a script using it needs an if __name__ == "__main__": guard (see Scripts That Start Worker Processes: the __main__ Guard).

Expensive External Function#

Wrap subprocess or external program:

import subprocess
import json

class ExternalSimulation(Problem):
    def __init__(self):
        # 3D problem
        box = [
            (0.0, 1.0),
            (0.0, 1.0),
            (0.0, 1.0)
        ]
        super().__init__(box)

    def eval(self, x):
        """Call external simulation"""
        # Write input
        input_data = {"parameters": x.tolist()}
        with open("input.json", "w") as f:
            json.dump(input_data, f)

        # Run simulation
        result = subprocess.run(
            ["./my_simulation", "input.json"],
            capture_output=True,
            text=True,
            timeout=300  # 5 minute timeout
        )

        # Parse output
        output_data = json.loads(result.stdout)
        return output_data["objective_value"]

Choosing Heuristics#

Heuristic Portfolio#

A good portfolio balances exploration and exploitation:

Purpose

Heuristics

When to Use

Initialization

Center, Zero

Always include one

Space-filling

LatinHypercube, Sobol

High-dimensional problems (dim > 5); prefer Sobol for Bayesian optimization initial designs (lower discrepancy than LHS)

Exploration

Random, Extremal

Always include Random

Local search

Nearby, NelderMead

Smooth problems

Model-based (surrogate)

GaussianProcessHeuristic, QuadraticWLS

Few evaluations, smooth/expensive functions (Bayesian optimization)

Cluster-based

ClaudeHeuristic

Multimodal landscapes, finding hidden optima near good regions

Population-based

CMAES (IPOP/BIPOP), DifferentialEvolution, LSHADE, JSO, PSO

CMAES: smooth problems, ridges, and ill-conditioned landscapes (Rosenbrock); BIPOP-CMA-ES: highly multimodal (BBOB-2009 winner); DE: multimodal (Rastrigin, Schwefel); LSHADE: literature-best adaptive DE — adapts F / CR via success-history memories and shrinks the population linearly with the budget (CEC-2014 winner, Tanabe & Fukunaga 2014); JSO: jSO refinement of L-SHADE with weighted current-to-pbest-w/1 mutation, linear p_best schedule, Cauchy-F clamping, CR floors, averaged memory updates and a fixed 0.9 / 0.9 anchor memory bin (CEC-2017 winner, Brest-Maučec-Bošković 2017); PSO: momentum + social attraction, complementary to CMA-ES / DE — strong on narrow-valley problems where vector inertia helps

Gradient-free local

LBFGSB, LocalPenaltySearch

When local structure suspected

Constraint Handling

FeasibleSearch, ConstraintGradient, ConstraintRepair

When constraints are present

LBFGSB, COBYQA, LocalPenaltySearch and QuadraticWlsModel run in spawned subprocesses; scripts that use them need an if __name__ == "__main__": guard (see Scripts That Start Worker Processes: the __main__ Guard).

Tuning the Population Methods#

The three subsections below cover the settings that were measured to matter most on the MA-BBOB battery. Every parameter mentioned here is documented in full on its own class; this is the why and the numbers, not a second copy of the API reference.

Population Sizing (NP_init="auto")#

The L-SHADE family — LSHADE, JSO, NLSHADE_LBC and the other SHADE derivatives — accepts NP_init="auto", which sizes the initial population from the run’s evaluation budget and the problem dimension:

NP = clip( round( 3·dim · (budget / (500·dim))**0.25 ), max(NP_min, 6), 400 )

This is the constructor default for the whole L-SHADE family; the literature value 30 is used only as a fallback when the budget is not known at construction. The coefficient is a class attribute (AUTO_DIM_COEF): the base rule uses 3, and NLSHADE_LBC uses 4 — its linear bias control wants a larger rank pool, measured at +0.052 AOCC over the 3·dim rule on the 12-seed roster (10/12 seeds).

from panobbgo.heuristics import JSO
from panobbgo.strategies import StrategyRoundRobin

strategy = StrategyRoundRobin(problem, max_evaluations=2500, seed=42)
strategy.add(JSO, NP_init="auto")     # d=5, B=2500  →  NP_init = 15
strategy.start()

Why. Fixed-NP_init grid sweeps of the three L-SHADE-lineage arms, run solo on the standard battery, put the AOCC optimum at 6–8 for d=2, 10–20 for d=5 and 20–30 for d=10: the optimum tracks the dimension, which fixes the coefficient at ≈ 3·dim. Quadrupling the budget moves it up by only about 1.5×, hence the fourth-root budget term anchored at the reference 500 evaluations per dimension. The floor of 6 keeps current-to-pbest/1 working headroom — at NP_init=4 the mutation collapses (−0.25 AOCC for NLSHADE_LBC). The rule this replaced, min(18·dim, budget/12), took the CEC-2014 upper bound literally; at a few hundred evaluations per dimension its cap never binds, so it shipped populations roughly five times too large — most of the budget went into the initial random fill and the success-history adaptation never got enough generations to pay off.

Accepted on the 12-seed decision roster, each arm solo and paired on one RNG stream (planning/DISCOVERY_2026-09-09.md §17, §20):

Arm

Δ mean AOCC

CI 95 %

Seeds positive

LSHADE

+0.230

[+0.215, +0.244]

12 / 12

JSO

+0.204

[+0.175, +0.233]

12 / 12

NLSHADE_LBC

+0.064

[+0.028, +0.099]

10 / 12

Important

The budget must be known when the heuristic is constructed. "auto" is resolved once, in __init__, from strategy.config.max_eval. Pass the budget to the strategy constructor (max_evaluations=), or let a StrategySpec do it — its create_strategy(max_eval=...) sets the budget before any heuristic is built, and the harnesses now pass it. Assigning strategy.config.max_eval after strategy.add(...) is too late: the heuristic has already fallen back to the fixed default of 30.

CMA-ES Restarts#

Solo CMAES used to have no termination criterion at all: one CMA-ES run for the whole budget, and once σ had collapsed it kept resampling the same point. Diagnosed at d=5 with a 2500-evaluation budget, 52 % of the budget was spent after the last improvement of any size, and on two of five instances σ diverged against its clamp and sampled the box boundary for 92 % of the run.

Two mechanisms now fix this, both on by default (self_restart=True):

  • Hansen’s reference termination set — tolx, tolfun, tolfunhist, stagnation, conditioncov, noeffectaxis, noeffectcoord. When one fires, the heuristic restarts through the IPOP/BIPOP path, so ipop_factor finally has an effect in solo runs. These tolerances are written for runs of many thousands of generations and rarely fire inside a 500·dim budget; on their own they were worth +0.0001.

  • σ-divergence detection (sigma_divergence=True, the panobbgo analogue of pycma’s tolupsigma) — restart when the sampling spread σ·sqrt(diag C) has sat at or above sigma_max_frac (default 0.3) of the box range in every coordinate for sigma_divergence_gens generations. This is the addition that paid: +0.026 mean AOCC [+0.008, +0.043] on the 12-seed roster, 11 of 12 seeds positive, at 0.68 restarts per run. The gain is heavy-tailed — a handful of cells gain +0.18 … +0.44 and most are unchanged — because it only fires on the runs that would otherwise diverge (planning/DISCOVERY_2026-09-09.md §23).

restart_from chooses where a self-restart re-centres: "random" (default, the reference IPOP behaviour), "best" or "center". A σ-divergence restart always re-centres on the best point seen regardless — a diverged run has no basin worth keeping. stagnation_frac adds a budget-relative stagnation window; it is off by default because it measured harmful at the fractions where it fires often.

# The default — nothing to configure.
strategy.add(CMAES, sigma0=0.3, restart_mode="ipop")

# Restore the pre-2026-09 behaviour (one run for the whole budget).
strategy.add(CMAES, self_restart=False)

Note

Because CMA-ES now terminates and restarts itself, the external Restart analyzer is not needed with it — and was measured to hurt badly (see the warning under Multimodal problems with IPOP-CMA-ES above).

Active CMA (the default)#

Since 2026-09-27 CMAES runs active CMA-ES by default (active=True): the worst λ − μ offspring of a generation enter the covariance update with negative weights, so C shrinks along directions that proved bad instead of only growing along good ones (N. Hansen, “The CMA Evolution Strategy: A Tutorial”, arXiv:1604.00772, eq. 46–53). pycma and Optuna’s CmaEsSampler do the same.

The update comes with a repair guard (active_skip_repaired=True, also the default). A generation in which an offspring was projected back onto the box gets the positive-only update, and points injected from other solvers never receive a negative weight. Without the guard, active CMA collapses C along a coordinate whose optimum lies on a face of the box: the best offspring are the projected ones, their steps cut short at the face, while the worst step inward at full length. On BBOB f5 (linear slope) that cost up to 0.45 AOCC.

Measured on the 24 BBOB functions (d 2/5/10, instances 0/1, 12 seeds), paired against the old positive-only default: +0.013 mean AOCC at 200·d (11 of 12 seeds positive) and +0.044 at 500·d (12 of 12), ahead of Optuna’s CMA-ES at both budgets, and no function class significantly worse. The largest gains are on the ill-conditioned functions (+0.123 on the high-conditioning class at 500·d) (planning/DISCOVERY_2026-09-09.md §58–§60).

# The default — guarded active CMA.
strategy.add(CMAES)

# The positive-only update, the default before 2026-09-27.
strategy.add(CMAES, active=False)

# Active CMA without the repair guard (Hansen's tutorial update in every
# generation) — only for experiments; it fails on face-bound optima.
strategy.add(CMAES, active_skip_repaired=False)

Shared Archive and Warm Start#

A portfolio of independent solvers is only worth its switching costs if the arms share the evaluations they paid for. The Archive analyzer is that sharing layer: a bounded top-K of the whole result stream, ranked by the constraint handler’s penalty value and not filtered by who, so an arm that asks for a seed gets the best points in the run whoever produced them.

It is opt-in — initialize() does not add it, so a run without warm-started arms keeps exactly the modules it had before:

from panobbgo.analyzers import Archive
from panobbgo.heuristics import LSHADE

strategy.add_analyzer(Archive, k=256)          # or StrategySpec(analyzers=[(Archive, {})])
strategy.add(LSHADE, NP_init="auto", warm_start="archive")

Three selectors are shared by every arm (see archive_seed()):

warm_start

Seeds with

"archive"

the k best results in the run

"archive_diverse"

k well-separated good results

"archive_leaf"

the best point of each of the k best Splitter leaves — k different basins

What each arm does with them:

  • The L-SHADE family places the seeds into the initial population directly, as evaluated results, and fills any shortfall from the cold random path — so warm starting costs zero evaluations.

  • PSO takes positions and personal bests from the top-NP results, also at zero cost, and sets velocities to 0.5·(x_π(i) − x_i) over a random derangement, so the swarm starts moving between known good points instead of from a standstill.

  • CMA-ES fits its initial distribution to the seed cloud. It additionally accepts warm_start="archive_cov", which also seeds the covariance matrix C. Here the warm start saves no evaluations — CMA-ES has no population to fill — the whole gain is starting in the right basin at the right scale.

In all cases an empty archive (t = 0) means the arm silently cold-starts.

On a restart event from the Restart analyzer, the L-SHADE family and PSO re-seed from the archive only when the archive’s best point lies outside the stagnated basin — the bounding box of the arm’s own live population (PSO: positions and evaluated personal bests), inflated by 1 % of the box range per side. Otherwise, and when the arm has no evaluated population yet, the restart goes to the analyzer’s center as a cold restart does, so the "diverse" / "sphere" restart strategies take effect. A block bandit’s warm_start_now at the next block is unaffected. For a custom heuristic, call archive_seed() and treat [] as “use the cold path”; override warm_start_now() if a scheduler should be able to re-seed you mid-run.

The recommended warm configuration, if you use one, is both arms on plain warm_start="archive" with both guards off:

strategy = StrategyBlockBandit(problem, max_evaluations=2500, seed=42,
                               policy="uniform", block_evals=25,
                               warm_start_on_resume=True,
                               warm_start_only_if_foreign=False,
                               warm_start_only_if_better=False)
strategy.add_analyzer(Archive)
strategy.add(CMAES, warm_start="archive")
strategy.add(JSO, NP_init="auto", warm_start="archive")

Three findings behind those settings (planning/DISCOVERY_2026-09-09.md §25, §31):

  • Both arms warm, not one. One-directional sharing scored 0.619 against 0.645 for the same pair with both arms warm — CMA-ES’s warm start is worth as much as the DE arm’s.

  • ``”archive_cov”`` hurts (−0.019, at both dimensions). Seed the mean and σ; leave C = I.

  • ``warm_start_only_if_better`` hurts (−0.073 on the 3-seed screen, −0.007 on the roster). It cuts warm starts lopsidedly: CMA-ES usually holds the incumbent, so the guard starves the arm that most needs the relay. warm_start_only_if_foreign is the shipped guard, but it too was measured off in the specs that lead.

Warning

Experimental, off by default. Sharing is the one portfolio mechanism on this codebase that measures: it removes the −0.08 penalty a cold two-arm portfolio pays against its own best arm (the one CI clear of zero in the whole screen). It does not buy a lead. On the 12-seed roster the best warm portfolio — Blocks_uniform_cj_warm2, CMA-ES + jSO, both warm, rotating every block — reaches 0.685 against CMA-ES alone at 0.666: +0.019, 8 of 12 seeds, CI including zero. Level with the best single arm, not above it. The whole lean is at d=5 (+0.03); at d=2 a single arm converges before a relay can matter (planning/DISCOVERY_2026-09-09.md §27, §30). Treat warm_start as a per-arm experiment to be settled by your own paired A/B, not as a setting to switch on.

Choosing a Strategy#

StrategyRoundRobin#

Use when:

  • You want predictable, deterministic behavior

  • Comparing different heuristic portfolios

  • Debugging or understanding heuristic behavior

from panobbgo.strategies.round_robin import StrategyRoundRobin
strategy = StrategyRoundRobin(problem, max_evaluations=1000)

StrategyRewarding#

Use when (recommended for most cases):

  • You want adaptive selection based on performance

  • Problem structure is unknown

  • You have diverse heuristics

from panobbgo.strategies.rewarding import StrategyRewarding
strategy = StrategyRewarding(
    problem,
    max_evaluations=1000,
    smooth=0.1,      # Exploration parameter
    discount=0.95    # Performance decay
)

StrategyThompsonSampling#

Use when:

  • You want a principled probabilistic approach (Beta-Bernoulli bandit)

  • You want to balance exploration and exploitation automatically without manual tuning

  • Suitable for both stationary and non-stationary (if adapted) environments

from panobbgo.strategies.thompson import StrategyThompsonSampling
strategy = StrategyThompsonSampling(
    problem,
    max_evaluations=1000
)

StrategyUCB#

Use when:

  • You want a deterministic bandit strategy with theoretical guarantees

  • You prefer the Upper Confidence Bound (UCB1) algorithm

from panobbgo.strategies.ucb import StrategyUCB
strategy = StrategyUCB(
    problem,
    max_evaluations=1000,
    ucb_c=1.414  # Exploration constant (default sqrt(2))
)

StrategyLinUCB#

Use when:

  • You want a contextual bandit strategy that adapts based on optimization state

  • Uses context features (budget progress, success rate) to select heuristics

from panobbgo.strategies.contextual import StrategyLinUCB
strategy = StrategyLinUCB(
    problem,
    max_evaluations=1000,
    linucb_alpha=2.0  # Exploration parameter
)

StrategyBlockBandit (experimental)#

StrategyBlockBandit changes what a bandit pull is. The other strategies treat one point as one pull and pay out only on a new best, so a population heuristic emitting λ points per generation has its estimated value bounded by 1/λ by construction — a measurement problem, not a tuning problem. Here a pull is a block: roughly max_eval / n_blocks evaluations (default n_blocks=50) handed to a single arm. A block closes only when it has spent its evaluations and the owner’s queue has run empty, so a generation is never cut in half.

The reward is the AOCC area the arm bought with the block, per evaluation, in decades of log-precision against a run-local anchor. It is anytime (the mean over the block, not its endpoint) and scale-free (invariant under f → c·f + k), so arms on different objective scales are comparable without any tuning.

Two policies:

  • policy="uniform" — round-robin over blocks. Use this one.

  • policy="ducb" (the constructor default) — discounted UCB, with a one-block prologue per arm, an exploit-only tail, and hysteresis so a challenger must beat the incumbent by a factor before the schedule switches.

warm_start_on_resume=True (off by default) re-seeds an arm from the shared archive whenever the scheduler hands it a block back after a gap — see Shared Archive and Warm Start. The trigger is the gap, not an empty queue: a paused arm’s queued generation is stale by construction, so it is cleared first.

from panobbgo.strategies import StrategyBlockBandit
from panobbgo.analyzers import Archive
from panobbgo.heuristics import CMAES, JSO

strategy = StrategyBlockBandit(problem, max_evaluations=2500, seed=42,
                               policy="uniform", block_evals=25,
                               warm_start_on_resume=True,
                               warm_start_only_if_foreign=False)
strategy.add_analyzer(Archive)
strategy.add(CMAES, warm_start="archive")
strategy.add(JSO, NP_init="auto", warm_start="archive")
strategy.start()

What was measured to matter, and what was not#

Screens #5–#7 took the policy apart on the standard battery (planning/DISCOVERY_2026-09-09.md §26, §29, §31):

  • The selection policy contributes nothing measurable. D-UCB at any setting tried — ucb_c 1/2/4, gamma 0.5–0.9, hysteresis, tail_frac swept 0 → 0.6 — lands within 0.003 of plain rotation, and at tail_frac=0 it is rotation (identical in 23 of 30 cells; the mean gap is one cell). Once the arms share their evaluations, a switch stops being a cost and becomes a relay, so there is nothing left for a bandit to minimise. policy="uniform" is therefore the setting to use — it is the same behaviour with none of the knobs.

  • Block length is absolute, not a fraction of the budget. The useful range is ~25–50 evaluations, flat-ish between them with per-cell collapses either side and a hard collapse at 12. Set it with block_evals= — n_blocks=50 is a budget fraction, so on the 500·dim battery it means 20 evaluations at d=2 and 50 at d=5, two different experiments under one name. block_evals="auto" sizes a block as four reference generations, which is the mechanism behind the range: every block boundary discards the arm’s in-flight generation.

  • More than two arms still dilute. 2 → 3 → 4 arms: 0.685 → 0.648 → 0.604. Only at d=5 does a third arm pay (+0.037); at d=2 it costs −0.084. A third arm, if ever, is dimension-gated.

Warning

Experimental, and read screen results carefully. A cold two-arm block bandit loses −0.08 to its best arm, and the interleaving control (StrategyRewarding on the same two arms) loses the same amount — so that is the portfolio, not the scheduling shape. The scheduler itself is sound: every run spends its full budget and no generation is cut. With both arms warm the portfolio reaches parity but not a lead (§27, §30 and the warning under Shared Archive and Warm Start).

Also: the best spec of a three-seed screen is a candidate, not a result. soft_be25 came out of one screen at +0.050 with a CI excluding zero and scored −0.006 on the 12-seed roster — a CI computed on a selected maximum is not the CI of a pre-registered spec (planning/DISCOVERY_2026-09-09.md §30).

StrategyPhased#

Use when:

  • You want to divide the evaluation budget into distinct phases with different strategies

  • Early exploration (e.g., random sampling) should transition to later exploitation (e.g., model-based search)

  • Different heuristic portfolios are appropriate at different stages of the optimization

StrategyPhased is a meta-strategy that composes existing strategies across budget phases. Each phase specifies a fraction of the total budget, a sub-strategy for heuristic selection, and the heuristics to use in that phase. All heuristics are registered from the start, so model-building heuristics (e.g., Gaussian Process) accumulate data even before their phase is active.

from panobbgo.strategies.phased import StrategyPhased
from panobbgo.strategies.round_robin import StrategyRoundRobin
from panobbgo.strategies.rewarding import StrategyRewarding
from panobbgo.strategies.ucb import StrategyUCB
from panobbgo.heuristics import (
    Center, Random, LatinHypercube,
    NelderMead, GaussianProcessHeuristic, LBFGSB
)

problem = Rosenbrock(dims=5)

strategy = StrategyPhased(problem, phases=[
    {
        # Phase 1: Explore the space (first 25% of budget)
        "pct": 25,
        "strategy": (StrategyRoundRobin, {"size": 10}),
        "heuristics": [
            (Center, {}),
            (Random, {}),
            (LatinHypercube, {}),
        ],
    },
    {
        # Phase 2: Adaptive exploitation (remaining 75%)
        # No "pct" on the last phase — it gets the remaining budget.
        "strategy": (StrategyRewarding, {}),
        "heuristics": [
            (NelderMead, {}),
            (GaussianProcessHeuristic, {}),
            (LBFGSB, {}),
        ],
    },
], max_evaluations=1000)

strategy.start()

Phase configuration:

  • pct: Percentage of total budget for this phase. Optional on the last phase (it receives the remaining budget automatically).

  • strategy: A (StrategyClass, kwargs_dict) tuple specifying the selection algorithm and its parameters.

  • heuristics: A list of (HeuristicClass, kwargs_dict) tuples.

At phase transitions, bandit/selection statistics (UCB counts, performance scores, etc.) are reset for the new phase’s heuristics, but domain state (GP models, accumulated data) is preserved.

Three-phase example with gradual refinement:

strategy = StrategyPhased(problem, phases=[
    {
        "pct": 20,
        "strategy": (StrategyRoundRobin, {"size": 10}),
        "heuristics": [(Random, {}), (LatinHypercube, {})],
    },
    {
        "pct": 30,
        "strategy": (StrategyUCB, {"ucb_c": 1.0}),
        "heuristics": [(Random, {}), (NelderMead, {})],
    },
    {
        "strategy": (StrategyRewarding, {}),
        "heuristics": [(GaussianProcessHeuristic, {}), (LBFGSB, {})],
    },
], max_evaluations=2000)

Analyzing Results#

Accessing the Database#

# Get results DataFrame
df = strategy.results.results

# Best point
best = strategy.best
print(f"f(x) = {best.fx}, x = {best.x}, by {best.who}")

# All evaluations by a specific heuristic
random_results = df[df[('who', 0)] == 'Random']

# Feasible points only
feasible = df[df[('cv', 0)] == 0]
best_feasible_fx = feasible[('fx', 0)].min()

Plotting Convergence#

import matplotlib.pyplot as plt

# Get objective values in evaluation order
fx_values = df[('fx', 0)].values

# Compute running minimum
running_min = np.minimum.accumulate(fx_values)

# Plot
plt.figure(figsize=(10, 6))
plt.plot(running_min)
plt.xlabel('Evaluation')
plt.ylabel('Best f(x) found')
plt.title('Convergence Plot')
plt.grid(True)
plt.show()

Heuristic Performance#

For StrategyRewarding:

# Heuristic performance scores
for h in strategy.heuristics:
    print(f"{h.name}: performance = {h.performance:.4f}")

# Count points generated by each heuristic
df[('who', 0)].value_counts()

Pareto Front (Constrained Problems)#

# Access Pareto front from Best analyzer
best_analyzer = strategy.analyzer('Best')
pareto_front = best_analyzer.pareto_front

# Plot (f, CV) trade-off
plt.figure(figsize=(8, 6))
plt.scatter(
    [r.fx for r in pareto_front],
    [r.cv for r in pareto_front],
    c='red', marker='o'
)
plt.xlabel('f(x)')
plt.ylabel('Constraint Violation')
plt.title('Pareto Front')
plt.grid(True)
plt.show()

Advanced Topics#

Reproducible Runs#

Pass seed to the strategy and enable the synchronous evaluation mode to make a run a pure function of that seed:

strategy = StrategyRewarding(problem, seed=1234)
strategy.config.sync_evaluation = True   # deterministic result batches
strategy.add(Random)
strategy.add(JSO, NP_init="auto")
strategy.start()

Two such runs evaluate exactly the same points in the same order. Every module derives its own numpy.random.Generator from the master seed and its name (self.rng: SeedSequence(seed, spawn_key=(crc32(name), n)) for the n-th module of that name, see spawn_rng()), so adding, removing or reordering one module leaves every other module’s stream unchanged; the strategy’s own draws (Thompson sampling, phases) use a separate keyed stream, strategy.rng. The event bus delivers events serially, the main loop waits for all handlers before drawing new points, and each batch is evaluated sequentially in submission order (a thread pool would return results in completion order). Without seed the strategy draws one from numpy’s global state, so np.random.seed(s) before construction also pins the run; strategy.seed reports which seed was used.

The guarantee now covers the subprocess solver bridges (LBFGSB, COBYQA) too. They used to relay their pipe on a private “pump” thread and emit on their own schedule, which put them outside it; they now produce on the strategy’s own thread, when asked, so the point they hand out is a pure function of the values they were given and their worker’s seed (planning/DESIGN_pump_and_stall_2026-09-11.md §1.5).

Budget Management#

A run spends its full max_eval budget unless its heuristics run out of points to give. The Convergence analyzer publishes a converged event when the best value plateaus, but that event only ends the run if you opt in with strategy.config.stop_on_convergence = True (the plateau test fires routinely on multimodal problems, so stopping on it is not a safe default for global optimization).

The other way a run ends early is that nothing can produce a point — see the note under Configuration above. That is a fact about the portfolio, not a timeout, and it is sometimes the correct outcome: a solo COBYQA converges its trust region after roughly 25 evaluations and has nothing further to propose, so it ends there whatever budget you gave it. Pair such an arm with a generator (Random, a population method) if you want the rest of the budget spent.

# Set evaluation budget
strategy = StrategyRewarding(problem, max_evaluations=500)

# Check progress during optimization
print(f"Budget used: {len(strategy.results)} / {strategy.config.max_eval}")

Parallel Evaluation#

# The number of parallel evaluators is a config setting (also used by
# the local 'threaded'/'processes' pools); the batch size per pass is
# sized automatically from the budget and the measured evaluation time.
strategy = StrategyRewarding(problem, dask_n_workers=4)

# Unknown keyword arguments raise TypeError (they used to be ignored).

With strategy.config.evaluation_method = "processes" the evaluations run in spawned worker processes: the script needs an if __name__ == "__main__": guard (see Scripts That Start Worker Processes: the __main__ Guard) and the problem must be picklable.

Multi-start Optimization#

Use the Restart analyzer to automatically restart the search when it gets stuck in a local optimum:

from panobbgo.analyzers import Restart

strategy.add_analyzer(Restart,
    patience=100,              # Restart after 100 evals without improvement
    max_restarts=5,            # Allow up to 5 restarts
    restart_strategy="diverse" # Maximize distance from previous centers
)

Heuristics that define on_restart(center, reason) will automatically clear their queues and begin exploring around the new center. Heuristics without this handler continue as before.

The Restart analyzer pairs well with Convergence — set patience lower than Convergence.window_size so restarts happen before convergence is declared.

Warning

Do not use it with CMAES, which restarts itself (CMA-ES Restarts); the analyzer’s restart event throws away its adapted covariance and halved its score in measurement.

Splitter Resolution#

Splitter partitions the search space into a kd-tree of boxes and cuts a leaf once it holds enough points. How many points is “enough” used to be max(20, max_eval / dim²) — independent of the budget once the dimension is fixed, so a longer run produced the same coarse tree. The threshold is now stated on the leaf population and inverted, so the resolution scales with the budget: at d=2 the tree grows to 38 / 105 / 204 / 351 leaves across the budget range where the old one gave 6 / 33 / 142 / 602, and the root splits at evaluation 37 instead of 250 (planning/DISCOVERY_2026-09-09.md §35).

Parameter

Meaning

leaf_size

Target mean results per leaf (default 25); the tree aims at max_eval / leaf_size leaves.

min_leaf_size

Floor on the split threshold, so a leaf is never cut before it can say anything. Default 2·dim + 2.

max_leaves

Cap on the leaf count (default 512). It raises the threshold rather than refusing splits, so the partition stays a proper kd-tree.

split_rule

Which dimension to cut: "widest" (default) or "value", which scores dimensions by how strongly the objective separates across the prospective cut.

cut_rule

Where along it: "mean" (default) or "median", which cuts the median gap between adjacent distinct coordinates.

legacy

True restores the pre-2026-09-10 tree exactly, ignoring every other knob. Kept so the two trees can be measured paired.

Accepted on the 12-seed roster against legacy=True (§37): the consumers that read the tree gain — Random +0.033 [+0.009, +0.057], RegionUCB +0.050 [+0.023, +0.078] (12/12 seeds), and an archive_leaf warm start +0.053 [+0.027, +0.079]. The gain is concentrated at d=2, where the old tree had five leaves. The reference portfolio is unaffected — 0.0000 in every cell — because none of its arms queries the tree, so this change is free if you do not use one that does.

split_rule="value" and cut_rule="median" both ship opt-in: each measured inside the null floor overall, and the median cut carries a structural regression (it hits the depth cap with a 423-point leaf on a spec where the mean stays at depth 52). RegionUCB, the one consumer that reads every leaf, is the case worth revisiting on a roster — it gained +0.024 and +0.033 from them respectively (§39).

from panobbgo.analyzers import Splitter
from panobbgo.heuristics import RegionUCB

strategy.add_analyzer(Splitter, leaf_size=25)   # defaults; budget-scaled
strategy.add(RegionUCB)                         # UCB1 over the leaves

Note

RegionUCB can now be run alone. It emitted only from on_new_results and had no on_start, so a solo run produced 0 of 200 evaluations — a defect every benchmark hid by pairing it with another arm. With an initial design it spends its budget and is the stronger of the two standalone tree consumers (§39).

Sensitivity Analysis#

Use the Sensitivity analyzer to identify which input dimensions matter most:

from panobbgo.analyzers import Sensitivity

strategy.add_analyzer(Sensitivity,
    update_interval=50,  # Recompute every 50 new results
    method="spearman"    # Or "partial" for partial correlation
)

# After optimization, check importance:
sens = strategy.analyzer('Sensitivity')
print(f"Dimension importance: {sens.importance}")

Sensitivity-Aware Nearby Heuristic

When both Sensitivity and Nearby are active, Nearby automatically becomes sensitivity-aware: it scales its per-dimension perturbations proportionally to the importance scores. Important dimensions receive larger perturbations, focusing the local search where it matters most.

This is particularly valuable for high-dimensional problems where only a subset of dimensions drive the objective. For a 10-D problem where only 3 dimensions are active, the sensitivity-aware Nearby focuses ≈70 % of search effort on those 3 dimensions:

from panobbgo.analyzers import Sensitivity
from panobbgo.heuristics import Nearby

strategy.add(Nearby,
    radius=0.05,
    axes="all",
    new=3,
    sensitivity_scale=1.5,   # Sharpens dim-importance contrast (default 1.0)
)
strategy.add_analyzer(Sensitivity(strategy,
    update_interval=20,       # Recompute every 20 evaluations
))

strategy.start()
print("Dimension importance:", strategy.analyzer("Sensitivity").importance)

The sensitivity_scale parameter controls how aggressively important dimensions dominate. Values > 1 amplify the contrast; 0 disables sensitivity-awareness entirely.

Bayesian Optimization with Gaussian Process#

GaussianProcessHeuristic implements full Bayesian optimization — the gold standard for expensive black-box functions with a limited evaluation budget.

How it works:

  1. After each batch of results, a Gaussian Process (GP) is fitted to all observed \((x, f(x))\) pairs using a Matérn-5/2 kernel (via scikit-learn).

  2. The fitted GP gives a probabilistic prediction \((\mu(x), \sigma^2(x))\) at any un-evaluated point.

  3. An acquisition function selects the next candidate point by trading off predicted quality (\(\mu\)) against prediction uncertainty (\(\sigma\)).

Acquisition functions (acquisition_func parameter):

  • AcquisitionFunction.EI (default) — Expected Improvement: \(\text{EI}(x) = (\mu^* - \mu)\,\Phi(Z) + \sigma\,\phi(Z)\) where \(Z = (\mu^* - \mu)/\sigma\). Best for exploitation-heavy search.

  • AcquisitionFunction.UCB — Lower Confidence Bound for minimisation: \(\text{LCB}(x) = \mu(x) - \kappa\,\sigma(x)\). Higher kappa → more exploration.

  • AcquisitionFunction.PI — Probability of Improvement: \(\text{PI}(x) = \Phi((\mu^* - \mu)/\sigma)\). Conservative; similar to EI.

Constrained EI (EIC): When the problem has active constraint violations the GP automatically trains a second surrogate on \(CV(x)\) and weights the acquisition by the probability of feasibility: \(\text{EIC}(x) = \text{EI}(x) \cdot P(\text{feas.})\).

from panobbgo.heuristics import GaussianProcessHeuristic
from panobbgo.heuristics.gaussian_process import AcquisitionFunction

# Default: EI acquisition, good for smooth/unimodal functions
strategy.add(GaussianProcessHeuristic)

# UCB for more exploratory search (useful for multimodal problems)
strategy.add(GaussianProcessHeuristic,
    acquisition_func=AcquisitionFunction.UCB,
    kappa=2.576,        # 99% confidence level
    n_restarts=10,      # Acquisition optimisation restarts
)

# EI with more exploration (higher xi)
strategy.add(GaussianProcessHeuristic,
    acquisition_func=AcquisitionFunction.EI,
    xi=0.1,             # Default 0.01 → more exploitative; 0.1 → more explorative
)

Recommended pairing with StrategyPhased for a classic two-phase BO workflow:

from panobbgo.strategies.phased import StrategyPhased
from panobbgo.strategies.round_robin import StrategyRoundRobin
from panobbgo.strategies.rewarding import StrategyRewarding
from panobbgo.heuristics import LatinHypercube, GaussianProcessHeuristic, NelderMead, Random

strategy = StrategyPhased(problem, phases=[
    {
        "pct": 20,                                       # 20% = initial design
        "strategy": (StrategyRoundRobin, {"size": 5}),
        "heuristics": [(LatinHypercube, {"div": 4}), (Random, {})],
    },
    {
        "strategy": (StrategyRewarding, {}),              # Remaining 80% = BO
        "heuristics": [
            (GaussianProcessHeuristic, {"n_restarts": 10}),
            (NelderMead, {}),
            (Random, {}),
        ],
    },
], max_evaluations=500)

strategy.start()
print(f"Best: {strategy.best.fx:.6f} at {strategy.best.x}")

Custom Events#

# Publish custom event from a heuristic
class MyHeuristic(Heuristic):
    def on_new_results(self, results):
        if len(results) > 10:
            self.eventbus.publish("my_custom_event", data=results)

# Subscribe in another module
class MyAnalyzer(Analyzer):
    def on_my_custom_event(self, data):
        print(f"Received custom event with {len(data)} results")

Logging#

# Configure in ~/.panobbgo/config.ini
[logging]
level = DEBUG
focus = heuristics  # Only log from heuristics module

# Or programmatically
import logging
logging.getLogger('panobbgo').setLevel(logging.DEBUG)

Handlers. Panobbgo only installs its own fallback handler (stderr, level WARNING on the panobbgo logger) when neither the panobbgo logger nor the root logger has a handler at the moment the first strategy is built. An application that configures logging first — e.g. logging.basicConfig(level=logging.INFO) — gets panobbgo’s records through its own handlers exactly once, at its own level. If you configure logging only after building a strategy, drop the fallback with logging.getLogger('panobbgo').handlers.clear().

Logger focus (--lf / --log-focus NAME) matches the five-character logger names exactly. Every heuristic and analyzer logs under a name of its own — by default the first five letters of its module name, upper-cased (LSHAD, CMAES, NELDE), some pick one explicitly (SPLIT, META, LBFGS, BEST). There is no longer a shared HEUR logger, so --lf HEUR matches nothing: name the modules you want instead (--lf LSHAD --lf CMAES). The core loggers are STRAT, STATS, EVBUS and RSLTS.

Persistent Storage & Resuming#

Panobbgo supports saving optimization results to an SQLite database. This allows you to:

  1. Pause and resume long-running optimizations.

  2. Recover from crashes without losing data.

  3. Analyze results post-hoc using standard SQL tools or other libraries.

Enabling Storage#

Add the storage configuration to your ~/.panobbgo/config.ini or pass it via config.yaml:

config.ini:

[storage]
backend = sqlite
uri = my_results.db

config.yaml:

storage:
  backend: sqlite
  uri: my_results.db

Resuming Optimization#

When you start a strategy with storage enabled, Panobbgo automatically checks the database file. If it finds existing results, it loads them into memory and resumes the optimization process, continuing from where it left off.

# Run 1: Start optimization
# (Assume config enables sqlite storage)
strategy = StrategyRewarding(problem, max_evaluations=100)
strategy.start()
# Strategy runs for 100 evals and saves them to 'my_results.db'

# Run 2: Resume and extend
# Panobbgo loads the 100 previous results
strategy = StrategyRewarding(problem, max_evaluations=200)
strategy.start()
# Strategy runs for another 100 evals (total 200)

The database records a fingerprint of the problem (class, formula version, dimension, box and parameters; wrappers include the wrapped problem). A run on a different problem refuses to open it (StorageMismatchError) instead of resuming foreign results. A database written before fingerprints existed is refused too, since its results cannot be verified; if you know they belong to the problem, set storage: adopt_legacy: true for one run (or call SQLiteStorage(uri).adopt(problem_fingerprint(problem))).

Accessing Stored Data#

The SQLite database contains a results table with the following schema:

  • id: Integer Primary Key

  • x: JSON array of coordinates

  • fx: Objective function value

  • cv_vec: JSON array of constraint violations

  • who: Name of the heuristic that generated the point

  • error: Error estimate

  • timestamp: Unix timestamp of generation

You can query this using the sqlite3 command-line tool or any SQLite client:

sqlite3 my_results.db "SELECT id, fx, who FROM results ORDER BY fx ASC LIMIT 5;"

Troubleshooting#

Dask Cluster Not Found#

Error: TimeoutError: Cluster not found (Only when using evaluation: method: dask)

Solution: Start Dask cluster before running:

dask scheduler &
dask worker localhost:8786 --nworkers 4 &

Function Evaluation Fails#

Error: Exception during evaluation

Solution: Ensure your eval() method handles all inputs in the bounding box:

def eval(self, x):
    try:
        return my_calculation(x)
    except Exception as e:
        # Return large penalty value
        return 1e10

Out of Memory#

Error: MemoryError with large result database

Solution: Reduce max_evaluations or implement result pruning.

Slow Convergence#

Issue: Not finding good solutions

Solutions:

  1. Increase budget: max_evaluations=5000

  2. Add more diverse heuristics

  3. Adjust bounding box (too large?)

  4. Check if problem is feasible

Next Steps#