gemseo.algos.evaluation_problem module#

Evaluation problem.

class EvaluationProblem(design_space, database=None, differentiation_method=DifferentiationMethod.USER_GRAD, differentiation_step=1e-07, parallel_differentiation=False, **parallel_differentiation_options)[source]#

Bases: BaseProblem

A problem to evaluate functions over a design space.

This problem can only include observables, i.e. functions with OBS as function type.

Parameters:
  • design_space (DesignSpace) -- The design space on which the functions are evaluated.

  • database (Database) -- The initial database to store the function evaluations. If None, the problem starts from an empty database. If there is no need to store the function evaluations, this argument is ignored.

  • differentiation_method (DifferentiationMethod) --

    The differentiation method to evaluate the derivatives.

    By default it is set to "user".

  • differentiation_step (float) --

    The step used by the differentiation method. This argument is ignored when the differentiation method is not an ApproximationMode.

    By default it is set to 1e-07.

  • parallel_differentiation (bool) --

    Whether to approximate the derivatives in parallel.

    By default it is set to False.

  • hdf_node_path -- The path of the node in the HDF file to store the function evaluations. If empty, the root node is considered. This argument is ignored when database is a Database or the empty string.

  • **parallel_differentiation_options (int | bool) -- The options to approximate the derivatives in parallel.

class ApproximationMode(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)#

Bases: StrEnum

The approximation derivation modes.

CENTERED_DIFFERENCES = 'centered_differences'#

The centered differences method used to approximate the Jacobians by perturbing each variable with a small real number.

COMPLEX_STEP = 'complex_step'#

The complex step method used to approximate the Jacobians by perturbing each variable with a small complex number.

FINITE_DIFFERENCES = 'finite_differences'#

The finite differences method used to approximate the Jacobians by perturbing each variable with a small real number.

class DifferentiationMethod(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)#

Bases: StrEnum

The differentiation methods.

CENTERED_DIFFERENCES = 'centered_differences'#
COMPLEX_STEP = 'complex_step'#
FINITE_DIFFERENCES = 'finite_differences'#
NO_DERIVATIVE = 'no_derivative'#
USER_GRAD = 'user'#
add_listener(listener, at_each_iteration=True, at_each_function_call=False)[source]#

Add a listener for some events.

Listeners are callback functions attached to the database which are triggered when new values are stored within the database.

Parameters:
  • listener (Callable[[ndarray[Any, dtype[floating[Any]]]], Any]) -- A function to be called after some events, whose argument is a design vector.

  • at_each_iteration (bool) --

    Whether to evaluate the listeners after evaluating all functions for a given point and storing their values in the database.

    By default it is set to True.

  • at_each_function_call (bool) --

    Whether to evaluate the listeners after storing any new value in the database.

    By default it is set to False.

Return type:

None

add_observable(observable, new_iter=True)[source]#

Add an observable function.

It is an MDOFunction with OBS as function type.

Parameters:
  • observable (MDOFunction) -- The observable function.

  • new_iter (bool) --

    Whether to call the observable whenever a database entry is created.

    By default it is set to True.

Return type:

None

check()[source]#

Check if the functions attached to the problem can be evaluated.

Return type:

None

evaluate_functions(design_vector=None, design_vector_is_normalized=True, preprocess_design_vector=True, output_functions=(), jacobian_functions=None)[source]#

Evaluate the functions, and possibly their derivatives.

Parameters:
  • design_vector (RealArray | None) -- The design vector at which to evaluate the functions; if None, use the current value of the design space.

  • design_vector_is_normalized (bool) --

    Whether design_vector is normalized.

    By default it is set to True.

  • preprocess_design_vector (bool) --

    Whether to preprocess the design vector.

    By default it is set to True.

  • output_functions (Iterable[MDOFunction] | None) --

    The functions computing the outputs. If empty, evaluate all the functions computing outputs. If None, do not evaluate functions computing outputs.

    By default it is set to ().

  • jacobian_functions (Iterable[MDOFunction] | None) -- The functions computing the Jacobians. If empty, evaluate all the functions computing Jacobians. If None, do not evaluate functions computing Jacobians.

Returns:

The output values of the functions, as well as their Jacobian matrices if jacobian_functions is empty.

Return type:

EvaluationType

get_functions(no_db_no_norm=False, observable_names=None, jacobian_names=None, **kwargs)[source]#

Return the functions to be evaluated.

Parameters:
  • no_db_no_norm (bool) --

    Whether to prevent both database backup and design vector normalization.

    By default it is set to False.

  • observable_names (Iterable[str] | None) -- The names of the observables to evaluate. If empty, then all the observables are evaluated. If None, then no observable is evaluated.

  • jacobian_names (Iterable[str] | None) -- The names of the functions whose Jacobian matrices must be computed. If empty, then compute the Jacobian matrices of the functions that are selected for evaluation using the other arguments. If None, then no Jacobian matrices is computed.

  • **kwargs (Any) -- The options to select the functions to be evaluated.

