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 (thepanobbgo.lib.wrappers.NoisyProblemadapter 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:
objectThe bounding box of the
Problem- copy(immutable: bool = False) BoundingBox[source]#
- class panobbgo.lib.CocoProblem(coco_problem)[source]#
Bases:
ProblemWraps a
cocoex.Problemas a panobbgoProblem.- Parameters:
coco_problem – A
cocoex.Probleminstance obtained from iterating over acocoex.Suite.lower_bounds (The bounding box is derived from the COCO problem's)
:param and
upper_bounds. Callingeval()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 + dxand the objective is evaluated atx - 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 originalbox.
- 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 tococo_problem.constraint(x). Returns a numpy array where positive values indicate violation, matching panobbgo’s convention.
- exception panobbgo.lib.EvaluationCrashed[source]#
Bases:
EvaluationFailedThe 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_evaland is published asfailed_evaluations.
- exception panobbgo.lib.EvaluationFailed[source]#
Bases:
ExceptionAn objective’s own signal that this call returns no value.
Base class of
EvaluationCrashedandEvaluationTimedOut. A problem raises one of them fromProblem.eval()to simulate a failed evaluation (the failure regions ofFamily); 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:
EvaluationFailedThe 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 ordinaryResultwithResult.timed_outset 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:
ProblemWrapperApplies 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 + dxand the objective is evaluated atx - 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 originalbox.
- class panobbgo.lib.NoisyProblem(problem: Problem, model: NoiseModel, *, seed: int, resample: bool = False, f_opt: float | None = None)[source]#
Bases:
ProblemWrap
problemsoevalreturns a noisy value and the true one stays reachable.- Parameters:
problem – The inner
Problem. Its box is copied, itseval_constraintsand (if present)close/reset/optimum_yare 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 atxis frozen — a pure function of(seed, x).True: the k-th evaluation ofxdraws 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’soptimum_y, else itsf_opt(the classic functions declare one). If neither is known the noise is applied to the raw valuefwithout themax(0, ·)clamp — a guessedf_opt = 0would flatten every objective value below 0. OnlyNoNoise,AdditiveGaussianNoiseandMultiplicativeGaussianNoisemake sense on a raw value; the BBOB models then raiseValueErrorand need an explicitf_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 + dxand the objective is evaluated atx - 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 originalbox.
- apply_noise(x: ndarray, true_fx: float) float[source]#
Corrupt a known true value at
x— the pure(seed, x)map.
- 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.ndarrayoffloats.- Return type:
- eval_pair(x: ndarray) Tuple[float, float][source]#
Return
(noisy, true)from a single inner evaluation.
- 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
- property wrapped: Problem#
The inner problem (the name
ProblemWrapperuses).
- class panobbgo.lib.NormalizedProblem(problem: Problem)[source]#
Bases:
ProblemWrapperScales 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 + dxand the objective is evaluated atx - 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 originalbox.
- 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 thisevalmethod.- 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.ndarrayoffloats.- Return type:
- class panobbgo.lib.Point(x: ndarray | List[float] | Tuple[float, ...], who: str)[source]#
Bases:
objectThis contains the x vector for a new point and a reference to
whohas generated it.- property who: str#
A string, which is the
nameof 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:
objectthis 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 + dxand the objective is evaluated atx - 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 originalbox.
- property box: BoundingBox#
The bounding box for this problem, a \((\mathit{dim},2)\)-
array.
- 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 thisevalmethod.- 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.ndarrayoffloats.- Return type:
- 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 thanNone, and several implementations decide that per instance (a family withn_constraints=0returnsNone). 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;Nonefalls 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:
ProblemBase 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 + dxand the objective is evaluated atx - 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 originalbox.
- 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 thisevalmethod.- 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.ndarrayoffloats.- Return type:
- 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:
objectThis 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 vectorcv_norm: the norm used to calculatecv. (seenumpy.linalg.norm(), defaultNonemeans 2-norm)timed_out: the evaluation hitevaluation.timeout;fxis thenNaN,cv_vecNoneandcvinf— seetimed_out.
- property cv: float#
Constraint Violation.
The chosen norm of
cv_vec; seecv_normin constructor.Note
Only the positive entries are used to calculate the norm! A
NaNentry is an unknown violation, not a satisfied constraint: the result is theninf(infeasible), never feasible. (cv_vec > 0.0isFalseforNaN, 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 fx: float | None#
The function value \(f(x)\) after
evaluatingit.
- t_dispatch: float | None = None#
Virtual dispatch / completion time of the call under
evaluation.method = "virtual"(panobbgo.virtual_clock);Nonein 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#
Trueiff this is the placeholder of an evaluation that hitevaluation.timeout.Such a result is a regular one — recorded, charged once against the budget, published through
new_results— withfx = NaN,cv_vec = None(the violations are unknown; its length is not guessed) andcvinf(infeasible), so every ranking puts it last and heuristics see a bad point. The results frame writesNaNinto itscv_veccolumns for such a row.
- panobbgo.lib.is_simulated_crash(error: Any) bool[source]#
Is
error(an exception or therepran evaluation path reports) anEvaluationCrashed?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 atDEBUGrather thanERROR.
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:
ProblemWrapperApplies 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 + dxand the objective is evaluated atx - 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 originalbox.
- class panobbgo.lib.wrappers.NoisyProblem(problem: Problem, noise_std: float = 0.1, noise_type: str = 'additive', seed: int | None = None)[source]#
Bases:
NoisyProblemDeprecated: use
panobbgo.lib.noise.NoisyProblem(exported aspanobbgo.lib.NoisyProblem).Kept for the old signature. Gaussian noise on the raw value —
f + noise_std·ε("additive") orf·(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=Nonepicks 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 + dxand the objective is evaluated atx - 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 originalbox.
- 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 abovef_opt, so withf_opt != 0the 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:
ProblemWrapperScales 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 + dxand the objective is evaluated atx - 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 originalbox.
- 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 thisevalmethod.- 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.ndarrayoffloats.- Return type:
- class panobbgo.lib.wrappers.ProblemWrapper(problem: Problem, box: list[tuple[float, float]] | None = None)[source]#
Bases:
ProblemBase 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 + dxand the objective is evaluated atx - 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 originalbox.
- 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 thisevalmethod.- 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.ndarrayoffloats.- Return type: