Evaluation Classes
ropt.evaluation
The data exchanged between ropt and a user evaluation function.
An EvaluationBatchContext describes
which rows must be evaluated, an
EvaluationBatchResult carries the
objective and constraint values back, and
EvaluationBatchCallback is the
protocol such a callable must follow. For the
Evaluator classes that wrap them, see
Evaluators.
See Writing Evaluation Callbacks for usage.
ropt.evaluation.EvaluationBatchContext
dataclass
Per-batch metadata passed to evaluator functions.
See Writing Evaluation Callbacks for usage details and examples.
Attributes:
| Name | Type | Description |
|---|---|---|
context |
EnOptContext
|
The |
active |
NDArray[bool_]
|
Boolean array indicating which rows require evaluation. |
realizations |
NDArray[intc]
|
Realization index for each row. |
perturbations |
NDArray[intc] | None
|
Perturbation index for each row (< 0 means unperturbed). |
batch_id |
int
|
Integer identifying the current evaluation batch. |
metadata |
dict[str, Any] | None
|
The metadata the run was started with, if any. |
get_active_evaluations
Return only the rows of array where active is True.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
NDArray[T]
|
A 1-D or 2-D array with one entry/row per variable vector. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[T]
|
The subset of rows corresponding to active evaluations. |
insert_inactive_results
Expand a filtered array back to full size, filling inactive rows.
Inserts fill_value at positions where active is False, restoring
the array to its original number of rows.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
NDArray[T]
|
The filtered array (output of |
required |
fill_value
|
float
|
The value to insert for inactive entries. |
0.0
|
Returns:
| Type | Description |
|---|---|
NDArray[T]
|
An expanded array matching the original number of rows. |
ropt.evaluation.EvaluationBatchResult
dataclass
Results of a function evaluation batch.
Stores objective values (and optional constraint values) for a batch of
variable vectors. Inactive rows should be set to zero; failed active rows
should be set to numpy.nan.
See Writing Evaluation Callbacks for
batch_id management and other conventions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
objectives
|
NDArray[float64]
|
Objective values, shape |
required |
constraints
|
NDArray[float64] | None
|
Optional constraint values, shape |
None
|
batch_id
|
int
|
Integer identifying this evaluation batch. |
0
|
metadata
|
dict[str, NDArray[Any]]
|
Optional dict of per-row metadata (not used internally by |
dict()
|
ropt.evaluation.EvaluationBatchCallback
Bases: Protocol
Defines the call signature for batch evaluation callbacks.
__call__
Evaluate the given variables within the provided context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variables
|
NDArray[float64]
|
The variables to pass to the evaluation function. |
required |
context
|
EvaluationBatchContext
|
The evaluator context to pass. |
required |
Returns:
| Type | Description |
|---|---|
EvaluationBatchResult
|
The results of the evaluation. |