optiprofiler.Feature

Contents

optiprofiler.Feature#

class optiprofiler.Feature(name, **options)[source]#

Specification of the feature applied to the benchmarked problems: an ordered pipeline of stages, each with its own validated stage-local options.

A single feature is a one-stage pipeline; 'plain' is the identity with no effective stage. The specification is immutable and carries no experiment state: the number of runs belongs to benchmark(..., n_runs=N), and every trial builds fresh runtime state from the records.

Parameters:
namestr, dict, list, tuple or Feature

Either a feature name, several names joined with + to apply them in order ('noisy+truncated' adds noise first and truncates the noisy value afterwards; keyword options are broadcast to every stage that accepts them), or a structured specification: one stage entry {'name': ..., 'options': {...}} or an ordered list/tuple of such entries and bare names, each stage owning the options inside its entry (no keyword option is accepted then). An existing Feature is accepted as it is, without reparsing. The available stage names are 'plain', 'perturbed_x0', 'noisy', 'truncated', 'permuted', 'linearly_transformed', 'random_nan', 'unrelaxable_constraints', 'nonquantifiable_constraints', 'quantized' and 'custom'.

Other Parameters:
distributionstr or callable, optional

Distribution used by the ‘noisy’ feature (‘gaussian’ or ‘uniform’) and the ‘perturbed_x0’ feature (‘spherical’ or ‘gaussian’), or a callable distribution(rng, size).

noise_level, noise_type, noise_mode, noise_mapoptional

Options of the ‘noisy’ feature; noise_map is ‘chebyshev’ or a callable deterministic scalar map. noise_level is a finite, nonnegative real scalar.

perturbation_levelfloat or array_like, optional

Finite, nonnegative amplitude for ‘perturbed_x0’: a scalar or a one-dimensional vector of length 1 or problem.n (coordinatewise). Zero leaves the initial point unchanged; NaN and infinity are invalid.

significant_digits, perturbed_trailing_digitsoptional

Options of the ‘truncated’ feature.

nan_rateint or float, optional

Finite real scalar in [0, 1] for the ‘random_nan’ feature.

rotated, condition_factoroptional

Options of ‘linearly_transformed’; condition_factor is a finite, nonnegative real scalar.

unrelaxable_bounds, unrelaxable_linear_constraints, unrelaxable_nonlinear_constraintsbool, optional

Options of the ‘unrelaxable_constraints’ feature.

mesh_size, mesh_type, ground_truthoptional

Options of ‘quantized’. mesh_size is a finite, positive real scalar; mesh_type is ‘absolute’ or ‘relative’ (case-insensitive, stored in lowercase). Booleans are not numeric magnitude/count options. NumPy real scalar magnitudes are accepted. Only perturbation_level also accepts vectors; other magnitude options must be scalars. Option names are case-insensitive; two spellings of one name in the same call or stage entry are rejected as a duplicate.

mod_x0, mod_affine, mod_bounds, mod_linear_ub, mod_linear_eq, mod_fun, mod_cub, mod_ceqcallable, optional

Callbacks of the ‘custom’ feature.

Raises:
TypeError

If an argument received an invalid value.

ValueError

If the arguments are inconsistent, or if an experiment option such as n_runs is given here instead of to benchmark.

Notes

options and the modifier_* methods remain as deprecated one-stage conveniences only; the benchmark, the recorder, the archives and the reports use stages. Each call of such a method builds a runtime of its own. A runtime keeps the transformation of mod_affine for one problem and seed (one entry: asking it about another problem or seed replaces it), so that the initial point, the bounds, the linear constraints, the derivatives and every evaluation of a FeaturedProblem share one map, whereas each of these conveniences asks mod_affine again: a callback with a state can give two of them two different maps. The kept transformation belongs to the problem object it was asked for; a problem is not to be changed in place while a featured problem is built on it.

Ownership of option values: exact built-in data containers (list, tuple, dict) and exact numpy.ndarray values are copied at construction (arrays as read-only copies) and the inspection views hand out isolated read-only array copies, fresh container copies and read-only mappings, so changing such a container or array after construction, or changing what a view returned, never changes the specification. Opaque values are retained by identity and are not copied: callables, container subclasses, any other object and the elements of object-dtype arrays; the specification never mutates them, but their own state stays the caller’s. No copy, iteration or reduction hook of a user object is invoked.

Examples

from optiprofiler import Feature

feature = Feature('noisy', noise_level=1e-2)
feature.stages[0].options['noise_level']   # 0.01

pipeline = Feature([
    {'name': 'noisy', 'options': {'distribution': 'uniform'}},
    {'name': 'perturbed_x0', 'options': {'distribution': 'gaussian'}},
])
[stage.identity for stage in pipeline.stages]   # ['noisy#0', 'perturbed_x0#0']
Attributes:
stagestuple

The effective stages, in order (empty for the identity).

namestr

The effective name; 'plain' for the identity.

declared_name, declaredstr or None, Declaration

The declaration as given (declaration route and entries before defaults). A specification imported from a historical object that recorded no declaration has route None, no entries and declared_name None; its effective stages are complete.

is_stochastic, is_identitybool

Methods

get_default_rng(seed, *args)

Generate a random number generator.

modifier_affine(seed, problem)

Deprecated one-stage convenience; see stages.

modifier_bounds(seed, problem)

Deprecated one-stage convenience; see stages.

modifier_ceq(x, seed, problem, n_eval_ceq)

Deprecated one-stage convenience; see stages.

modifier_cub(x, seed, problem, n_eval_cub)

Deprecated one-stage convenience; see stages.

modifier_fun(x, seed, problem, n_eval)

Deprecated one-stage convenience; see stages.

modifier_linear_eq(seed, problem)

Deprecated one-stage convenience; see stages.

modifier_linear_ub(seed, problem)

Deprecated one-stage convenience; see stages.

modifier_x0(seed, problem)

Deprecated one-stage convenience; see stages.

chebyshev_noise_map