Returns:

The functions computing the outputs and the functions computing the Jacobians.

Raises:

ValueError -- If a name in jacobian_names is not the name of a function of the problem.

Return type:

tuple[list[MDOFunction], list[MDOFunction]]

preprocess_functions(is_function_input_normalized=True, use_database=True, round_ints=True, eval_obs_jac=False, support_sparse_jacobian=False, store_jacobian=True)[source]#

Wrap the function for a more attractive evaluation.

E.g. approximation of the derivatives or evaluation backup.

In the case of derivative approximation, only the computed gradients are stored in the database, not the eventual finite differences or complex step perturbed evaluations.

Parameters:
  • is_function_input_normalized (bool) --

    Whether to consider the function input as normalized and unnormalize it before the function evaluation.

    By default it is set to True.

  • use_database (bool) --

    Whether to store the function evaluations in the database.

    By default it is set to True.

  • round_ints (bool) --

    Whether to round the integer variables.

    By default it is set to True.

  • eval_obs_jac (bool) --

    Whether to evaluate the Jacobian of the observables.

    By default it is set to False.

  • support_sparse_jacobian (bool) --

    Whether the driver supports sparse Jacobian.

    By default it is set to False.

  • store_jacobian (bool) --

    Whether to store the Jacobian matrices in the database. This argument is ignored when use_database is False.

    By default it is set to True.

Return type:

None

reset(database=True, current_iter=True, design_space=True, function_calls=True, preprocessing=True)[source]#

Partially or fully reset the problem.

Parameters:
  • database (bool) --

    Whether to clear the database.

    By default it is set to True.

  • current_iter (bool) --

    Whether to reset the counter of evaluations to the initial iteration.

    By default it is set to True.

  • design_space (bool) --

    Whether to reset the current value of the design space which can be None.

    By default it is set to True.

  • function_calls (bool) --

    Whether to reset the number of calls of the functions.

    By default it is set to True.

  • preprocessing (bool) --

    Whether to turn the pre-processing of functions to False.

    By default it is set to True.

Return type:

None

to_dataset(name: str = '', categorize: Literal[True] = True, export_gradients: bool = False, input_values: Iterable[RealArray] = (), **dataset_options: ...) IODataset[source]#
to_dataset(name: str = '', categorize: Literal[False] = True, export_gradients: bool = False, input_values: Iterable[RealArray] = (), **dataset_options: ...) Dataset

Export the database of the problem to a Dataset.

Parameters:
  • name -- The name to be given to the dataset. If empty, use the name of the database.

  • categorize -- Whether to distinguish between the different groups of variables. If so, use an IODataset with the design variables in the IODataset.INPUT_GROUP and the functions and their derivatives in the IODataset.OUTPUT_GROUP. Otherwise, group all the variables in Dataset.PARAMETER_GROUP`.

  • export_gradients -- Whether to export the gradients of the functions if the latter are available in the database of the problem.

  • input_values -- The input values to be considered. If empty, consider all the input values of the database.

Returns:

A dataset built from the database of the problem.

check_bounds: ClassVar[bool] = True#

Whether to check if a point is in the design space before calling functions.

database: Database#

The database to store the function evaluations.

design_space: DesignSpace#

The design space on which the functions are evaluated.

differentiation_step: float#

The differentiation step.

evaluation_counter: EvaluationCounter#

The counter of function evaluations.

Every execution of a DriverLibrary handling this problem increments this counter by 1.

property function_names: list[str]#

All the function names except those of new_iter_observables.

property functions: list[MDOFunction]#

All the functions except new_iter_observables.

property new_iter_observables: Observables#

The observables to be evaluated whenever a database entry is created.

property observables: Observables#

The observables.

property original_functions: list[MDOFunction]#

All the original functions except those of new_iter_observables.

property parallel_differentiation: bool#

Whether to approximate the derivatives in parallel.

This attribute is ignored when the differentiation method is not an ApproximationMode.

property parallel_differentiation_options: dict[str, int | bool]#

The options to approximate the derivatives in parallel.

This attribute is ignored when the differentiation method is not an ApproximationMode.

property stop_if_nan: bool#

Whether the evaluation stops when a function returns NaN.

EvaluationType(*args, **kwargs)#

The type of the output value of an evaluation.

alias of tuple[dict[str, float | ndarray[Any, dtype[floating[Any]]]], dict[str, ndarray[Any, dtype[floating[Any]]]]]