Library Module#

Core problem definition classes:

  • Problem: Base class for optimization problems

  • Point: Represents a point in parameter space

  • Result: Contains evaluation results

  • BoundingBox: Defines parameter bounds

Problem Wrappers:

  • ProblemWrapper: Base class for composable problem decorators

  • NormalizedProblem: Scales all dimensions to [0, 1]

  • LogTransformProblem: Applies log transform to objective

  • NoisyProblem (panobbgo.lib.noise): deterministic, seeded noise models (the panobbgo.lib.wrappers.NoisyProblem adapter is deprecated)

Library Core#

This module exposes the core data structures used throughout Panobbgo.

class panobbgo.lib.BoundingBox(box: List[Tuple[float, float]] | Sequence[Tuple[float, float]] | Tuple[Tuple[float, float], ...] | ndarray, dx: ndarray | None = None, immutable: bool = True)[source]#

Bases: object

The bounding box of the Problem

box: ndarray#
center: ndarray#
copy(immutable: bool = False) → BoundingBox[source]#
ranges: ndarray#
class panobbgo.lib.CocoProblem(coco_problem)[source]#

Bases: Problem

Wraps a cocoex.Problem as a panobbgo Problem.

Parameters:
  • coco_problem – A cocoex.Problem instance obtained from iterating over a cocoex.Suite.

  • lower_bounds (The bounding box is derived from the COCO problem's)

:param and upper_bounds. Calling eval() delegates to the COCO: :param problem callable: :param which automatically increments the COCO evaluation: :param counter and triggers observer logging.:

Parameters:
  • box (list) – list of tuples for the bounding box with length n, e.g.: \(\left[ (-1,1), (-100, 0), (0, 0.01) \right]\).

  • dx (list) – translation of the whole problem, an n-dimensional vector (default: None). The search box becomes box + dx and the objective is evaluated at x - dx, i.e. the problem seen by the optimiser is \(g(x) = f(x - dx)\) and a minimiser \(x^*\) of \(f\) moves to \(x^* + dx\). Every point the objective sees lies in the original box.

eval(x)[source]#

Evaluate the objective function.

Calls the COCO problem callable, which also triggers COCO’s internal evaluation counter and observer logging.

eval_constraints(x)[source]#

Evaluate constraint violations (if any).

For constrained COCO suites (e.g. bbob-constrained), delegates to coco_problem.constraint(x). Returns a numpy array where positive values indicate violation, matching panobbgo’s convention.

fingerprint() → str[source]#

Storage identity: the COCO id encodes suite, function, instance and dimension.

property has_constraints: bool#

Whether the wrapped COCO problem has constraints.

property initial_solution: ndarray#

The COCO-provided initial solution.

exception panobbgo.lib.EvaluationCrashed[source]#

Bases: EvaluationFailed

The call crashed: the evaluation path books it as a failed evaluation.

Nothing special happens on the way: like any exception raised by an objective it leaves no result, stays charged against max_eval and is published as failed_evaluations.

exception panobbgo.lib.EvaluationFailed[source]#

Bases: Exception

An objective’s own signal that this call returns no value.

Base class of EvaluationCrashed and EvaluationTimedOut. A problem raises one of them from Problem.eval() to simulate a failed evaluation (the failure regions of Family); a real objective that fails raises whatever it raises. The benchmark trackers (IOHTracker) count such a call as spent budget without progress, and re-raise it.

exception panobbgo.lib.EvaluationTimedOut[source]#

Bases: EvaluationFailed

The call would have run past evaluation.timeout.

Problem.__call__() turns it into the same placeholder the evaluation paths book for a real timeout — Result(point, NaN, cv_vec=None, timed_out=True) — without anyone waiting. Because the conversion happens inside the call, every evaluation path (inline, threads, processes, dask, a simulated clock) receives an ordinary Result with Result.timed_out set and books it as a timed-out evaluation, deterministically. A simulator with a duration model reads the same flag to charge the call its timeout duration.

class panobbgo.lib.LogTransformProblem(problem: Problem, offset: float = 0.0)[source]#

Bases: ProblemWrapper

Applies log transform to the objective: log(1 + f(x) - offset). Useful when objective spans orders of magnitude.

Constraints are NOT transformed (they have their own scale via cv).

Parameters:
  • box (list) – list of tuples for the bounding box with length n, e.g.: \(\left[ (-1,1), (-100, 0), (0, 0.01) \right]\).

  • dx (list) – translation of the whole problem, an n-dimensional vector (default: None). The search box becomes box + dx and the objective is evaluated at x - dx, i.e. the problem seen by the optimiser is \(g(x) = f(x - dx)\) and a minimiser \(x^*\) of \(f\) moves to \(x^* + dx\). Every point the objective sees lies in the original box.

eval(x)[source]#

This is called to evaluate the given black-box function. The problem should be called directly (__call__ special function wraps this) and the given problem should subclass this eval method.

Return type:

numpy.float64

class panobbgo.lib.NoisyProblem(problem: Problem, model: NoiseModel, *, seed: int, resample: bool = False, f_opt: float | None = None)[source]#

Bases: Problem

Wrap problem so eval returns a noisy value and the true one stays reachable.

Parameters:
  • problem – The inner Problem. Its box is copied, its eval_constraints and (if present) close / reset / optimum_y are delegated.

  • model – A NoiseModel.

  • seed – Seed of the noise stream. Two wrappers with the same seed over the same inner problem are the same noisy function; different seeds are different realisations of the same noise process, and that is how the harness makes instances differ.

  • resample – False (default): the noise at x is frozen — a pure function of (seed, x). True: the k-th evaluation of x draws fresh noise from (seed, x, k). See the module docstring for why the default is the frozen one.

  • f_opt – The value the precision is measured against: the models corrupt max(0, f - f_opt). Defaults to the inner problem’s optimum_y, else its f_opt (the classic functions declare one). If neither is known the noise is applied to the raw value f without the max(0, ·) clamp — a guessed f_opt = 0 would flatten every objective value below 0. Only NoNoise, AdditiveGaussianNoise and MultiplicativeGaussianNoise make sense on a raw value; the BBOB models then raise ValueError and need an explicit f_opt.

Notes

The class deliberately does not count evaluations — that is IOHTracker’s job, and the wrapper is installed under it.

Parameters:
  • box (list) – list of tuples for the bounding box with length n, e.g.: \(\left[ (-1,1), (-100, 0), (0, 0.01) \right]\).

  • dx (list) – translation of the whole problem, an n-dimensional vector (default: None). The search box becomes box + dx and the objective is evaluated at x - dx, i.e. the problem seen by the optimiser is \(g(x) = f(x - dx)\) and a minimiser \(x^*\) of \(f\) moves to \(x^* + dx\). Every point the objective sees lies in the original box.

apply_noise(x: ndarray, true_fx: float) → float[source]#

Corrupt a known true value at x — the pure (seed, x) map.

close() → None[source]#
eval(x: ndarray) → float[source]#

The noisy value — what an optimizer running on this problem sees.

eval_constraints(x: ndarray) → ndarray | None[source]#

This method is optionally overwritten by the problem to calculate the constraint violations. It has to return a numpy.ndarray of floats.

Return type:

numpy.ndarray

eval_pair(x: ndarray) → Tuple[float, float][source]#

Return (noisy, true) from a single inner evaluation.

property f_opt: float | None#

Same as optimum_y (the name the classic functions use).

fingerprint() → str[source]#

Storage identity: noise model, seed, resampling and the inner problem’s fingerprint.

property optimum_y: float | None#

unknown).

