Skip to content

Enumerations

ropt.enums

Enumerations used in the configuration, event and result APIs.

A member of a string-valued enumeration is a str, so wherever one is accepted its value may be written instead: VariableType, BoundaryType, PerturbationType and AxisName.

VariableType

Bases: StrEnum

Enumerates the types of optimization variables.

Specified in VariablesConfig, this information allows optimization backends to adapt their behavior.

REAL class-attribute instance-attribute

REAL = 'real'

Continuous variables represented by real values.

INTEGER class-attribute instance-attribute

INTEGER = 'integer'

Discrete variables represented by integer values.

BoundaryType

Bases: StrEnum

Enumerates strategies for handling variable boundary violations.

When variables are perturbed during optimization, their values might fall outside the defined lower and upper bounds. This enumeration defines different methods to adjust these perturbed values back within the valid range. The chosen strategy is configured in the GradientConfig.

NONE class-attribute instance-attribute

NONE = 'none'

Do not modify the value.

TRUNCATE class-attribute instance-attribute

TRUNCATE = 'truncate'

Truncate the value \(v_i\) at the lower or upper boundary (\(l_i\), \(u_i\)):

\[ \hat{v_i} = \begin{cases} l_i & \text{if $v_i < l_i$}, \\ u_i & \text{if $v_i > u_i$}, \\ v_i & \text{otherwise} \end{cases} \]

MIRROR class-attribute instance-attribute

MIRROR = 'mirror'

Mirror the value \(v_i\) at the lower or upper boundary (\(l_i\), \(u_i\)):

\[ \hat{v_i} = \begin{cases} 2l_i - v_i & \text{if $v_i < l_i$}, \\ 2u_i - v_i & \text{if $v_i > u_i$}, \\ v_i & \text{otherwise} \end{cases} \]

PerturbationType

Bases: StrEnum

Enumerates methods for scaling perturbation samples.

Before a generated perturbation sample is added to a variable's current value (during gradient estimation, for example), it can be scaled. This enumeration defines the available scaling methods, configured in the GradientConfig.

ABSOLUTE class-attribute instance-attribute

ABSOLUTE = 'absolute'

Use the perturbation value as is.

RELATIVE class-attribute instance-attribute

RELATIVE = 'relative'

Multiply the perturbation value \(p_i\) by the range defined by the bounds of the variables \(c_i\): \(\hat{p}_i = (c_{i,\text{max}} - c_{i,\text{min}}) \times p_i\). The bounds will generally be defined in the configuration for the variables (see VariablesConfig).

EnOptEventType

Bases: IntEnum

Enumerates the types of events emitted during a run.

See Handling Results for when each event type fires and what data it carries.

START_EVALUATION class-attribute instance-attribute

START_EVALUATION = 1

Emitted before a batch of function or gradient evaluations.

FINISHED_EVALUATION class-attribute instance-attribute

FINISHED_EVALUATION = 2

Emitted after that batch completes; carries the results produced.

START_OPTIMIZER class-attribute instance-attribute

START_OPTIMIZER = 3

Emitted just before starting an optimizer.

FINISHED_OPTIMIZER class-attribute instance-attribute

FINISHED_OPTIMIZER = 4

Emitted immediately after an optimizer finishes.

START_ENSEMBLE_EVALUATOR class-attribute instance-attribute

START_ENSEMBLE_EVALUATOR = 5

Emitted before an evaluation without an optimizer begins.

FINISHED_ENSEMBLE_EVALUATOR class-attribute instance-attribute

FINISHED_ENSEMBLE_EVALUATOR = 6

Emitted after an evaluation without an optimizer finishes.

ExitCode

Bases: IntEnum

Enumerates the reasons a task ends.

An optimization either stops or is aborted. It stops when a condition on the optimization is met — the optimizer converged, a budget ran out, a handler decided the results were good enough — so it ends at a point that satisfied a stated criterion, and its result carries the code. A task of any kind is aborted when something ends it regardless of its state, and it then raises AbortedError, which carries the code.

Each member carries a short description in message, for reporting.

UNKNOWN class-attribute instance-attribute

UNKNOWN = 0

Unknown cause of termination.

TOO_FEW_REALIZATIONS class-attribute instance-attribute

TOO_FEW_REALIZATIONS = 1

Returned when too few realizations are evaluated successfully.

MAX_FUNCTIONS_REACHED class-attribute instance-attribute

MAX_FUNCTIONS_REACHED = 2

Returned when the maximum number of function evaluations is reached.

MAX_BATCHES_REACHED class-attribute instance-attribute

MAX_BATCHES_REACHED = 3

Returned when the maximum number of evaluation batches is reached.

STOPPED class-attribute instance-attribute

STOPPED = 4

Returned when an event handler asked the optimization to stop.

A graceful end at an evaluation boundary, on a criterion the caller supplied. A result callback is such a handler.

FINISHED class-attribute instance-attribute

FINISHED = 5

Returned when the optimizer ended the optimization.

EXECUTOR_SHUT_DOWN class-attribute instance-attribute

EXECUTOR_SHUT_DOWN = 6

Carried by AbortedError when the executor could no longer run the work.

Not a failure: in practice the interpreter was shutting down and the worker pool was gone, so the task is released rather than left waiting. An executor that breaks raises ExecutionError instead.

ABORTED class-attribute instance-attribute

ABORTED = 7

Carried by AbortedError when the task was aborted from outside, without regard to where it had got to.

This is what closing a session, or a KeyboardInterrupt passing through a task, gives a task still under way.

ABORTED_ON_ERROR class-attribute instance-attribute

ABORTED_ON_ERROR = 8

Carried by AbortedError when another task raised, and this one was aborted with it.

USER_ABORT class-attribute instance-attribute

USER_ABORT = 9

Carried by AbortedError when Session.abort aborted the task.

Set apart from ABORTED so that an abort that was asked for can be told from one the library performed itself.

message property

message: str

A short description of this exit code, for reporting.

Note that str() and f-strings give the integer value, as they do for any IntEnum; use this or name to report the code.

Returns:

Type Description
str

A capitalized phrase with no trailing period.

AxisName

Bases: StrEnum

Enumerates the semantic meaning of axes in data arrays.

Labels what each dimension of a Results field's multidimensional array represents, and is used to look up axis labels via get_axes. See Working with Results for a full table of fields and their axes.

VARIABLE class-attribute instance-attribute

VARIABLE = 'variable'

The axis index corresponds to the index of the variable.

OBJECTIVE class-attribute instance-attribute

OBJECTIVE = 'objective'

The axis index corresponds to the index of the objective function.

LINEAR_CONSTRAINT class-attribute instance-attribute

LINEAR_CONSTRAINT = 'linear_constraint'

The axis index corresponds to the index of the linear constraint.

NONLINEAR_CONSTRAINT class-attribute instance-attribute

NONLINEAR_CONSTRAINT = 'nonlinear_constraint'

The axis index corresponds to the index of the constraint function.

REALIZATION class-attribute instance-attribute

REALIZATION = 'realization'

The axis index corresponds to the index of the realization.

PERTURBATION class-attribute instance-attribute

PERTURBATION = 'perturbation'

The axis index corresponds to the index of the perturbation.