Type:

The inner problem’s optimum — noise leaves it where it was (None

reset() → None[source]#
true_eval(x: ndarray) → float[source]#

The noiseless value. Costs one inner evaluation.

property wrapped: Problem#

The inner problem (the name ProblemWrapper uses).

class panobbgo.lib.NormalizedProblem(problem: Problem)[source]#

Bases: ProblemWrapper

Scales all dimensions to [0, 1]. Heuristics see a unit hypercube; the wrapper maps back to original coordinates for evaluation.

x_original = x_normalized * ranges + lower_bounds

Parameters:
  • box (list) – list of tuples for the bounding box with length n, e.g.: \(\left[ (-1,1), (-100, 0), (0, 0.01) \right]\).

  • dx (list) – translation of the whole problem, an n-dimensional vector (default: None). The search box becomes box + dx and the objective is evaluated at x - dx, i.e. the problem seen by the optimiser is \(g(x) = f(x - dx)\) and a minimiser \(x^*\) of \(f\) moves to \(x^* + dx\). Every point the objective sees lies in the original box.

eval(x)[source]#

This is called to evaluate the given black-box function. The problem should be called directly (__call__ special function wraps this) and the given problem should subclass this eval method.

Return type:

numpy.float64

eval_constraints(x)[source]#

This method is optionally overwritten by the problem to calculate the constraint violations. It has to return a numpy.ndarray of floats.

Return type:

numpy.ndarray

class panobbgo.lib.Point(x: ndarray | List[float] | Tuple[float, ...], who: str)[source]#

Bases: object

This contains the x vector for a new point and a reference to who has generated it.

property who: str#

A string, which is the name of a heuristic.

To get the actual heuristic, use the strategie’s heuristic() method.

property x: ndarray#

The vector \(x\), a numpy.ndarray

class panobbgo.lib.Problem(box: List[Tuple[float, float]] | Sequence[Tuple[float, float]] | Tuple[Tuple[float, float], ...], dx: ndarray | List[float] | Tuple[float, ...] | None = None)[source]#

Bases: object

this is used to store the objective function, information about the problem, etc.

Parameters:
  • box (list) – list of tuples for the bounding box with length n, e.g.: \(\left[ (-1,1), (-100, 0), (0, 0.01) \right]\).

  • dx (list) – translation of the whole problem, an n-dimensional vector (default: None). The search box becomes box + dx and the objective is evaluated at x - dx, i.e. the problem seen by the optimiser is \(g(x) = f(x - dx)\) and a minimiser \(x^*\) of \(f\) moves to \(x^* + dx\). Every point the objective sees lies in the original box.

property box: BoundingBox#

The bounding box for this problem, a \((\mathit{dim},2)\)-array.

property center: ndarray#

center of the box

property dim: int#

The number of dimensions.

dx: ndarray | None#
eval(x: ndarray) → float[source]#

This is called to evaluate the given black-box function. The problem should be called directly (__call__ special function wraps this) and the given problem should subclass this eval method.

Return type:

numpy.float64

eval_constraints(x: ndarray) → ndarray | None[source]#

This method is optionally overwritten by the problem to calculate the constraint violations. It has to return a numpy.ndarray of floats.

Return type:

numpy.ndarray

is_constrained() → bool[source]#

Does this problem report constraint violations?

There is no declared flag: a problem is constrained iff its eval_constraints() returns a vector rather than None, and several implementations decide that per instance (a family with n_constraints=0 returns None). So the constraints are evaluated once, at the box centre, through the same translation __call__() applies. That is one constraint evaluation and no objective evaluation; it does not touch any evaluation counter.

project(point: ndarray) → ndarray[source]#

projects given point into the search box. e.g. \([-1.1, 1]\) with box \([(-1,1),(-1,1)]\) gives \([-1,1]\)

random_point(distribution: str = 'uniform', rng: Generator | None = None) → ndarray[source]#

Generates a random point inside the given search box.

Parameters:
  • rng – Generator to draw from. Modules pass their own self.rng; None falls back to numpy’s global state.

  • distribution – The distribution to use. Currently supports ‘uniform’ and ‘normal’. Normal distribution is centered in the box, scaled such that 3 standard deviations cover half the range, and is clipped to ensure the point stays strictly within the box boundaries.

Returns:

A random point within the search box as a numpy array.

Raises:

ValueError – If an unsupported distribution is specified.

property ranges: ndarray#

The ranges along each dimension, a numpy.ndarray.

class panobbgo.lib.ProblemWrapper(problem: Problem, box: list[tuple[float, float]] | None = None)[source]#

Bases: Problem

Base class for problem wrappers. Delegates to wrapped problem.

Parameters:
  • box (list) – list of tuples for the bounding box with length n, e.g.: \(\left[ (-1,1), (-100, 0), (0, 0.01) \right]\).

  • dx (list) – translation of the whole problem, an n-dimensional vector (default: None). The search box becomes box + dx and the objective is evaluated at x - dx, i.e. the problem seen by the optimiser is \(g(x) = f(x - dx)\) and a minimiser \(x^*\) of \(f\) moves to \(x^* + dx\). Every point the objective sees lies in the original box.

eval(x)[source]#

This is called to evaluate the given black-box function. The problem should be called directly (__call__ special function wraps this) and the given problem should subclass this eval method.

Return type:

numpy.float64

eval_constraints(x)[source]#

This method is optionally overwritten by the problem to calculate the constraint violations. It has to return a numpy.ndarray of floats.

Return type:

numpy.ndarray

fingerprint() → str[source]#

Storage identity: the wrapper class, its parameters and the wrapped problem’s fingerprint.

property wrapped: Problem#

The underlying wrapped problem.

class panobbgo.lib.Result(point: Point | None, fx: float | None, cv_vec: ndarray | None = None, cv_norm: int | float | str | None = None, error: float = 0.0, timed_out: bool = False)[source]#

Bases: object

This represents one result, wich is a mapping of a Point \(x \rightarrow f(x)\).

Additionally, there is also

  • error: estimated or calculated \(\Delta f(x)\).

  • cv_vec: a possibly empty vector listing the constraint violation for each constraint.

Args:

  • cv_vec: the constraint violation vector

  • cv_norm: the norm used to calculate cv. (see numpy.linalg.norm(), default None means 2-norm)

  • timed_out: the evaluation hit evaluation.timeout; fx is then NaN, cv_vec None and cv inf — see timed_out.

property cv: float#

Constraint Violation.

The chosen norm of cv_vec; see cv_norm in constructor.

Note

Only the positive entries are used to calculate the norm! A NaN entry is an unknown violation, not a satisfied constraint: the result is then inf (infeasible), never feasible. (cv_vec > 0.0 is False for NaN, so the entry used to be silently dropped.)

property cv_vec: ndarray | None#

Vector of constraint violations for each constraint, or None.

Note

Be aware, that entries could be negative. This is useful if you want to know how well a point is satisfied. The .cv property just looks at the positive entries, though.

property error: float#

Error margin of function evaluation, usually 0.0.

property fx: float | None#

The function value \(f(x)\) after evaluating it.

property point: Point | None#

Returns the actual Point object.

property pp: ndarray#

pareto point, i.e. array([cv, fx])

t_complete: float | None = None#
t_dispatch: float | None = None#

Virtual dispatch / completion time of the call under evaluation.method = "virtual" (panobbgo.virtual_clock); None in every other mode. Class-level defaults, so results pickled before these existed still load. In memory only: the sqlite storage backend does not store them.

property timed_out: bool#

True iff this is the placeholder of an evaluation that hit evaluation.timeout.

Such a result is a regular one — recorded, charged once against the budget, published through new_results — with fx = NaN, cv_vec = None (the violations are unknown; its length is not guessed) and cv inf (infeasible), so every ranking puts it last and heuristics see a bad point. The results frame writes NaN into its cv_vec columns for such a row.

property who: str#

The name of the heuristic, who did generate this point (String).

property x: ndarray | None#

Point \(x\) where this result has been evaluated.

panobbgo.lib.is_simulated_crash(error: Any) → bool[source]#

Is error (an exception or the repr an evaluation path reports) an EvaluationCrashed?

The evaluation paths carry a failure as repr(exc) (a worker process can only send a string), so this reads the prefix. They log such an expected, simulated failure at DEBUG rather than ERROR.

Problem Wrappers#

Composable decorator classes that wrap a Problem instance and transform inputs/outputs, without modifying the original problem.

These are composable:

wrapped = NormalizedProblem(LogTransformProblem(MyProblem()))
class panobbgo.lib.wrappers.LogTransformProblem(problem: Problem, offset: float = 0.0)[source]#

Bases: ProblemWrapper

Applies log transform to the objective: log(1 + f(x) - offset). Useful when objective spans orders of magnitude.

Constraints are NOT transformed (they have their own scale via cv).

Parameters:
  • box (list) – list of tuples for the bounding box with length n, e.g.: \(\left[ (-1,1), (-100, 0), (0, 0.01) \right]\).

  • dx (list) – translation of the whole problem, an n-dimensional vector (default: None). The search box becomes box + dx and the objective is evaluated at x - dx, i.e. the problem seen by the optimiser is \(g(x) = f(x - dx)\) and a minimiser \(x^*\) of \(f\) moves to \(x^* + dx\). Every point the objective sees lies in the original box.

eval(x)[source]#

This is called to evaluate the given black-box function. The problem should be called directly (__call__ special function wraps this) and the given problem should subclass this eval method.

Return type:

numpy.float64

class panobbgo.lib.wrappers.NoisyProblem(problem: Problem, noise_std: float = 0.1, noise_type: str = 'additive', seed: int | None = None)[source]#

Bases: NoisyProblem

Deprecated: use panobbgo.lib.noise.NoisyProblem (exported as panobbgo.lib.NoisyProblem).

Kept for the old signature. Gaussian noise on the raw value — f + noise_std·ε ("additive") or f·(1 + noise_std·ε) ("multiplicative") — with fresh noise per evaluation, now drawn from the deterministic (seed, x, k) stream of the noise module instead of one generator shared by every evaluator thread (whose draws depended on thread scheduling). seed=None picks a random seed.

Parameters:
  • box (list) – list of tuples for the bounding box with length n, e.g.: \(\left[ (-1,1), (-100, 0), (0, 0.01) \right]\).

  • dx (list) – translation of the whole problem, an n-dimensional vector (default: None). The search box becomes box + dx and the objective is evaluated at x - dx, i.e. the problem seen by the optimiser is \(g(x) = f(x - dx)\) and a minimiser \(x^*\) of \(f\) moves to \(x^* + dx\). Every point the objective sees lies in the original box.

apply_noise(x: ndarray, true_fx: float) → float[source]#

Corrupt a known true value at x — the pure (seed, x) map.

fingerprint() → str[source]#

Storage identity, distinct from panobbgo.lib.noise.NoisyProblem’s.

apply_noise() corrupts the raw value, not the precision above f_opt, so with f_opt != 0 the two give different values for the same model, seed and point; sharing a fingerprint let a run’s database resume under the other silently.

class panobbgo.lib.wrappers.NormalizedProblem(problem: Problem)[source]#

Bases: ProblemWrapper

Scales all dimensions to [0, 1]. Heuristics see a unit hypercube; the wrapper maps back to original coordinates for evaluation.

x_original = x_normalized * ranges + lower_bounds

Parameters:
  • box (list) – list of tuples for the bounding box with length n, e.g.: \(\left[ (-1,1), (-100, 0), (0, 0.01) \right]\).

  • dx (list) – translation of the whole problem, an n-dimensional vector (default: None). The search box becomes box + dx and the objective is evaluated at x - dx, i.e. the problem seen by the optimiser is \(g(x) = f(x - dx)\) and a minimiser \(x^*\) of \(f\) moves to \(x^* + dx\). Every point the objective sees lies in the original box.

eval(x)[source]#

This is called to evaluate the given black-box function. The problem should be called directly (__call__ special function wraps this) and the given problem should subclass this eval method.

Return type:

numpy.float64

eval_constraints(x)[source]#

This method is optionally overwritten by the problem to calculate the constraint violations. It has to return a numpy.ndarray of floats.

Return type:

numpy.ndarray

class panobbgo.lib.wrappers.ProblemWrapper(problem: Problem, box: list[tuple[float, float]] | None = None)[source]#

Bases: Problem

Base class for problem wrappers. Delegates to wrapped problem.

Parameters:
  • box (list) – list of tuples for the bounding box with length n, e.g.: \(\left[ (-1,1), (-100, 0), (0, 0.01) \right]\).

  • dx (list) – translation of the whole problem, an n-dimensional vector (default: None). The search box becomes box + dx and the objective is evaluated at x - dx, i.e. the problem seen by the optimiser is \(g(x) = f(x - dx)\) and a minimiser \(x^*\) of \(f\) moves to \(x^* + dx\). Every point the objective sees lies in the original box.

eval(x)[source]#

This is called to evaluate the given black-box function. The problem should be called directly (__call__ special function wraps this) and the given problem should subclass this eval method.

Return type:

numpy.float64

eval_constraints(x)[source]#

This method is optionally overwritten by the problem to calculate the constraint violations. It has to return a numpy.ndarray of floats.

Return type:

numpy.ndarray

fingerprint() → str[source]#

Storage identity: the wrapper class, its parameters and the wrapped problem’s fingerprint.

property wrapped: Problem#

The underlying wrapped problem.